blob: b96236d218cabdba6fccf8407c760448c75730fc [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
deadbeefab9b2d12015-10-14 11:33:11 -0700464 void SendAudioVideoStream1() {
465 send_stream_1_ = true;
466 send_stream_2_ = false;
467 send_audio_ = true;
468 send_video_ = true;
469 }
470
471 void SendAudioVideoStream2() {
472 send_stream_1_ = false;
473 send_stream_2_ = true;
474 send_audio_ = true;
475 send_video_ = true;
476 }
477
478 void SendAudioVideoStream1And2() {
479 send_stream_1_ = true;
480 send_stream_2_ = true;
481 send_audio_ = true;
482 send_video_ = true;
483 }
484
485 void SendNothing() {
486 send_stream_1_ = false;
487 send_stream_2_ = false;
488 send_audio_ = false;
489 send_video_ = false;
490 }
491
492 void SendAudioOnlyStream2() {
493 send_stream_1_ = false;
494 send_stream_2_ = true;
495 send_audio_ = true;
496 send_video_ = false;
497 }
498
499 void SendVideoOnlyStream2() {
500 send_stream_1_ = false;
501 send_stream_2_ = true;
502 send_audio_ = false;
503 send_video_ = true;
504 }
505
506 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
507 if (send_stream_1_ && send_audio_) {
508 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
509 kStream1);
510 }
511 if (send_stream_1_ && send_video_) {
512 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
513 kStream1);
514 }
515 if (send_stream_2_ && send_audio_) {
516 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
517 kStream2);
518 }
519 if (send_stream_2_ && send_video_) {
520 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
521 kStream2);
522 }
523 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
524 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
525 data_channel_->label(),
526 data_channel_->label());
527 }
528 }
529
530 void GetOptionsForOffer(
531 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
532 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800533 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700534
deadbeefc80741f2015-10-22 13:14:45 -0700535 AddStreamsToOptions(session_options);
536 if (rtc_options.offer_to_receive_audio ==
537 RTCOfferAnswerOptions::kUndefined) {
538 session_options->recv_audio =
539 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
540 }
541 if (rtc_options.offer_to_receive_video ==
542 RTCOfferAnswerOptions::kUndefined) {
543 session_options->recv_video =
544 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
545 }
546 session_options->bundle_enabled =
547 session_options->bundle_enabled &&
548 (session_options->has_audio() || session_options->has_video() ||
549 session_options->has_data());
550
deadbeefab9b2d12015-10-14 11:33:11 -0700551 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
552 session_options->data_channel_type = cricket::DCT_SCTP;
553 }
554 }
555
htaa2a49d92016-03-04 02:51:39 -0800556 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
557 // ParseConstraintsForAnswer is used to set some defaults.
558 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700559
deadbeefc80741f2015-10-22 13:14:45 -0700560 AddStreamsToOptions(session_options);
561 session_options->bundle_enabled =
562 session_options->bundle_enabled &&
563 (session_options->has_audio() || session_options->has_video() ||
564 session_options->has_data());
565
deadbeefab9b2d12015-10-14 11:33:11 -0700566 if (session_->data_channel_type() == cricket::DCT_SCTP) {
567 session_options->data_channel_type = cricket::DCT_SCTP;
568 }
569 }
570
571 // Creates a local offer and applies it. Starts ICE.
572 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 // to decide which streams to create.
574 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000575 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 SetLocalDescriptionWithoutError(offer);
577 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
578 observer_.ice_gathering_state_,
579 kIceCandidatesTimeout);
580 }
581
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000582 SessionDescriptionInterface* CreateOffer() {
583 PeerConnectionInterface::RTCOfferAnswerOptions options;
584 options.offer_to_receive_audio =
585 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
586
587 return CreateOffer(options);
588 }
589
wu@webrtc.org91053e72013-08-10 07:18:04 +0000590 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800591 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000592 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000593 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700594 cricket::MediaSessionOptions session_options;
595 GetOptionsForOffer(options, &session_options);
596 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000597 EXPECT_TRUE_WAIT(
598 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000599 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000600 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000601 }
602
603 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800604 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000606 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800607 cricket::MediaSessionOptions session_options = options;
608 GetOptionsForAnswer(&session_options);
609 // Overwrite recv_audio and recv_video with passed-in values.
610 session_options.recv_video = options.recv_video;
611 session_options.recv_audio = options.recv_audio;
612 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000613 EXPECT_TRUE_WAIT(
614 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000615 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000616 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000617 }
618
htaa2a49d92016-03-04 02:51:39 -0800619 SessionDescriptionInterface* CreateAnswer() {
620 cricket::MediaSessionOptions options;
621 options.recv_video = true;
622 options.recv_audio = true;
623 return CreateAnswer(options);
624 }
625
wu@webrtc.org364f2042013-11-20 21:49:41 +0000626 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 return (session_->voice_channel() != NULL &&
628 session_->video_channel() != NULL);
629 }
630
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
632 ASSERT_TRUE(session_.get() != NULL);
633 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
634 ASSERT_TRUE(content != NULL);
635 const cricket::AudioContentDescription* audio_content =
636 static_cast<const cricket::AudioContentDescription*>(
637 content->description);
638 ASSERT_TRUE(audio_content != NULL);
639 ASSERT_EQ(1U, audio_content->cryptos().size());
640 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
641 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
642 audio_content->cryptos()[0].cipher_suite);
643 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
644 audio_content->protocol());
645
646 content = cricket::GetFirstVideoContent(sdp);
647 ASSERT_TRUE(content != NULL);
648 const cricket::VideoContentDescription* video_content =
649 static_cast<const cricket::VideoContentDescription*>(
650 content->description);
651 ASSERT_TRUE(video_content != NULL);
652 ASSERT_EQ(1U, video_content->cryptos().size());
653 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
654 video_content->cryptos()[0].cipher_suite);
655 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
656 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
657 video_content->protocol());
658 }
659
660 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
661 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
662 ASSERT_TRUE(content != NULL);
663 const cricket::AudioContentDescription* audio_content =
664 static_cast<const cricket::AudioContentDescription*>(
665 content->description);
666 ASSERT_TRUE(audio_content != NULL);
667 ASSERT_EQ(0U, audio_content->cryptos().size());
668
669 content = cricket::GetFirstVideoContent(sdp);
670 ASSERT_TRUE(content != NULL);
671 const cricket::VideoContentDescription* video_content =
672 static_cast<const cricket::VideoContentDescription*>(
673 content->description);
674 ASSERT_TRUE(video_content != NULL);
675 ASSERT_EQ(0U, video_content->cryptos().size());
676
677 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700678 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700680 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 video_content->protocol());
682 } else {
683 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
684 audio_content->protocol());
685 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
686 video_content->protocol());
687 }
688 }
689
690 // Set the internal fake description factories to do DTLS-SRTP.
691 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000692 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000694 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200695 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800696 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700697 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800698 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
700 }
701
702 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
703 bool expected) {
704 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
705 ASSERT_TRUE(audio != NULL);
706 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 const TransportInfo* video = sdp->GetTransportInfoByName("video");
708 ASSERT_TRUE(video != NULL);
709 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 }
711
712 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000713 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000715 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000716 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000718 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000720 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
721 offer);
htaa2a49d92016-03-04 02:51:39 -0800722 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 // Answer should be NULL as no crypto params in offer.
724 ASSERT_TRUE(answer == NULL);
725 }
726
727 void VerifyAnswerFromCryptoOffer() {
728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000729 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700731 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
733 ASSERT_TRUE(offer.get() != NULL);
734 VerifyCryptoParams(offer->description());
735 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700736 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 ASSERT_TRUE(answer.get() != NULL);
738 VerifyCryptoParams(answer->description());
739 }
740
deadbeef0ed85b22016-02-23 17:24:52 -0800741 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
742 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800744 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 }
746
747 const cricket::ContentInfos& contents = desc1->contents();
748 cricket::ContentInfos::const_iterator it = contents.begin();
749
750 for (; it != contents.end(); ++it) {
751 const cricket::TransportDescription* transport_desc1 =
752 desc1->GetTransportDescriptionByName(it->name);
753 const cricket::TransportDescription* transport_desc2 =
754 desc2->GetTransportDescriptionByName(it->name);
755 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800756 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 }
758 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
759 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800760 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 }
762 }
deadbeef0ed85b22016-02-23 17:24:52 -0800763 return true;
764 }
765
766 // Compares ufrag/password only for the specified |media_type|.
767 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
768 const cricket::SessionDescription* desc2,
769 cricket::MediaType media_type) {
770 if (desc1->contents().size() != desc2->contents().size()) {
771 return false;
772 }
773
774 const cricket::ContentInfo* cinfo =
775 cricket::GetFirstMediaContent(desc1->contents(), media_type);
776 const cricket::TransportDescription* transport_desc1 =
777 desc1->GetTransportDescriptionByName(cinfo->name);
778 const cricket::TransportDescription* transport_desc2 =
779 desc2->GetTransportDescriptionByName(cinfo->name);
780 if (!transport_desc1 || !transport_desc2) {
781 return false;
782 }
783 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
784 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
785 return false;
786 }
787 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000789
790 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
791 std::string *sdp) {
792 const cricket::SessionDescription* desc = current_desc->description();
793 EXPECT_TRUE(current_desc->ToString(sdp));
794
795 const cricket::ContentInfos& contents = desc->contents();
796 cricket::ContentInfos::const_iterator it = contents.begin();
797 // Replace ufrag and pwd lines with empty strings.
798 for (; it != contents.end(); ++it) {
799 const cricket::TransportDescription* transport_desc =
800 desc->GetTransportDescriptionByName(it->name);
801 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
802 + "\r\n";
803 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
804 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000805 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000806 "", 0,
807 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000808 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000809 "", 0,
810 sdp);
811 }
812 }
813
deadbeef0ed85b22016-02-23 17:24:52 -0800814 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
815 const std::string& ufrag,
816 const std::string& pwd) {
817 cricket::SessionDescription* desc = current_desc->description();
818 for (TransportInfo& transport_info : desc->transport_infos()) {
819 cricket::TransportDescription& transport_desc =
820 transport_info.description;
821 transport_desc.ice_ufrag = ufrag;
822 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000823 }
824 }
825
deadbeef0ed85b22016-02-23 17:24:52 -0800826 // Sets ufrag/pwd for specified |media_type|.
827 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
828 cricket::MediaType media_type,
829 const std::string& ufrag,
830 const std::string& pwd) {
831 cricket::SessionDescription* desc = current_desc->description();
832 const cricket::ContentInfo* cinfo =
833 cricket::GetFirstMediaContent(desc->contents(), media_type);
834 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
835 cricket::TransportDescription* transport_desc =
836 &transport_info->description;
837 transport_desc->ice_ufrag = ufrag;
838 transport_desc->ice_pwd = pwd;
839 }
840
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 // Creates a remote offer and and applies it as a remote description,
842 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700843 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 // to decide which local and remote streams to create.
845 void CreateAndSetRemoteOfferAndLocalAnswer() {
846 SessionDescriptionInterface* offer = CreateRemoteOffer();
847 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800848 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 SetLocalDescriptionWithoutError(answer);
850 }
851 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
852 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700853 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 }
855 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700856 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 SetLocalDescriptionWithoutError(desc);
858 EXPECT_EQ(expected_state, session_->state());
859 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000860 void SetLocalDescriptionExpectError(const std::string& action,
861 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 SessionDescriptionInterface* desc) {
863 std::string error;
864 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000865 std::string sdp_type = "local ";
866 sdp_type.append(action);
867 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 EXPECT_NE(std::string::npos, error.find(expected_error));
869 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000870 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
871 SessionDescriptionInterface* desc) {
872 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
873 expected_error, desc);
874 }
875 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
876 SessionDescriptionInterface* desc) {
877 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
878 expected_error, desc);
879 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
881 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
882 }
883 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700884 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 SetRemoteDescriptionWithoutError(desc);
886 EXPECT_EQ(expected_state, session_->state());
887 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000888 void SetRemoteDescriptionExpectError(const std::string& action,
889 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 SessionDescriptionInterface* desc) {
891 std::string error;
892 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000893 std::string sdp_type = "remote ";
894 sdp_type.append(action);
895 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_NE(std::string::npos, error.find(expected_error));
897 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000898 void SetRemoteDescriptionOfferExpectError(
899 const std::string& expected_error, SessionDescriptionInterface* desc) {
900 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
901 expected_error, desc);
902 }
903 void SetRemoteDescriptionPranswerExpectError(
904 const std::string& expected_error, SessionDescriptionInterface* desc) {
905 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
906 expected_error, desc);
907 }
908 void SetRemoteDescriptionAnswerExpectError(
909 const std::string& expected_error, SessionDescriptionInterface* desc) {
910 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
911 expected_error, desc);
912 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913
914 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
915 SessionDescriptionInterface** nocrypto_answer) {
916 // Create a SDP without Crypto.
917 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000918 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 options.bundle_enabled = true;
920 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
921 ASSERT_TRUE(*offer != NULL);
922 VerifyCryptoParams((*offer)->description());
923
924 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
925 cricket::SEC_DISABLED);
926 EXPECT_TRUE(*nocrypto_answer != NULL);
927 }
928
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000929 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
930 SessionDescriptionInterface** nodtls_answer) {
931 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000932 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000933 options.bundle_enabled = true;
934
kwibergd1fe2812016-04-27 06:47:29 -0700935 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000936 CreateRemoteOffer(options, cricket::SEC_ENABLED));
937
938 *nodtls_answer =
939 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
940 EXPECT_TRUE(*nodtls_answer != NULL);
941 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
942 VerifyCryptoParams((*nodtls_answer)->description());
943
944 SetFactoryDtlsSrtp();
945 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
946 ASSERT_TRUE(*offer != NULL);
947 VerifyFingerprintStatus((*offer)->description(), true);
948 VerifyCryptoParams((*offer)->description());
949 }
950
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 JsepSessionDescription* CreateRemoteOfferWithVersion(
952 cricket::MediaSessionOptions options,
953 cricket::SecurePolicy secure_policy,
954 const std::string& session_version,
955 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000956 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 const cricket::SessionDescription* cricket_desc = NULL;
958 if (current_desc) {
959 cricket_desc = current_desc->description();
960 session_id = current_desc->session_id();
961 }
962
963 desc_factory_->set_secure(secure_policy);
964 JsepSessionDescription* offer(
965 new JsepSessionDescription(JsepSessionDescription::kOffer));
966 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
967 session_id, session_version)) {
968 delete offer;
969 offer = NULL;
970 }
971 return offer;
972 }
973 JsepSessionDescription* CreateRemoteOffer(
974 cricket::MediaSessionOptions options) {
975 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
976 kSessionVersion, NULL);
977 }
978 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000979 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
980 return CreateRemoteOfferWithVersion(
981 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 }
983 JsepSessionDescription* CreateRemoteOffer(
984 cricket::MediaSessionOptions options,
985 const SessionDescriptionInterface* current_desc) {
986 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
987 kSessionVersion, current_desc);
988 }
989
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000990 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
991 const char* sctp_stream_name, int new_port,
992 cricket::MediaSessionOptions options) {
993 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000994 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
995 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000996 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
997 }
998
999 // Takes ownership of offer_basis (and deletes it).
1000 JsepSessionDescription* ChangeSDPSctpPort(
1001 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1002 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1003 // SessionDescription from the mutated string.
1004 const char* default_port_str = "5000";
1005 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001006 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001007 std::string offer_str;
1008 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001009 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001010 new_port_str, strlen(new_port_str),
1011 &offer_str);
1012 JsepSessionDescription* offer = new JsepSessionDescription(
1013 offer_basis->type());
1014 delete offer_basis;
1015 offer->Initialize(offer_str, NULL);
1016 return offer;
1017 }
1018
deadbeefab9b2d12015-10-14 11:33:11 -07001019 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 // before this function to decide which streams to create.
1021 JsepSessionDescription* CreateRemoteOffer() {
1022 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001023 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 return CreateRemoteOffer(options, session_->remote_description());
1025 }
1026
1027 JsepSessionDescription* CreateRemoteAnswer(
1028 const SessionDescriptionInterface* offer,
1029 cricket::MediaSessionOptions options,
1030 cricket::SecurePolicy policy) {
1031 desc_factory_->set_secure(policy);
1032 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001033 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 JsepSessionDescription* answer(
1035 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1036 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1037 options, NULL),
1038 session_id, kSessionVersion)) {
1039 delete answer;
1040 answer = NULL;
1041 }
1042 return answer;
1043 }
1044
1045 JsepSessionDescription* CreateRemoteAnswer(
1046 const SessionDescriptionInterface* offer,
1047 cricket::MediaSessionOptions options) {
1048 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1049 }
1050
deadbeefab9b2d12015-10-14 11:33:11 -07001051 // Creates an answer session description.
1052 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 // to decide which streams to create.
1054 JsepSessionDescription* CreateRemoteAnswer(
1055 const SessionDescriptionInterface* offer) {
1056 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001057 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1059 }
1060
1061 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001064 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001065
1066 PeerConnectionInterface::RTCOfferAnswerOptions options;
1067 options.use_rtp_mux = bundle;
1068
1069 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1071 // and answer.
1072 SetLocalDescriptionWithoutError(offer);
1073
kwibergd1fe2812016-04-27 06:47:29 -07001074 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001075 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 std::string sdp;
1077 EXPECT_TRUE(answer->ToString(&sdp));
1078
1079 size_t expected_candidate_num = 2;
1080 if (!rtcp_mux) {
1081 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1082 // for rtp and rtcp.
1083 expected_candidate_num = 4;
1084 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 const std::string kRtcpMux = "a=rtcp-mux";
1086 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 kXRtcpMux.c_str(), kXRtcpMux.length(),
1089 &sdp);
1090 }
1091
1092 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1093 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094
1095 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001096 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1098 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001099 if (bundle) {
1100 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1101 } else {
1102 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 }
1104 }
1105 // Tests that we can only send DTMF when the dtmf codec is supported.
1106 void TestCanInsertDtmf(bool can) {
1107 if (can) {
1108 InitWithDtmfCodec();
1109 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001110 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 }
deadbeefab9b2d12015-10-14 11:33:11 -07001112 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 CreateAndSetRemoteOfferAndLocalAnswer();
1114 EXPECT_FALSE(session_->CanInsertDtmf(""));
1115 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1116 }
1117
zhihuang3a334652016-05-05 18:37:49 -07001118 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1119 const std::string& codec_name) {
1120 for (const auto& content : desc->description()->contents()) {
1121 if (static_cast<cricket::MediaContentDescription*>(content.description)
1122 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1123 const auto* mdesc =
1124 static_cast<cricket::VideoContentDescription*>(content.description);
1125 for (const auto& codec : mdesc->codecs()) {
1126 if (codec.name == codec_name) {
1127 return true;
1128 }
1129 }
1130 }
1131 }
1132 return false;
1133 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001134 // Helper class to configure loopback network and verify Best
1135 // Connection using right IP protocol for TestLoopbackCall
1136 // method. LoopbackNetworkManager applies firewall rules to block
1137 // all ping traffic once ICE completed, and remove them to observe
1138 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1139 // verifies the best connection is using the right IP protocol after
1140 // initial ICE convergences.
1141
1142 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001143 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001144 LoopbackNetworkConfiguration()
1145 : test_ipv6_network_(false),
1146 test_extra_ipv4_network_(false),
1147 best_connection_after_initial_ice_converged_(1, 0) {}
1148
1149 // Used to track the expected best connection count in each IP protocol.
1150 struct ExpectedBestConnection {
1151 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1152 : ipv4_count_(ipv4_count),
1153 ipv6_count_(ipv6_count) {}
1154
1155 int ipv4_count_;
1156 int ipv6_count_;
1157 };
1158
1159 bool test_ipv6_network_;
1160 bool test_extra_ipv4_network_;
1161 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1162
1163 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001164 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001165 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1166 }
1167
1168 private:
jbauchac8869e2015-07-03 01:36:14 -07001169 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170 const ExpectedBestConnection& expected) const {
1171 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001172 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1173 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001174 expected.ipv4_count_);
1175 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001176 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1177 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001178 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001179 // This is used in the loopback call so there is only single host to host
1180 // candidate pair.
1181 EXPECT_EQ(metrics_observer->GetEnumCounter(
1182 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1183 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001184 0);
1185 EXPECT_EQ(metrics_observer->GetEnumCounter(
1186 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1187 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001188 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001189 }
1190 };
1191
1192 class LoopbackNetworkManager {
1193 public:
1194 LoopbackNetworkManager(WebRtcSessionTest* session,
1195 const LoopbackNetworkConfiguration& config)
1196 : config_(config) {
1197 session->AddInterface(
1198 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1199 if (config_.test_extra_ipv4_network_) {
1200 session->AddInterface(
1201 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1202 }
1203 if (config_.test_ipv6_network_) {
1204 session->AddInterface(
1205 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1206 }
1207 }
1208
1209 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1210 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1211 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1212 if (config_.test_extra_ipv4_network_) {
1213 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1214 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1215 }
1216 if (config_.test_ipv6_network_) {
1217 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1218 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1219 }
1220 }
1221
1222 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1223
1224 private:
1225 LoopbackNetworkConfiguration config_;
1226 };
1227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 // The method sets up a call from the session to itself, in a loopback
1229 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001230 // disconnection, and then a permanent disconnection.
1231 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1233 // While running the call, this method also checks if the session goes through
1234 // the correct sequence of ICE states when a connection is established,
1235 // broken, and re-established.
1236 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001237 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1238 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001240
stefanc1aeaf02015-10-15 07:26:07 -07001241 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001243 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001244 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245
1246 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1247 observer_.ice_gathering_state_);
1248 SetLocalDescriptionWithoutError(offer);
1249 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1250 observer_.ice_connection_state_);
1251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001252 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1254 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001255 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256
1257 std::string sdp;
1258 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001259 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1260 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 ASSERT_TRUE(desc != NULL);
1262 SetRemoteDescriptionWithoutError(desc);
1263
1264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001265 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001266
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001267 // The ice connection state is "Connected" too briefly to catch in a test.
1268 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001269 observer_.ice_connection_state_, kIceCandidatesTimeout);
1270 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271
stefanc1aeaf02015-10-15 07:26:07 -07001272 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1273 LoopbackNetworkManager loopback_network_manager(this, config);
1274 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 // Adding firewall rule to block ping requests, which should cause
1277 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001278
1279 loopback_network_manager.ApplyFirewallRules(fss_.get());
1280
1281 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1283 observer_.ice_connection_state_,
1284 kIceCandidatesTimeout);
1285
jbauchac8869e2015-07-03 01:36:14 -07001286 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001292 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 observer_.ice_connection_state_,
1294 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001295
1296 // Now we block ping requests and wait until the ICE connection transitions
1297 // to the Failed state. This will take at least 30 seconds because it must
1298 // wait for the Port to timeout.
1299 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300
1301 loopback_network_manager.ApplyFirewallRules(fss_.get());
1302 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001303 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304 observer_.ice_connection_state_,
1305 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 }
1307
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308 void TestLoopbackCall() {
1309 LoopbackNetworkConfiguration config;
1310 TestLoopbackCall(config);
1311 }
1312
stefanc1aeaf02015-10-15 07:26:07 -07001313 void TestPacketOptions() {
1314 media_controller_.reset(
1315 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1316 LoopbackNetworkConfiguration config;
1317 LoopbackNetworkManager loopback_network_manager(this, config);
1318
1319 SetupLoopbackCall();
1320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001321 // Wait for channel to be ready for sending.
1322 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001323 uint8_t test_packet[15] = {0};
1324 rtc::PacketOptions options;
1325 options.packet_id = 10;
1326 media_engine_->GetVideoChannel(0)
1327 ->SendRtp(test_packet, sizeof(test_packet), options);
1328
1329 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001330 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1331 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001332 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1333 }
1334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1336 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001337 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1338 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001339
1340 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001341 std::vector<cricket::AudioCodec> codecs =
1342 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 codecs.push_back(kCNCodec1);
1344 codecs.push_back(kCNCodec2);
1345 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001346 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 }
1348
1349 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1350 const cricket::ContentDescription* description = content->description;
1351 ASSERT(description != NULL);
1352 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001353 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 ASSERT(audio_content_desc != NULL);
1355 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1356 if (audio_content_desc->codecs()[i].name == "CN")
1357 return false;
1358 }
1359 return true;
1360 }
1361
deadbeefab9b2d12015-10-14 11:33:11 -07001362 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001363 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001364 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001365 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1366 data_channel_ = DataChannel::Create(
1367 session_.get(), session_->data_channel_type(), "datachannel", dci);
1368 }
1369
1370 void SetLocalDescriptionWithDataChannel() {
1371 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001372 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 SetLocalDescriptionWithoutError(offer);
1374 }
1375
wu@webrtc.org91053e72013-08-10 07:18:04 +00001376 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001377 RTCCertificateGenerationMethod cert_gen_method,
1378 CreateSessionDescriptionRequest::Type type) {
1379 InitWithDtls(cert_gen_method);
1380 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1381 }
1382
1383 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1384 CreateSessionDescriptionRequest::Type type) {
1385 InitWithDtlsIdentityGenFail();
1386 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1387 }
1388
1389 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001391 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001392 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001393 if (type == CreateSessionDescriptionRequest::kAnswer) {
1394 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001395 std::unique_ptr<JsepSessionDescription> offer(
1396 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 ASSERT_TRUE(offer.get() != NULL);
1398 SetRemoteDescriptionWithoutError(offer.release());
1399 }
1400
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001401 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001402 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001403 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001404 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 observers[kNumber];
1406 for (int i = 0; i < kNumber; ++i) {
1407 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1408 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001409 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001410 } else {
htaa2a49d92016-03-04 02:51:39 -08001411 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001412 }
1413 }
1414
1415 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1416 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1417 WebRtcSessionCreateSDPObserverForTest::kFailed;
1418
1419 for (int i = 0; i < kNumber; ++i) {
1420 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1421 if (success) {
1422 EXPECT_TRUE(observers[i]->description() != NULL);
1423 } else {
1424 EXPECT_TRUE(observers[i]->description() == NULL);
1425 }
1426 }
1427 }
1428
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001429 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001430 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001431 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001432 turn_server.credentials = credentials;
1433 turn_server.ports.push_back(
1434 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1435 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001436 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001437 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001438 }
1439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 cricket::FakeMediaEngine* media_engine_;
1441 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001442 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001443 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001444 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1445 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1446 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1447 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1448 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1449 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 rtc::SocketServerScope ss_scope_;
1451 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001452 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001453 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001454 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001455 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001456 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001457 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001458 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 MockIceObserver observer_;
1460 cricket::FakeVideoMediaChannel* video_channel_;
1461 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001462 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001463 // The following flags affect options created for CreateOffer/CreateAnswer.
1464 bool send_stream_1_ = false;
1465 bool send_stream_2_ = false;
1466 bool send_audio_ = false;
1467 bool send_video_ = false;
1468 rtc::scoped_refptr<DataChannel> data_channel_;
1469 // Last values received from data channel creation signal.
1470 std::string last_data_channel_label_;
1471 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001472 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473};
1474
Henrik Boström87713d02015-08-25 09:53:21 +02001475TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1476 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 // SDES is disabled when DTLS is on.
1478 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479}
1480
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001481TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001483 // SDES is required if DTLS is off.
1484 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001485}
1486
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1488 TestSessionCandidatesWithBundleRtcpMux(false, false);
1489}
1490
1491// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1492// with rtcp-mux and/or bundle.
1493TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1494 TestSessionCandidatesWithBundleRtcpMux(false, true);
1495}
1496
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1498 TestSessionCandidatesWithBundleRtcpMux(true, true);
1499}
1500
1501TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001502 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1503 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001504 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001505 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 InitiateCall();
1507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1510}
1511
deadbeeff5f03e82016-06-06 11:16:06 -07001512TEST_F(WebRtcSessionTest, TestStunError) {
1513 rtc::ScopedFakeClock clock;
1514
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001515 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1516 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001517 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001518 rtc::FP_UDP,
1519 rtc::FD_ANY,
1520 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001521 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001522 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001524 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001525 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1527 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001528 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1529 // warning.
1530 session_->Close();
1531 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532}
1533
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001534TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001535 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001536 SessionDescriptionInterface* offer = NULL;
1537 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1538 std::string unknown_action;
1539 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1540 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1541}
1542
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543// Test creating offers and receive answers and make sure the
1544// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001545TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001547 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001548 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 const std::string session_id_orig = offer->session_id();
1550 const std::string session_version_orig = offer->session_version();
1551 SetLocalDescriptionWithoutError(offer);
1552
deadbeefab9b2d12015-10-14 11:33:11 -07001553 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 SessionDescriptionInterface* answer =
1555 CreateRemoteAnswer(session_->local_description());
1556 SetRemoteDescriptionWithoutError(answer);
1557
1558 video_channel_ = media_engine_->GetVideoChannel(0);
1559 voice_channel_ = media_engine_->GetVoiceChannel(0);
1560
1561 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1562 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1563
1564 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1565 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1566
1567 ASSERT_EQ(1u, video_channel_->send_streams().size());
1568 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1569 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1570 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1571
1572 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001573 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001574 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575
1576 // Verify the session id is the same and the session version is
1577 // increased.
1578 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001579 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1580 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581
1582 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001583 EXPECT_EQ(0u, video_channel_->send_streams().size());
1584 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585
deadbeefab9b2d12015-10-14 11:33:11 -07001586 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 answer = CreateRemoteAnswer(session_->local_description());
1588 SetRemoteDescriptionWithoutError(answer);
1589
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 // Make sure the receive streams have not changed.
1591 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1592 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1593 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1594 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1595}
1596
1597// Test receiving offers and creating answers and make sure the
1598// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001600 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001601 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001602 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 SetRemoteDescriptionWithoutError(offer);
1605
deadbeefab9b2d12015-10-14 11:33:11 -07001606 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001607 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001608 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 SetLocalDescriptionWithoutError(answer);
1610
1611 const std::string session_id_orig = answer->session_id();
1612 const std::string session_version_orig = answer->session_version();
1613
1614 video_channel_ = media_engine_->GetVideoChannel(0);
1615 voice_channel_ = media_engine_->GetVoiceChannel(0);
1616
htaa2a49d92016-03-04 02:51:39 -08001617 ASSERT_TRUE(video_channel_);
1618 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1620 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1621
1622 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1623 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1624
1625 ASSERT_EQ(1u, video_channel_->send_streams().size());
1626 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1627 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1628 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1629
deadbeefab9b2d12015-10-14 11:33:11 -07001630 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001631 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 SetRemoteDescriptionWithoutError(offer);
1633
1634 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001635 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001636 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637
1638 // Verify the session id is the same and the session version is
1639 // increased.
1640 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001641 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1642 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 SetLocalDescriptionWithoutError(answer);
1644
1645 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1646 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1647 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1648 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1649 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1650 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1651
1652 // Make sure we have no send streams.
1653 EXPECT_EQ(0u, video_channel_->send_streams().size());
1654 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1655}
1656
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001658 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001659 media_engine_->set_fail_create_channel(true);
1660
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001662 ASSERT_TRUE(offer != NULL);
1663 // SetRemoteDescription and SetLocalDescription will take the ownership of
1664 // the offer.
1665 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001666 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001667 ASSERT_TRUE(offer != NULL);
1668 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1669}
1670
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671//
1672// Tests for creating/setting SDP under different SDES/DTLS polices:
1673//
1674// --DTLS off and SDES on
1675// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1676// set local/remote offer/answer with crypto --> success
1677// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1678// failure
1679// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1680// failure
1681// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1682// failure
1683//
1684// --DTLS on and SDES off
1685// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1686// set local/remote offer/answer with DTLS fingerprint --> success
1687// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1688// fingerprint --> failure
1689// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1690// --> failure
1691// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1692// --> failure
1693//
1694// --Encryption disabled: DTLS off and SDES off
1695// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1696// answer without SDES or DTLS --> success
1697// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1698// answer without SDES or DTLS --> success
1699//
1700
1701// Test that we return a failure when applying a remote/local offer that doesn't
1702// have cryptos enabled when DTLS is off.
1703TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001706 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 JsepSessionDescription* offer = CreateRemoteOffer(
1708 options, cricket::SEC_DISABLED);
1709 ASSERT_TRUE(offer != NULL);
1710 VerifyNoCryptoParams(offer->description(), false);
1711 // SetRemoteDescription and SetLocalDescription will take the ownership of
1712 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1715 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001716 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717}
1718
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001719// Test that we return a failure when applying a local answer that doesn't have
1720// cryptos enabled when DTLS is off.
1721TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001722 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 SessionDescriptionInterface* offer = NULL;
1724 SessionDescriptionInterface* answer = NULL;
1725 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1726 // SetRemoteDescription and SetLocalDescription will take the ownership of
1727 // the offer.
1728 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001729 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730}
1731
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001732// Test we will return fail when apply an remote answer that doesn't have
1733// crypto enabled when DTLS is off.
1734TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001735 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 SessionDescriptionInterface* offer = NULL;
1737 SessionDescriptionInterface* answer = NULL;
1738 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1739 // SetRemoteDescription and SetLocalDescription will take the ownership of
1740 // the offer.
1741 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743}
1744
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001745// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1746// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001747TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001748 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001749 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001750 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 SetFactoryDtlsSrtp();
1752 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001753 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 JsepSessionDescription* offer =
1755 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 ASSERT_TRUE(offer != NULL);
1757 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
1760 // SetRemoteDescription will take the ownership of the offer.
1761 SetRemoteDescriptionWithoutError(offer);
1762
1763 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001764 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 ASSERT_TRUE(answer != NULL);
1766 VerifyFingerprintStatus(answer->description(), true);
1767 // Check that we don't have an a=crypto line in the answer.
1768 VerifyNoCryptoParams(answer->description(), true);
1769
1770 // Now set the local description, which should work, even without a=crypto.
1771 SetLocalDescriptionWithoutError(answer);
1772}
1773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1775// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001776TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001777 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001778 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001779 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 SetFactoryDtlsSrtp();
1781
1782 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001783 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784 ASSERT_TRUE(offer != NULL);
1785 VerifyFingerprintStatus(offer->description(), true);
1786 // Check that we don't have an a=crypto line in the offer.
1787 VerifyNoCryptoParams(offer->description(), true);
1788
1789 // Now set the local description, which should work, even without a=crypto.
1790 SetLocalDescriptionWithoutError(offer);
1791
1792 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001793 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 JsepSessionDescription* answer =
1795 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1796 ASSERT_TRUE(answer != NULL);
1797 VerifyFingerprintStatus(answer->description(), true);
1798 VerifyNoCryptoParams(answer->description(), true);
1799
1800 // SetRemoteDescription will take the ownership of the answer.
1801 SetRemoteDescriptionWithoutError(answer);
1802}
1803
1804// Test that if we support DTLS and the other side didn't offer a fingerprint,
1805// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001806TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001807 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001808 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001810 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001811 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 JsepSessionDescription* offer = CreateRemoteOffer(
1813 options, cricket::SEC_REQUIRED);
1814 ASSERT_TRUE(offer != NULL);
1815 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818 // SetRemoteDescription will take the ownership of the offer.
1819 SetRemoteDescriptionOfferExpectError(
1820 kSdpWithoutDtlsFingerprint, offer);
1821
1822 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1823 // SetLocalDescription will take the ownership of the offer.
1824 SetLocalDescriptionOfferExpectError(
1825 kSdpWithoutDtlsFingerprint, offer);
1826}
1827
1828// Test that we return a failure when applying a local answer that doesn't have
1829// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001830TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001831 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001832 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 SessionDescriptionInterface* offer = NULL;
1834 SessionDescriptionInterface* answer = NULL;
1835 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1836
1837 // SetRemoteDescription and SetLocalDescription will take the ownership of
1838 // the offer and answer.
1839 SetRemoteDescriptionWithoutError(offer);
1840 SetLocalDescriptionAnswerExpectError(
1841 kSdpWithoutDtlsFingerprint, answer);
1842}
1843
1844// Test that we return a failure when applying a remote answer that doesn't have
1845// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001846TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001847 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001848 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001849 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001851 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001852 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001853 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001854 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001855 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856
1857 // SetRemoteDescription and SetLocalDescription will take the ownership of
1858 // the offer and answer.
1859 SetLocalDescriptionWithoutError(offer);
1860 SetRemoteDescriptionAnswerExpectError(
1861 kSdpWithoutDtlsFingerprint, answer);
1862}
1863
1864// Test that we create a local offer without SDES or DTLS and accept a remote
1865// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001866TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001867 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001869 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001870
1871 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001872 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001873 ASSERT_TRUE(offer != NULL);
1874 VerifyFingerprintStatus(offer->description(), false);
1875 // Check that we don't have an a=crypto line in the offer.
1876 VerifyNoCryptoParams(offer->description(), false);
1877
1878 // Now set the local description, which should work, even without a=crypto.
1879 SetLocalDescriptionWithoutError(offer);
1880
1881 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001882 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 JsepSessionDescription* answer =
1884 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1885 ASSERT_TRUE(answer != NULL);
1886 VerifyFingerprintStatus(answer->description(), false);
1887 VerifyNoCryptoParams(answer->description(), false);
1888
1889 // SetRemoteDescription will take the ownership of the answer.
1890 SetRemoteDescriptionWithoutError(answer);
1891}
1892
1893// Test that we create a local answer without SDES or DTLS and accept a remote
1894// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001895TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001897 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898
1899 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001900 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001901 JsepSessionDescription* offer =
1902 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1903 ASSERT_TRUE(offer != NULL);
1904 VerifyFingerprintStatus(offer->description(), false);
1905 VerifyNoCryptoParams(offer->description(), false);
1906
1907 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 SetRemoteDescriptionWithoutError(offer);
1909
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001911 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 ASSERT_TRUE(answer != NULL);
1913 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914 // Check that we don't have an a=crypto line in the answer.
1915 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 SetLocalDescriptionWithoutError(answer);
1919}
1920
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001921// Test that we can create and set an answer correctly when different
1922// SSL roles have been negotiated for different transports.
1923// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1924TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1925 SendAudioVideoStream1();
1926 InitWithDtls(GetParam());
1927 SetFactoryDtlsSrtp();
1928
1929 SessionDescriptionInterface* offer = CreateOffer();
1930 SetLocalDescriptionWithoutError(offer);
1931
1932 cricket::MediaSessionOptions options;
1933 options.recv_video = true;
1934
1935 // First, negotiate different SSL roles.
1936 SessionDescriptionInterface* answer =
1937 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1938 TransportInfo* audio_transport_info =
1939 answer->description()->GetTransportInfoByName("audio");
1940 audio_transport_info->description.connection_role =
1941 cricket::CONNECTIONROLE_ACTIVE;
1942 TransportInfo* video_transport_info =
1943 answer->description()->GetTransportInfoByName("video");
1944 video_transport_info->description.connection_role =
1945 cricket::CONNECTIONROLE_PASSIVE;
1946 SetRemoteDescriptionWithoutError(answer);
1947
1948 // Now create an offer in the reverse direction, and ensure the initial
1949 // offerer responds with an answer with correct SSL roles.
1950 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1951 kSessionVersion,
1952 session_->remote_description());
1953 SetRemoteDescriptionWithoutError(offer);
1954
htaa2a49d92016-03-04 02:51:39 -08001955 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001956 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1957 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1958 audio_transport_info->description.connection_role);
1959 video_transport_info = answer->description()->GetTransportInfoByName("video");
1960 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1961 video_transport_info->description.connection_role);
1962 SetLocalDescriptionWithoutError(answer);
1963
1964 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1965 // audio is transferred over to video in the answer that completes the BUNDLE
1966 // negotiation.
1967 options.bundle_enabled = true;
1968 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1969 kSessionVersion,
1970 session_->remote_description());
1971 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001972 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001973 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1974 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1975 audio_transport_info->description.connection_role);
1976 video_transport_info = answer->description()->GetTransportInfoByName("video");
1977 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1978 video_transport_info->description.connection_role);
1979 SetLocalDescriptionWithoutError(answer);
1980}
1981
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001983 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001984 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 SetLocalDescriptionWithoutError(offer);
1988
1989 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 SetLocalDescriptionWithoutError(offer2);
1992}
1993
1994TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 SetRemoteDescriptionWithoutError(offer);
2000
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002001 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 SetRemoteDescriptionWithoutError(offer2);
2003}
2004
2005TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002006 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002007 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002008 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002010 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002011 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2012 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013}
2014
2015TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002016 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002017 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002018 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002021 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002022 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023}
2024
2025TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002026 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002027 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002029 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
htaa2a49d92016-03-04 02:51:39 -08002031 JsepSessionDescription* pranswer =
2032 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002034 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002037 JsepSessionDescription* pranswer2 =
2038 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2040
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
deadbeefab9b2d12015-10-14 11:33:11 -07002043 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002044 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002045 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046}
2047
2048TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002049 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002052 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053
2054 JsepSessionDescription* pranswer =
2055 CreateRemoteAnswer(session_->local_description());
2056 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2057
2058 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002059 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 JsepSessionDescription* pranswer2 =
2063 CreateRemoteAnswer(session_->local_description());
2064 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2065
2066 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002067 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068
deadbeefab9b2d12015-10-14 11:33:11 -07002069 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SessionDescriptionInterface* answer =
2071 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002072 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
2075TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002078 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002079
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 SessionDescriptionInterface* answer =
2081 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002082 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2083 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002088 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002089 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 SessionDescriptionInterface* answer =
2092 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002093 SetRemoteDescriptionAnswerExpectError(
2094 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002097// Tests that the remote candidates are added and removed successfully.
2098TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002102 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2103 "", "", "host", 0, "");
2104 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2106
deadbeefd59daf82015-10-14 15:02:44 -07002107 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2109
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002110 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002112
2113 // Fail since we have not set a remote description.
2114 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2117 session_->local_description());
2118 SetRemoteDescriptionWithoutError(answer);
2119
deadbeefd59daf82015-10-14 15:02:44 -07002120 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2121 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002122 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002123 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2124 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 // Verifying the candidates are copied properly from internal vector.
2127 const SessionDescriptionInterface* remote_desc =
2128 session_->remote_description();
2129 ASSERT_TRUE(remote_desc != NULL);
2130 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2131 const IceCandidateCollection* candidates =
2132 remote_desc->candidates(kMediaContentIndex0);
2133 ASSERT_EQ(2u, candidates->count());
2134 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2135 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2136 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2137 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2138
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002139 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2140 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 candidate.set_component(2);
2142 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2143 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002144 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
2146 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2147 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002148
2149 // Remove candidate1 and candidate2
2150 std::vector<cricket::Candidate> remote_candidates;
2151 remote_candidates.push_back(ice_candidate1.candidate());
2152 remote_candidates.push_back(ice_candidate2.candidate());
2153 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2154 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155}
2156
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002157// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158// that it is retained if the remote session description is changed.
2159TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002160 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 cricket::Candidate candidate1;
2162 candidate1.set_component(1);
2163 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2164 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002165 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 CreateAndSetRemoteOfferAndLocalAnswer();
2167
2168 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2169 const SessionDescriptionInterface* remote_desc =
2170 session_->remote_description();
2171 ASSERT_TRUE(remote_desc != NULL);
2172 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2173 const IceCandidateCollection* candidates =
2174 remote_desc->candidates(kMediaContentIndex0);
2175 ASSERT_EQ(1u, candidates->count());
2176 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2177
2178 // Update the RemoteSessionDescription with a new session description and
2179 // a candidate and check that the new remote session description contains both
2180 // candidates.
2181 SessionDescriptionInterface* offer = CreateRemoteOffer();
2182 cricket::Candidate candidate2;
2183 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2184 candidate2);
2185 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2186 SetRemoteDescriptionWithoutError(offer);
2187
2188 remote_desc = session_->remote_description();
2189 ASSERT_TRUE(remote_desc != NULL);
2190 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2191 candidates = remote_desc->candidates(kMediaContentIndex0);
2192 ASSERT_EQ(2u, candidates->count());
2193 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2194 // Username and password have be updated with the TransportInfo of the
2195 // SessionDescription, won't be equal to the original one.
2196 candidate2.set_username(candidates->at(0)->candidate().username());
2197 candidate2.set_password(candidates->at(0)->candidate().password());
2198 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2199 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2200 // No need to verify the username and password.
2201 candidate1.set_username(candidates->at(1)->candidate().username());
2202 candidate1.set_password(candidates->at(1)->candidate().password());
2203 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2204
2205 // Test that the candidate is ignored if we can add the same candidate again.
2206 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2207}
2208
2209// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002210// that they are retained if the local session description is changed. And if
2211// continual gathering is enabled, they are removed from the local session
2212// description when the network is down.
2213TEST_F(WebRtcSessionTest,
2214 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002215 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002216 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002217 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 CreateAndSetRemoteOfferAndLocalAnswer();
2219
2220 const SessionDescriptionInterface* local_desc = session_->local_description();
2221 const IceCandidateCollection* candidates =
2222 local_desc->candidates(kMediaContentIndex0);
2223 ASSERT_TRUE(candidates != NULL);
2224 EXPECT_EQ(0u, candidates->count());
2225
2226 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2227
2228 local_desc = session_->local_description();
2229 candidates = local_desc->candidates(kMediaContentIndex0);
2230 ASSERT_TRUE(candidates != NULL);
2231 EXPECT_LT(0u, candidates->count());
2232 candidates = local_desc->candidates(1);
2233 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002234 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
2236 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002237 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 CreateAndSetRemoteOfferAndLocalAnswer();
2239
2240 local_desc = session_->local_description();
2241 candidates = local_desc->candidates(kMediaContentIndex0);
2242 ASSERT_TRUE(candidates != NULL);
2243 EXPECT_LT(0u, candidates->count());
2244 candidates = local_desc->candidates(1);
2245 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002246 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002247
2248 candidates = local_desc->candidates(kMediaContentIndex0);
2249 size_t num_local_candidates = candidates->count();
2250 // Enable Continual Gathering
Honghai Zhang5622c5e2016-07-01 13:59:29 -07002251 cricket::IceConfig config;
2252 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2253 session_->SetIceConfig(config);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002254 // Bring down the network interface to trigger candidate removals.
2255 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2256 // Verify that all local candidates are removed.
2257 EXPECT_EQ(0, observer_.num_candidates_removed_);
2258 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2259 kIceCandidatesTimeout);
2260 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2261}
2262
2263// Tests that if continual gathering is disabled, local candidates won't be
2264// removed when the interface is turned down.
2265TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2266 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2267 Init();
2268 SendAudioVideoStream1();
2269 CreateAndSetRemoteOfferAndLocalAnswer();
2270
2271 const SessionDescriptionInterface* local_desc = session_->local_description();
2272 const IceCandidateCollection* candidates =
2273 local_desc->candidates(kMediaContentIndex0);
2274 ASSERT_TRUE(candidates != NULL);
2275 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2276
2277 size_t num_local_candidates = candidates->count();
2278 EXPECT_LT(0u, num_local_candidates);
2279 // By default, Continual Gathering is disabled.
2280 // Bring down the network interface.
2281 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2282 // Verify that the local candidates are not removed.
2283 rtc::Thread::Current()->ProcessMessages(1000);
2284 EXPECT_EQ(0, observer_.num_candidates_removed_);
2285 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286}
2287
2288// Test that we can set a remote session description with remote candidates.
2289TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002290 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
2292 cricket::Candidate candidate1;
2293 candidate1.set_component(1);
2294 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2295 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002296 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002297 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298
2299 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2300 SetRemoteDescriptionWithoutError(offer);
2301
2302 const SessionDescriptionInterface* remote_desc =
2303 session_->remote_description();
2304 ASSERT_TRUE(remote_desc != NULL);
2305 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2306 const IceCandidateCollection* candidates =
2307 remote_desc->candidates(kMediaContentIndex0);
2308 ASSERT_EQ(1u, candidates->count());
2309 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2310
htaa2a49d92016-03-04 02:51:39 -08002311 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 SetLocalDescriptionWithoutError(answer);
2313}
2314
2315// Test that offers and answers contains ice candidates when Ice candidates have
2316// been gathered.
2317TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002318 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002319 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002320 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 // Ice is started but candidates are not provided until SetLocalDescription
2322 // is called.
2323 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2324 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2325 CreateAndSetRemoteOfferAndLocalAnswer();
2326 // Wait until at least one local candidate has been collected.
2327 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2328 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329
kwibergd1fe2812016-04-27 06:47:29 -07002330 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2333 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334
2335 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2336 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002337 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2339 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 SetLocalDescriptionWithoutError(answer);
2341}
2342
2343// Verifies TransportProxy and media channels are created with content names
2344// present in the SessionDescription.
2345TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002346 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002347 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002348 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
2350 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002351 // "video". Goal is to modify these content names and verify transport
2352 // channels
2353 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 // present in SDP.
2355 std::string sdp;
2356 EXPECT_TRUE(offer->ToString(&sdp));
2357 const std::string kAudioMid = "a=mid:audio";
2358 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2359 const std::string kVideoMid = "a=mid:video";
2360 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2361
2362 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002363 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 kAudioMidReplaceStr.c_str(),
2365 kAudioMidReplaceStr.length(),
2366 &sdp);
2367 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002368 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 kVideoMidReplaceStr.c_str(),
2370 kVideoMidReplaceStr.length(),
2371 &sdp);
2372
2373 SessionDescriptionInterface* modified_offer =
2374 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2375
2376 SetRemoteDescriptionWithoutError(modified_offer);
2377
htaa2a49d92016-03-04 02:51:39 -08002378 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 SetLocalDescriptionWithoutError(answer);
2380
deadbeefcbecd352015-09-23 11:50:27 -07002381 cricket::TransportChannel* voice_transport_channel =
2382 session_->voice_rtp_transport_channel();
2383 EXPECT_TRUE(voice_transport_channel != NULL);
2384 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2385 cricket::TransportChannel* video_transport_channel =
2386 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002387 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002388 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2390 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2391}
2392
2393// Test that an offer contains the correct media content descriptions based on
2394// the send streams when no constraints have been set.
2395TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002396 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002397 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 ASSERT_TRUE(offer != NULL);
2400 const cricket::ContentInfo* content =
2401 cricket::GetFirstAudioContent(offer->description());
2402 EXPECT_TRUE(content != NULL);
2403 content = cricket::GetFirstVideoContent(offer->description());
2404 EXPECT_TRUE(content == NULL);
2405}
2406
2407// Test that an offer contains the correct media content descriptions based on
2408// the send streams when no constraints have been set.
2409TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002410 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002412 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002413 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 const cricket::ContentInfo* content =
2416 cricket::GetFirstAudioContent(offer->description());
2417 EXPECT_TRUE(content != NULL);
2418 content = cricket::GetFirstVideoContent(offer->description());
2419 EXPECT_TRUE(content == NULL);
2420
2421 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002422 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002423 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 content = cricket::GetFirstAudioContent(offer->description());
2425 EXPECT_TRUE(content != NULL);
2426 content = cricket::GetFirstVideoContent(offer->description());
2427 EXPECT_TRUE(content != NULL);
2428}
2429
2430// Test that an offer contains no media content descriptions if
2431// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2432TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002433 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434 PeerConnectionInterface::RTCOfferAnswerOptions options;
2435 options.offer_to_receive_audio = 0;
2436 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437
kwibergd1fe2812016-04-27 06:47:29 -07002438 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 ASSERT_TRUE(offer != NULL);
2441 const cricket::ContentInfo* content =
2442 cricket::GetFirstAudioContent(offer->description());
2443 EXPECT_TRUE(content == NULL);
2444 content = cricket::GetFirstVideoContent(offer->description());
2445 EXPECT_TRUE(content == NULL);
2446}
2447
2448// Test that an offer contains only audio media content descriptions if
2449// kOfferToReceiveAudio constraints are set to true.
2450TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002451 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002452 PeerConnectionInterface::RTCOfferAnswerOptions options;
2453 options.offer_to_receive_audio =
2454 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2455
kwibergd1fe2812016-04-27 06:47:29 -07002456 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457
2458 const cricket::ContentInfo* content =
2459 cricket::GetFirstAudioContent(offer->description());
2460 EXPECT_TRUE(content != NULL);
2461 content = cricket::GetFirstVideoContent(offer->description());
2462 EXPECT_TRUE(content == NULL);
2463}
2464
2465// Test that an offer contains audio and video media content descriptions if
2466// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2467TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002468 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470 PeerConnectionInterface::RTCOfferAnswerOptions options;
2471 options.offer_to_receive_audio =
2472 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2473 options.offer_to_receive_video =
2474 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2475
kwibergd1fe2812016-04-27 06:47:29 -07002476 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 const cricket::ContentInfo* content =
2479 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002480 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 content = cricket::GetFirstVideoContent(offer->description());
2483 EXPECT_TRUE(content != NULL);
2484
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002485 // Sets constraints to false and verifies that audio/video contents are
2486 // removed.
2487 options.offer_to_receive_audio = 0;
2488 options.offer_to_receive_video = 0;
2489 offer.reset(CreateOffer(options));
2490
2491 content = cricket::GetFirstAudioContent(offer->description());
2492 EXPECT_TRUE(content == NULL);
2493 content = cricket::GetFirstVideoContent(offer->description());
2494 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495}
2496
2497// Test that an answer can not be created if the last remote description is not
2498// an offer.
2499TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002500 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002501 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 SetLocalDescriptionWithoutError(offer);
2503 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2504 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002505 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506}
2507
2508// Test that an answer contains the correct media content descriptions when no
2509// constraints have been set.
2510TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002511 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002513 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002515 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 const cricket::ContentInfo* content =
2517 cricket::GetFirstAudioContent(answer->description());
2518 ASSERT_TRUE(content != NULL);
2519 EXPECT_FALSE(content->rejected);
2520
2521 content = cricket::GetFirstVideoContent(answer->description());
2522 ASSERT_TRUE(content != NULL);
2523 EXPECT_FALSE(content->rejected);
2524}
2525
2526// Test that an answer contains the correct media content descriptions when no
2527// constraints have been set and the offer only contain audio.
2528TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002529 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 // Create a remote offer with audio only.
2531 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002532
kwibergd1fe2812016-04-27 06:47:29 -07002533 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2535 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2536
2537 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002538 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 const cricket::ContentInfo* content =
2540 cricket::GetFirstAudioContent(answer->description());
2541 ASSERT_TRUE(content != NULL);
2542 EXPECT_FALSE(content->rejected);
2543
2544 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2545}
2546
2547// Test that an answer contains the correct media content descriptions when no
2548// constraints have been set.
2549TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002550 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002552 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 SetRemoteDescriptionWithoutError(offer.release());
2554 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002555 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002556 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 const cricket::ContentInfo* content =
2558 cricket::GetFirstAudioContent(answer->description());
2559 ASSERT_TRUE(content != NULL);
2560 EXPECT_FALSE(content->rejected);
2561
2562 content = cricket::GetFirstVideoContent(answer->description());
2563 ASSERT_TRUE(content != NULL);
2564 EXPECT_FALSE(content->rejected);
2565}
2566
2567// Test that an answer contains the correct media content descriptions when
2568// constraints have been set but no stream is sent.
2569TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002570 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002572 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 SetRemoteDescriptionWithoutError(offer.release());
2574
htaa2a49d92016-03-04 02:51:39 -08002575 cricket::MediaSessionOptions session_options;
2576 session_options.recv_audio = false;
2577 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002578 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002579 CreateAnswer(session_options));
2580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 const cricket::ContentInfo* content =
2582 cricket::GetFirstAudioContent(answer->description());
2583 ASSERT_TRUE(content != NULL);
2584 EXPECT_TRUE(content->rejected);
2585
2586 content = cricket::GetFirstVideoContent(answer->description());
2587 ASSERT_TRUE(content != NULL);
2588 EXPECT_TRUE(content->rejected);
2589}
2590
2591// Test that an answer contains the correct media content descriptions when
2592// constraints have been set and streams are sent.
2593TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002596 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 SetRemoteDescriptionWithoutError(offer.release());
2598
htaa2a49d92016-03-04 02:51:39 -08002599 cricket::MediaSessionOptions options;
2600 options.recv_audio = false;
2601 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602
2603 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002604 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002605 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606
2607 // TODO(perkj): Should the direction be set to SEND_ONLY?
2608 const cricket::ContentInfo* content =
2609 cricket::GetFirstAudioContent(answer->description());
2610 ASSERT_TRUE(content != NULL);
2611 EXPECT_FALSE(content->rejected);
2612
2613 // TODO(perkj): Should the direction be set to SEND_ONLY?
2614 content = cricket::GetFirstVideoContent(answer->description());
2615 ASSERT_TRUE(content != NULL);
2616 EXPECT_FALSE(content->rejected);
2617}
2618
2619TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2620 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002622 PeerConnectionInterface::RTCOfferAnswerOptions options;
2623 options.offer_to_receive_audio =
2624 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2625 options.voice_activity_detection = false;
2626
kwibergd1fe2812016-04-27 06:47:29 -07002627 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002628
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629 const cricket::ContentInfo* content =
2630 cricket::GetFirstAudioContent(offer->description());
2631 EXPECT_TRUE(content != NULL);
2632 EXPECT_TRUE(VerifyNoCNCodecs(content));
2633}
2634
2635TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2636 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002637 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002639 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 SetRemoteDescriptionWithoutError(offer.release());
2641
htaa2a49d92016-03-04 02:51:39 -08002642 cricket::MediaSessionOptions options;
2643 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002644 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645 const cricket::ContentInfo* content =
2646 cricket::GetFirstAudioContent(answer->description());
2647 ASSERT_TRUE(content != NULL);
2648 EXPECT_TRUE(VerifyNoCNCodecs(content));
2649}
2650
2651// This test verifies the call setup when remote answer with audio only and
2652// later updates with video.
2653TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002654 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2656 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2657
deadbeefab9b2d12015-10-14 11:33:11 -07002658 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002659 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660
2661 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2663
2664 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2665 // and answer;
2666 SetLocalDescriptionWithoutError(offer);
2667 SetRemoteDescriptionWithoutError(answer);
2668
2669 video_channel_ = media_engine_->GetVideoChannel(0);
2670 voice_channel_ = media_engine_->GetVoiceChannel(0);
2671
2672 ASSERT_TRUE(video_channel_ == NULL);
2673
2674 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2675 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2676 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2677
2678 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002679 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 CreateAndSetRemoteOfferAndLocalAnswer();
2681
2682 video_channel_ = media_engine_->GetVideoChannel(0);
2683 voice_channel_ = media_engine_->GetVoiceChannel(0);
2684
2685 ASSERT_TRUE(video_channel_ != NULL);
2686 ASSERT_TRUE(voice_channel_ != NULL);
2687
2688 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2689 ASSERT_EQ(1u, video_channel_->send_streams().size());
2690 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2691 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2693 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2694 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2695 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2696
2697 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002698 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 CreateAndSetRemoteOfferAndLocalAnswer();
2700
2701 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2702 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2703 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2704 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2705 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2706}
2707
2708// This test verifies the call setup when remote answer with video only and
2709// later updates with audio.
2710TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002711 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2713 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002714 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002715 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716
2717 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002718 options.recv_audio = false;
2719 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2721 offer, options, cricket::SEC_ENABLED);
2722
2723 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2724 // and answer.
2725 SetLocalDescriptionWithoutError(offer);
2726 SetRemoteDescriptionWithoutError(answer);
2727
2728 video_channel_ = media_engine_->GetVideoChannel(0);
2729 voice_channel_ = media_engine_->GetVoiceChannel(0);
2730
2731 ASSERT_TRUE(voice_channel_ == NULL);
2732 ASSERT_TRUE(video_channel_ != NULL);
2733
2734 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2735 ASSERT_EQ(1u, video_channel_->send_streams().size());
2736 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2737
2738 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002739 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 CreateAndSetRemoteOfferAndLocalAnswer();
2741
2742 voice_channel_ = media_engine_->GetVoiceChannel(0);
2743 ASSERT_TRUE(voice_channel_ != NULL);
2744
2745 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2746 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2747 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2748 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2749
2750 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002751 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 CreateAndSetRemoteOfferAndLocalAnswer();
2753
2754 video_channel_ = media_engine_->GetVideoChannel(0);
2755 voice_channel_ = media_engine_->GetVoiceChannel(0);
2756
2757 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2758 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2759 ASSERT_EQ(1u, video_channel_->send_streams().size());
2760 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2761}
2762
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002764 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002765 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002766 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 VerifyCryptoParams(offer->description());
2768 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002769 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770 VerifyCryptoParams(answer->description());
2771}
2772
2773TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002774 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002776 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002777 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778 VerifyNoCryptoParams(offer->description(), false);
2779}
2780
2781TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002782 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783 VerifyAnswerFromNonCryptoOffer();
2784}
2785
2786TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 VerifyAnswerFromCryptoOffer();
2789}
2790
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002791// This test verifies that setLocalDescription fails if
2792// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2793TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002794 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002795 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002796 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002797
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002798 std::string sdp;
2799 RemoveIceUfragPwdLines(offer.get(), &sdp);
2800 SessionDescriptionInterface* modified_offer =
2801 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002802 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002803}
2804
2805// This test verifies that setRemoteDescription fails if
2806// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2807TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002808 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002809 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002810 std::string sdp;
2811 RemoveIceUfragPwdLines(offer.get(), &sdp);
2812 SessionDescriptionInterface* modified_offer =
2813 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002814 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002815}
2816
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002817// This test verifies that setLocalDescription fails if local offer has
2818// too short ice ufrag and pwd strings.
2819TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002820 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002821 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002822 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002823 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2824 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002825 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002826 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002827 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002828
2829 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002830 offer.reset(CreateOffer());
2831 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2832 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002833}
2834
2835// This test verifies that setRemoteDescription fails if remote offer has
2836// too short ice ufrag and pwd strings.
2837TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002838 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002839 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002840 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2841 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002842 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002843 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002844 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002845
deadbeef0ed85b22016-02-23 17:24:52 -08002846 offer.reset(CreateRemoteOffer());
2847 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2848 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002849}
2850
Honghai Zhang04e91462015-12-11 14:26:22 -08002851// Test that if the remote offer indicates the peer requested ICE restart (via
2852// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2853TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002854 Init();
honghaiz503726c2015-07-31 12:37:38 -07002855
2856 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002857 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002858 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002859 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2860 0, "", "", "relay", 0, "");
2861 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2862 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002863 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2864 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002865 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2866
2867 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002868 offer.reset(CreateRemoteOffer());
2869 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002870 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2871 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2872 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002873 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2874 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002875 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2876
2877 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002878 offer.reset(CreateRemoteOffer());
2879 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002880 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2881 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2882 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002883 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2884 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002885 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2886
2887 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002888 offer.reset(CreateRemoteOffer());
2889 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2890 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002891 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2892}
2893
Honghai Zhang04e91462015-12-11 14:26:22 -08002894// Test that if the remote answer indicates the peer requested ICE restart (via
2895// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2896TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2897 Init();
2898 SessionDescriptionInterface* offer = CreateOffer();
2899 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002900
2901 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002902 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002903 answer->set_type(JsepSessionDescription::kPrAnswer);
2904 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002905 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2906 0, "", "", "relay", 0, "");
2907 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2908 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002909 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2910 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002911 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2912
2913 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002914 answer.reset(CreateRemoteAnswer(offer));
2915 answer->set_type(JsepSessionDescription::kPrAnswer);
2916 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002917 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2918 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2919 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002920 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2921 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002922 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2923
2924 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002925 answer.reset(CreateRemoteAnswer(offer));
2926 answer->set_type(JsepSessionDescription::kPrAnswer);
2927 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002928 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2929 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2930 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002931 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2932 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002933 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2934
2935 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002936 answer.reset(CreateRemoteAnswer(offer));
2937 answer->set_type(JsepSessionDescription::kPrAnswer);
2938 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2939 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002940 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2941}
2942
Donald Curtisd4f769d2015-05-28 09:48:21 -07002943// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002944// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002945TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2946 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2947
2948 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002949 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002950
2951 PeerConnectionInterface::RTCOfferAnswerOptions options;
2952 options.use_rtp_mux = true;
2953
2954 SessionDescriptionInterface* offer = CreateRemoteOffer();
2955 SetRemoteDescriptionWithoutError(offer);
2956
htaa2a49d92016-03-04 02:51:39 -08002957 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002958 SetLocalDescriptionWithoutError(answer);
2959
deadbeefcbecd352015-09-23 11:50:27 -07002960 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2961 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002962
deadbeefcbecd352015-09-23 11:50:27 -07002963 cricket::BaseChannel* voice_channel = session_->voice_channel();
2964 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002965
2966 // Checks if one of the transport channels contains a connection using a given
2967 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002968 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002969 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002970 session_->GetChannelTransportStats(voice_channel, &stats);
2971 for (auto& kv : stats.transport_stats) {
2972 for (auto& chan_stat : kv.second.channel_stats) {
2973 for (auto& conn_info : chan_stat.connection_infos) {
2974 if (conn_info.remote_candidate.address().port() == port) {
2975 return true;
2976 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002977 }
2978 }
2979 }
2980 return false;
2981 };
2982
2983 EXPECT_FALSE(connection_with_remote_port(5000));
2984 EXPECT_FALSE(connection_with_remote_port(5001));
2985 EXPECT_FALSE(connection_with_remote_port(6000));
2986
2987 // The way the *_WAIT checks work is they only wait if the condition fails,
2988 // which does not help in the case where state is not changing. This is
2989 // problematic in this test since we want to verify that adding a video
2990 // candidate does _not_ change state. So we interleave candidates and assume
2991 // that messages are executed in the order they were posted.
2992
2993 // First audio candidate.
2994 cricket::Candidate candidate0;
2995 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2996 candidate0.set_component(1);
2997 candidate0.set_protocol("udp");
2998 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2999 candidate0);
3000 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3001
3002 // Video candidate.
3003 cricket::Candidate candidate1;
3004 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3005 candidate1.set_component(1);
3006 candidate1.set_protocol("udp");
3007 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3008 candidate1);
3009 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3010
3011 // Second audio candidate.
3012 cricket::Candidate candidate2;
3013 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3014 candidate2.set_component(1);
3015 candidate2.set_protocol("udp");
3016 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3017 candidate2);
3018 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3019
3020 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3021 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3022
3023 // No need here for a _WAIT check since we are checking that state hasn't
3024 // changed: if this is false we would be doing waits for nothing and if this
3025 // is true then there will be no messages processed anyways.
3026 EXPECT_FALSE(connection_with_remote_port(6000));
3027}
3028
deadbeefcbecd352015-09-23 11:50:27 -07003029// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003030TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3031 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003032 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003033
3034 PeerConnectionInterface::RTCOfferAnswerOptions options;
3035 options.use_rtp_mux = true;
3036
3037 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003039
deadbeefcbecd352015-09-23 11:50:27 -07003040 EXPECT_NE(session_->voice_rtp_transport_channel(),
3041 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003042
deadbeefab9b2d12015-10-14 11:33:11 -07003043 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003044 SessionDescriptionInterface* answer =
3045 CreateRemoteAnswer(session_->local_description());
3046 SetRemoteDescriptionWithoutError(answer);
3047
deadbeefcbecd352015-09-23 11:50:27 -07003048 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3049 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003050}
3051
deadbeefcbecd352015-09-23 11:50:27 -07003052// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003053TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3054 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003055 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003056
Donald Curtis0e209b02015-03-24 09:29:54 -07003057 PeerConnectionInterface::RTCOfferAnswerOptions options;
3058 options.use_rtp_mux = true;
3059
3060 SessionDescriptionInterface* offer = CreateOffer(options);
3061 SetLocalDescriptionWithoutError(offer);
3062
deadbeefcbecd352015-09-23 11:50:27 -07003063 EXPECT_NE(session_->voice_rtp_transport_channel(),
3064 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003065
deadbeefab9b2d12015-10-14 11:33:11 -07003066 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003067
3068 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003069 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003070 CreateRemoteAnswer(session_->local_description()));
3071 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3072 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3073 JsepSessionDescription* modified_answer =
3074 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3075 modified_answer->Initialize(answer_copy, "1", "1");
3076 SetRemoteDescriptionWithoutError(modified_answer); //
3077
deadbeefcbecd352015-09-23 11:50:27 -07003078 EXPECT_NE(session_->voice_rtp_transport_channel(),
3079 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003080}
3081
3082// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3083TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3084 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003085 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003086
3087 PeerConnectionInterface::RTCOfferAnswerOptions options;
3088 options.use_rtp_mux = true;
3089
3090 SessionDescriptionInterface* offer = CreateOffer(options);
3091 SetLocalDescriptionWithoutError(offer);
3092
deadbeefcbecd352015-09-23 11:50:27 -07003093 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3094 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003095
deadbeefab9b2d12015-10-14 11:33:11 -07003096 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003097 SessionDescriptionInterface* answer =
3098 CreateRemoteAnswer(session_->local_description());
3099 SetRemoteDescriptionWithoutError(answer);
3100
deadbeefcbecd352015-09-23 11:50:27 -07003101 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3102 session_->video_rtp_transport_channel());
3103}
3104
3105// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3106// audio content in the answer.
3107TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3108 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003109 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003110
3111 PeerConnectionInterface::RTCOfferAnswerOptions options;
3112 options.use_rtp_mux = true;
3113
3114 SessionDescriptionInterface* offer = CreateOffer(options);
3115 SetLocalDescriptionWithoutError(offer);
3116
3117 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3118 session_->video_rtp_transport_channel());
3119
deadbeefab9b2d12015-10-14 11:33:11 -07003120 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003121 cricket::MediaSessionOptions recv_options;
3122 recv_options.recv_audio = false;
3123 recv_options.recv_video = true;
3124 SessionDescriptionInterface* answer =
3125 CreateRemoteAnswer(session_->local_description(), recv_options);
3126 SetRemoteDescriptionWithoutError(answer);
3127
deadbeefd59daf82015-10-14 15:02:44 -07003128 EXPECT_TRUE(nullptr == session_->voice_channel());
3129 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003130
deadbeefd59daf82015-10-14 15:02:44 -07003131 session_->Close();
3132 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3133 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3134 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3135 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003136}
3137
3138// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3139TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3140 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003141 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003142
Donald Curtis0e209b02015-03-24 09:29:54 -07003143 PeerConnectionInterface::RTCOfferAnswerOptions options;
3144 options.use_rtp_mux = true;
3145
3146 SessionDescriptionInterface* offer = CreateOffer(options);
3147 SetLocalDescriptionWithoutError(offer);
3148
deadbeefcbecd352015-09-23 11:50:27 -07003149 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3150 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003151
deadbeefab9b2d12015-10-14 11:33:11 -07003152 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003153
3154 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003155 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156 CreateRemoteAnswer(session_->local_description()));
3157 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3158 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3159 JsepSessionDescription* modified_answer =
3160 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3161 modified_answer->Initialize(answer_copy, "1", "1");
3162 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003163
deadbeefcbecd352015-09-23 11:50:27 -07003164 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3165 session_->video_rtp_transport_channel());
3166}
3167
3168// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3169TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3170 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003171 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003172
3173 SessionDescriptionInterface* offer = CreateRemoteOffer();
3174 SetRemoteDescriptionWithoutError(offer);
3175
3176 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3177 session_->video_rtp_transport_channel());
3178
deadbeefab9b2d12015-10-14 11:33:11 -07003179 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003180 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003181 SetLocalDescriptionWithoutError(answer);
3182
3183 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3184 session_->video_rtp_transport_channel());
3185}
3186
3187// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3188TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3189 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003190 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003191
3192 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003193 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003194 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3195 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3196 JsepSessionDescription* modified_offer =
3197 new JsepSessionDescription(JsepSessionDescription::kOffer);
3198 modified_offer->Initialize(offer_copy, "1", "1");
3199
3200 // Expect an error when applying the remote description
3201 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3202 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003203}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003204
Peter Thatcher4eddf182015-04-30 10:55:59 -07003205// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003206TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3207 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003208 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209
Donald Curtis0e209b02015-03-24 09:29:54 -07003210 PeerConnectionInterface::RTCOfferAnswerOptions options;
3211 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003212
Donald Curtis0e209b02015-03-24 09:29:54 -07003213 SessionDescriptionInterface* offer = CreateOffer(options);
3214 SetLocalDescriptionWithoutError(offer);
3215
deadbeefcbecd352015-09-23 11:50:27 -07003216 EXPECT_NE(session_->voice_rtp_transport_channel(),
3217 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003218
deadbeefab9b2d12015-10-14 11:33:11 -07003219 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003220 SessionDescriptionInterface* answer =
3221 CreateRemoteAnswer(session_->local_description());
3222 SetRemoteDescriptionWithoutError(answer);
3223
3224 // This should lead to an audio-only call but isn't implemented
3225 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003226 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3227 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003228}
3229
deadbeefcbecd352015-09-23 11:50:27 -07003230// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003231TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3232 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003233 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003234 PeerConnectionInterface::RTCOfferAnswerOptions options;
3235 options.use_rtp_mux = true;
3236
3237 SessionDescriptionInterface* offer = CreateOffer(options);
3238 SetLocalDescriptionWithoutError(offer);
3239
deadbeefcbecd352015-09-23 11:50:27 -07003240 EXPECT_NE(session_->voice_rtp_transport_channel(),
3241 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003242
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003244
3245 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003246 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003247 CreateRemoteAnswer(session_->local_description()));
3248 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3249 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3250 JsepSessionDescription* modified_answer =
3251 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3252 modified_answer->Initialize(answer_copy, "1", "1");
3253 SetRemoteDescriptionWithoutError(modified_answer); //
3254
deadbeefcbecd352015-09-23 11:50:27 -07003255 EXPECT_NE(session_->voice_rtp_transport_channel(),
3256 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257}
3258
Peter Thatcher4eddf182015-04-30 10:55:59 -07003259// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3260TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3261 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003262 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003263
3264 PeerConnectionInterface::RTCOfferAnswerOptions options;
3265 options.use_rtp_mux = true;
3266
3267 SessionDescriptionInterface* offer = CreateOffer(options);
3268 SetRemoteDescriptionWithoutError(offer);
3269
deadbeefcbecd352015-09-23 11:50:27 -07003270 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3271 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003272}
3273
skvlad6c87a672016-05-17 17:49:52 -07003274// Adding a new channel to a BUNDLE which is already connected should directly
3275// assign the bundle transport to the channel, without first setting a
3276// disconnected non-bundle transport and then replacing it. The application
3277// should not receive any changes in the ICE state.
3278TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3279 LoopbackNetworkConfiguration config;
3280 LoopbackNetworkManager loopback_network_manager(this, config);
3281 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3282 // connected. Disabling either of these two means that we need to wait for the
3283 // answer to find out if more transports are needed.
3284 configuration_.bundle_policy =
3285 PeerConnectionInterface::kBundlePolicyMaxBundle;
3286 configuration_.rtcp_mux_policy =
3287 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3288 options_.disable_encryption = true;
3289 Init();
3290
3291 // Negotiate an audio channel with MAX_BUNDLE enabled.
3292 SendAudioOnlyStream2();
3293 SessionDescriptionInterface* offer = CreateOffer();
3294 SetLocalDescriptionWithoutError(offer);
3295 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3296 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3297 std::string sdp;
3298 offer->ToString(&sdp);
3299 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3300 JsepSessionDescription::kAnswer, sdp, nullptr);
3301 ASSERT_TRUE(answer != NULL);
3302 SetRemoteDescriptionWithoutError(answer);
3303
3304 // Wait for the ICE state to stabilize.
3305 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3306 observer_.ice_connection_state_, kIceCandidatesTimeout);
3307 observer_.ice_connection_state_history_.clear();
3308
3309 // Now add a video channel which should be using the same bundle transport.
3310 SendAudioVideoStream2();
3311 offer = CreateOffer();
3312 offer->ToString(&sdp);
3313 SetLocalDescriptionWithoutError(offer);
3314 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3315 sdp, nullptr);
3316 ASSERT_TRUE(answer != NULL);
3317 SetRemoteDescriptionWithoutError(answer);
3318
3319 // Wait for ICE state to stabilize
3320 rtc::Thread::Current()->ProcessMessages(0);
3321 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3322 observer_.ice_connection_state_, kIceCandidatesTimeout);
3323
3324 // No ICE state changes are expected to happen.
3325 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3326}
3327
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003328TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3329 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003330 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003331
3332 PeerConnectionInterface::RTCOfferAnswerOptions options;
3333 SessionDescriptionInterface* offer = CreateOffer(options);
3334 SetLocalDescriptionWithoutError(offer);
3335
deadbeefcbecd352015-09-23 11:50:27 -07003336 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3337 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003338
deadbeefab9b2d12015-10-14 11:33:11 -07003339 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003340 SessionDescriptionInterface* answer =
3341 CreateRemoteAnswer(session_->local_description());
3342 SetRemoteDescriptionWithoutError(answer);
3343
deadbeefcbecd352015-09-23 11:50:27 -07003344 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3345 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003346}
3347
3348TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3349 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003350 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003351
3352 PeerConnectionInterface::RTCOfferAnswerOptions options;
3353 SessionDescriptionInterface* offer = CreateOffer(options);
3354 SetLocalDescriptionWithoutError(offer);
3355
deadbeefcbecd352015-09-23 11:50:27 -07003356 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3357 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003358
deadbeefab9b2d12015-10-14 11:33:11 -07003359 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003360 SessionDescriptionInterface* answer =
3361 CreateRemoteAnswer(session_->local_description());
3362 SetRemoteDescriptionWithoutError(answer);
3363
deadbeefcbecd352015-09-23 11:50:27 -07003364 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3365 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003366}
3367
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003368// This test verifies that SetLocalDescription and SetRemoteDescription fails
3369// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3370TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003371 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003372 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003373
3374 PeerConnectionInterface::RTCOfferAnswerOptions options;
3375 options.use_rtp_mux = true;
3376
3377 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003378 std::string offer_str;
3379 offer->ToString(&offer_str);
3380 // Disable rtcp-mux
3381 const std::string rtcp_mux = "rtcp-mux";
3382 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003383 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003384 xrtcp_mux.c_str(), xrtcp_mux.length(),
3385 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003386 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003387 new JsepSessionDescription(JsepSessionDescription::kOffer);
3388 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003389 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003390 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003391 new JsepSessionDescription(JsepSessionDescription::kOffer);
3392 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003393 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003394 // Trying unmodified SDP.
3395 SetLocalDescriptionWithoutError(offer);
3396}
3397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3399 TestCanInsertDtmf(false);
3400}
3401
3402TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3403 TestCanInsertDtmf(true);
3404}
3405
3406TEST_F(WebRtcSessionTest, InsertDtmf) {
3407 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003408 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003409 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 CreateAndSetRemoteOfferAndLocalAnswer();
3411 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3412 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3413
3414 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 const int expected_duration = 90;
3416 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3417 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3418 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3419
3420 // Verify
3421 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003422 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003424 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003426 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003428 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429}
3430
deadbeefd59daf82015-10-14 15:02:44 -07003431// This test verifies the |initial_offerer| flag when session initiates the
3432// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003434 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003435 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003436 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3438 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003439 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003441 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442}
3443
deadbeefd59daf82015-10-14 15:02:44 -07003444// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003446 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003447 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 SessionDescriptionInterface* offer = CreateRemoteOffer();
3449 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003450 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451
deadbeefd59daf82015-10-14 15:02:44 -07003452 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003454 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455}
3456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3458TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003459 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003460 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003461 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003463 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 CreateRemoteAnswer(session_->local_description()));
3465
3466 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3467 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003468 JsepSessionDescription* modified_answer =
3469 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470
3471 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3472 answer->session_id(),
3473 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003474 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475
wu@webrtc.org4e393072014-04-07 17:04:35 +00003476 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 std::string sdp;
3478 EXPECT_TRUE(answer->ToString(&sdp));
3479 const std::string kAudioMid = "a=mid:audio";
3480 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003481 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 kAudioMidReplaceStr.c_str(),
3483 kAudioMidReplaceStr.length(),
3484 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003485 SessionDescriptionInterface* modified_answer1 =
3486 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003487 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488
wu@webrtc.org4e393072014-04-07 17:04:35 +00003489 // Different media types.
3490 EXPECT_TRUE(answer->ToString(&sdp));
3491 const std::string kAudioMline = "m=audio";
3492 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003493 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003494 kAudioMlineReplaceStr.c_str(),
3495 kAudioMlineReplaceStr.length(),
3496 &sdp);
3497 SessionDescriptionInterface* modified_answer2 =
3498 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3499 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SetRemoteDescriptionWithoutError(answer.release());
3502}
3503
3504// Verifying remote offer and local answer have matching m-lines as per
3505// RFC 3264.
3506TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003507 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003508 SendAudioVideoStream1();
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
3513 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3514 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003515 JsepSessionDescription* modified_answer =
3516 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517
3518 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3519 answer->session_id(),
3520 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003521 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522 SetLocalDescriptionWithoutError(answer);
3523}
3524
3525// This test verifies that WebRtcSession does not start candidate allocation
3526// before SetLocalDescription is called.
3527TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003528 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003529 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 SessionDescriptionInterface* offer = CreateRemoteOffer();
3531 cricket::Candidate candidate;
3532 candidate.set_component(1);
3533 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3534 candidate);
3535 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3536 cricket::Candidate candidate1;
3537 candidate1.set_component(1);
3538 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3539 candidate1);
3540 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3541 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003542 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3543 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544
3545 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003546 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3548 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3549
htaa2a49d92016-03-04 02:51:39 -08003550 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3553}
3554
3555// This test verifies that crypto parameter is updated in local session
3556// description as per security policy set in MediaSessionDescriptionFactory.
3557TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003558 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003559 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003560 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003561
3562 // Making sure SetLocalDescription correctly sets crypto value in
3563 // SessionDescription object after de-serialization of sdp string. The value
3564 // will be set as per MediaSessionDescriptionFactory.
3565 std::string offer_str;
3566 offer->ToString(&offer_str);
3567 SessionDescriptionInterface* jsep_offer_str =
3568 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3569 SetLocalDescriptionWithoutError(jsep_offer_str);
3570 EXPECT_TRUE(session_->voice_channel()->secure_required());
3571 EXPECT_TRUE(session_->video_channel()->secure_required());
3572}
3573
3574// This test verifies the crypto parameter when security is disabled.
3575TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003576 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003577 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003578 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003579 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
3581 // Making sure SetLocalDescription correctly sets crypto value in
3582 // SessionDescription object after de-serialization of sdp string. The value
3583 // will be set as per MediaSessionDescriptionFactory.
3584 std::string offer_str;
3585 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003586 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3588 SetLocalDescriptionWithoutError(jsep_offer_str);
3589 EXPECT_FALSE(session_->voice_channel()->secure_required());
3590 EXPECT_FALSE(session_->video_channel()->secure_required());
3591}
3592
3593// This test verifies that an answer contains new ufrag and password if an offer
3594// with new ufrag and password is received.
3595TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003596 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003598 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003599 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 SetRemoteDescriptionWithoutError(offer.release());
3601
deadbeefab9b2d12015-10-14 11:33:11 -07003602 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003603 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003604 SetLocalDescriptionWithoutError(answer.release());
3605
3606 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003607 for (const cricket::ContentInfo& content :
3608 session_->local_description()->description()->contents()) {
3609 options.transport_options[content.name].ice_restart = true;
3610 }
kwibergd1fe2812016-04-27 06:47:29 -07003611 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003612 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613 SetRemoteDescriptionWithoutError(updated_offer1.release());
3614
kwibergd1fe2812016-04-27 06:47:29 -07003615 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616
deadbeef0ed85b22016-02-23 17:24:52 -08003617 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3618 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619
deadbeef0ed85b22016-02-23 17:24:52 -08003620 // Even a second answer (created before the description is set) should have
3621 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003622 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003623
3624 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3625 session_->local_description()->description()));
3626
3627 SetLocalDescriptionWithoutError(updated_answer2.release());
3628}
3629
3630// This test verifies that an answer contains new ufrag and password if an offer
3631// that changes either the ufrag or password (but not both) is received.
3632// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3633// a=ice-pwd attributes compared to the previous SDP from the peer, it
3634// indicates that ICE is restarting for this media stream."
3635TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3636 Init();
3637 cricket::MediaSessionOptions options;
3638 options.recv_audio = true;
3639 options.recv_video = true;
3640 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003641 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003642 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3643 SetRemoteDescriptionWithoutError(offer.release());
3644
3645 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003646 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003647 SetLocalDescriptionWithoutError(answer.release());
3648
3649 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003650 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003651 CreateRemoteOffer(options, session_->remote_description()));
3652 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3653 "original_password12345");
3654 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3655
kwibergd1fe2812016-04-27 06:47:29 -07003656 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003657 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3658 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003660
3661 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003662 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003663 CreateRemoteOffer(options, session_->remote_description()));
3664 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3665 "modified_password12345");
3666 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3667
kwibergd1fe2812016-04-27 06:47:29 -07003668 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003669 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3670 session_->local_description()->description()));
3671 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003672}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673
wu@webrtc.org91053e72013-08-10 07:18:04 +00003674// This test verifies that an answer contains old ufrag and password if an offer
3675// with old ufrag and password is received.
3676TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003677 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003678 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003679 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003680 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003681 SetRemoteDescriptionWithoutError(offer.release());
3682
deadbeefab9b2d12015-10-14 11:33:11 -07003683 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003684 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003685 SetLocalDescriptionWithoutError(answer.release());
3686
3687 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003688 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003689 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690 SetRemoteDescriptionWithoutError(updated_offer2.release());
3691
kwibergd1fe2812016-04-27 06:47:29 -07003692 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003693
deadbeef0ed85b22016-02-23 17:24:52 -08003694 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3695 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003696
3697 SetLocalDescriptionWithoutError(updated_answer2.release());
3698}
3699
deadbeef0ed85b22016-02-23 17:24:52 -08003700// This test verifies that if an offer does an ICE restart on some, but not all
3701// media sections, the answer will change the ufrag/password in the correct
3702// media sections.
3703TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3704 Init();
3705 cricket::MediaSessionOptions options;
3706 options.recv_video = true;
3707 options.recv_audio = true;
3708 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003709 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003710
3711 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3712 "aaaaaaaaaaaaaaaaaaaaaa");
3713 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3714 "bbbbbbbbbbbbbbbbbbbbbb");
3715 SetRemoteDescriptionWithoutError(offer.release());
3716
3717 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003718 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003719 SetLocalDescriptionWithoutError(answer.release());
3720
3721 // Receive an offer with new ufrag and password, but only for the video media
3722 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003724 CreateRemoteOffer(options, session_->remote_description()));
3725 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3726 "cccccccccccccccccccccc");
3727 SetRemoteDescriptionWithoutError(updated_offer.release());
3728
kwibergd1fe2812016-04-27 06:47:29 -07003729 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003730
3731 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3732 session_->local_description()->description(),
3733 cricket::MEDIA_TYPE_AUDIO));
3734
3735 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3736 session_->local_description()->description(),
3737 cricket::MEDIA_TYPE_VIDEO));
3738
3739 SetLocalDescriptionWithoutError(updated_answer.release());
3740}
3741
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003743 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003744 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003745 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746 const std::string session_id_orig = offer->session_id();
3747 const std::string session_version_orig = offer->session_version();
3748 SetLocalDescriptionWithoutError(offer);
3749
3750 video_channel_ = media_engine_->GetVideoChannel(0);
3751 video_channel_->set_fail_set_send_codecs(true);
3752
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003753 SessionDescriptionInterface* answer =
3754 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003755 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003756
3757 // Test that after a content error, setting any description will
3758 // result in an error.
3759 video_channel_->set_fail_set_send_codecs(false);
3760 answer = CreateRemoteAnswer(session_->local_description());
3761 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3762 offer = CreateRemoteOffer();
3763 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003764}
3765
3766// Runs the loopback call test with BUNDLE and STUN disabled.
3767TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3768 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003769 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003770 cricket::PORTALLOCATOR_DISABLE_STUN |
3771 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003772 TestLoopbackCall();
3773}
3774
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003775TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003776 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003777 cricket::PORTALLOCATOR_DISABLE_STUN |
3778 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3779 cricket::PORTALLOCATOR_DISABLE_RELAY);
3780
3781 // best connection is IPv6 since it has higher network preference.
3782 LoopbackNetworkConfiguration config;
3783 config.test_ipv6_network_ = true;
3784 config.best_connection_after_initial_ice_converged_ =
3785 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3786
3787 TestLoopbackCall(config);
3788}
3789
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003790// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003791TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003792 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3793 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003794 TestLoopbackCall();
3795}
3796
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003797TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003798 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003799 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003800 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003801 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003802 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3803}
3804
Henrik Boström87713d02015-08-25 09:53:21 +02003805TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003806 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003807
htaa2a49d92016-03-04 02:51:39 -08003808 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003809 options_.disable_sctp_data_channels = false;
3810
Henrik Boström87713d02015-08-25 09:53:21 +02003811 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003812
3813 SetLocalDescriptionWithDataChannel();
3814 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3815}
3816
Henrik Boström87713d02015-08-25 09:53:21 +02003817TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003818 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003819
Henrik Boström87713d02015-08-25 09:53:21 +02003820 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003821
kwibergd1fe2812016-04-27 06:47:29 -07003822 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003823 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003824 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3825}
3826
Henrik Boström87713d02015-08-25 09:53:21 +02003827TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003828 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003829 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003830 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003831
3832 // Create remote offer with SCTP.
3833 cricket::MediaSessionOptions options;
3834 options.data_channel_type = cricket::DCT_SCTP;
3835 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003836 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003837 SetRemoteDescriptionWithoutError(offer);
3838
3839 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003840 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003841 EXPECT_TRUE(answer != NULL);
3842 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3843 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003844}
3845
Henrik Boström87713d02015-08-25 09:53:21 +02003846TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003847 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003848 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003849
3850 SetLocalDescriptionWithDataChannel();
3851 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3852}
3853
Henrik Boström87713d02015-08-25 09:53:21 +02003854TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003855 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003856
Henrik Boström87713d02015-08-25 09:53:21 +02003857 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003858
3859 SetLocalDescriptionWithDataChannel();
3860 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3861}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003862
Henrik Boström87713d02015-08-25 09:53:21 +02003863TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003864 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003865 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003866 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003867
3868 SetLocalDescriptionWithDataChannel();
3869 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3870}
3871
Henrik Boström87713d02015-08-25 09:53:21 +02003872TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003873 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003874 const int new_send_port = 9998;
3875 const int new_recv_port = 7775;
3876
Henrik Boström87713d02015-08-25 09:53:21 +02003877 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003878 SetFactoryDtlsSrtp();
3879
3880 // By default, don't actually add the codecs to desc_factory_; they don't
3881 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3882 // let the session description get parsed. That'll get the proper codecs
3883 // into the stream.
3884 cricket::MediaSessionOptions options;
3885 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3886 "stream1", new_send_port, options);
3887
3888 // SetRemoteDescription will take the ownership of the offer.
3889 SetRemoteDescriptionWithoutError(offer);
3890
htaa2a49d92016-03-04 02:51:39 -08003891 SessionDescriptionInterface* answer =
3892 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003893 ASSERT_TRUE(answer != NULL);
3894
3895 // Now set the local description, which'll take ownership of the answer.
3896 SetLocalDescriptionWithoutError(answer);
3897
3898 // TEST PLAN: Set the port number to something new, set it in the SDP,
3899 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003900 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003901 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003902
3903 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3904 int portnum = -1;
3905 ASSERT_TRUE(ch != NULL);
3906 ASSERT_EQ(1UL, ch->send_codecs().size());
3907 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003908 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003909 ch->send_codecs()[0].name.c_str()));
3910 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3911 &portnum));
3912 EXPECT_EQ(new_send_port, portnum);
3913
3914 ASSERT_EQ(1UL, ch->recv_codecs().size());
3915 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003916 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003917 ch->recv_codecs()[0].name.c_str()));
3918 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3919 &portnum));
3920 EXPECT_EQ(new_recv_port, portnum);
3921}
3922
deadbeefab9b2d12015-10-14 11:33:11 -07003923// Verifies that when a session's DataChannel receives an OPEN message,
3924// WebRtcSession signals the DataChannel creation request with the expected
3925// config.
3926TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3927 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3928
3929 InitWithDtls(GetParam());
3930
3931 SetLocalDescriptionWithDataChannel();
3932 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3933
3934 webrtc::DataChannelInit config;
3935 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07003936 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07003937 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3938 cricket::ReceiveDataParams params;
3939 params.ssrc = config.id;
3940 params.type = cricket::DMT_CONTROL;
3941
3942 cricket::DataChannel* data_channel = session_->data_channel();
3943 data_channel->SignalDataReceived(data_channel, params, payload);
3944
3945 EXPECT_EQ("a", last_data_channel_label_);
3946 EXPECT_EQ(config.id, last_data_channel_config_.id);
3947 EXPECT_FALSE(last_data_channel_config_.negotiated);
3948 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3949 last_data_channel_config_.open_handshake_role);
3950}
3951
3952TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003953 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02003954 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02003955
htaa2a49d92016-03-04 02:51:39 -08003956 configuration_.certificates.push_back(certificate);
3957 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003958 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3959
3960 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3961}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003962
Henrik Boström87713d02015-08-25 09:53:21 +02003963// Verifies that CreateOffer succeeds when CreateOffer is called before async
3964// identity generation is finished (even if a certificate is provided this is
3965// an async op).
3966TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3967 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3968 InitWithDtls(GetParam());
3969
Henrik Boströmd8281982015-08-27 10:12:24 +02003970 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003971 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003972 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003973
wu@webrtc.org91053e72013-08-10 07:18:04 +00003974 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003975 VerifyNoCryptoParams(offer->description(), true);
3976 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003977}
3978
3979// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003980// identity generation is finished (even if a certificate is provided this is
3981// an async op).
3982TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003983 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003984 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003985 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003986
3987 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003988 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003989 std::unique_ptr<JsepSessionDescription> offer(
3990 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003991 ASSERT_TRUE(offer.get() != NULL);
3992 SetRemoteDescriptionWithoutError(offer.release());
3993
kwibergd1fe2812016-04-27 06:47:29 -07003994 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003995 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003996 VerifyNoCryptoParams(answer->description(), true);
3997 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003998}
3999
4000// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004001// identity generation is finished (even if a certificate is provided this is
4002// an async op).
4003TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004004 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004005 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004006
Henrik Boströmd8281982015-08-27 10:12:24 +02004007 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004008
kwibergd1fe2812016-04-27 06:47:29 -07004009 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004010 EXPECT_TRUE(offer != NULL);
4011}
4012
4013// Verifies that CreateOffer fails when CreateOffer is called after async
4014// identity generation fails.
4015TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004016 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004017 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004018
Henrik Boströmd8281982015-08-27 10:12:24 +02004019 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004020
kwibergd1fe2812016-04-27 06:47:29 -07004021 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004022 EXPECT_TRUE(offer == NULL);
4023}
4024
4025// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4026// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004027TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004028 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004029 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004030 VerifyMultipleAsyncCreateDescription(GetParam(),
4031 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004032}
4033
4034// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4035// before async identity generation fails.
4036TEST_F(WebRtcSessionTest,
4037 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004038 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004039 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4040 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004041}
4042
4043// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4044// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004045TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004046 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004047 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004049 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004050}
4051
4052// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4053// before async identity generation fails.
4054TEST_F(WebRtcSessionTest,
4055 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004056 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004057 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4058 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004060
4061// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4062// offer has no SDES crypto but only DTLS fingerprint.
4063TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4064 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004065 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004066 // Create a remote offer with secured transport disabled.
4067 cricket::MediaSessionOptions options;
4068 JsepSessionDescription* offer(CreateRemoteOffer(
4069 options, cricket::SEC_DISABLED));
4070 // Adds a DTLS fingerprint to the remote offer.
4071 cricket::SessionDescription* sdp = offer->description();
4072 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4073 ASSERT_TRUE(audio != NULL);
4074 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4075 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004076 rtc::SSLFingerprint::CreateFromRfc4572(
4077 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004078 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004079 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004080}
4081
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004082TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004083 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004084 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004085 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004086 SessionDescriptionInterface* offer = CreateOffer();
4087
4088 SetLocalDescriptionWithoutError(offer);
4089
4090 voice_channel_ = media_engine_->GetVoiceChannel(0);
4091
4092 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004093 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004094 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004095}
4096
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004097// Tests that we can renegotiate new media content with ICE candidates in the
4098// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004099TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004100 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004101 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004102 SetFactoryDtlsSrtp();
4103
deadbeefab9b2d12015-10-14 11:33:11 -07004104 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004105 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004106 SetLocalDescriptionWithoutError(offer);
4107
4108 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4109 SetRemoteDescriptionWithoutError(answer);
4110
4111 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004112 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004113 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4114
4115 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004116 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004117 candidate1.set_component(1);
4118 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4119 candidate1);
4120 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4121 SetRemoteDescriptionWithoutError(offer);
4122
htaa2a49d92016-03-04 02:51:39 -08004123 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004124 SetLocalDescriptionWithoutError(answer);
4125}
4126
4127// Tests that we can renegotiate new media content with ICE candidates separated
4128// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004129TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004130 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004131 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004132 SetFactoryDtlsSrtp();
4133
deadbeefab9b2d12015-10-14 11:33:11 -07004134 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004135 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004136 SetLocalDescriptionWithoutError(offer);
4137
4138 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4139 SetRemoteDescriptionWithoutError(answer);
4140
4141 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004142 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004143 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4144 SetRemoteDescriptionWithoutError(offer);
4145
4146 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004147 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004148 candidate1.set_component(1);
4149 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4150 candidate1);
4151 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4152
htaa2a49d92016-03-04 02:51:39 -08004153 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004154 SetLocalDescriptionWithoutError(answer);
4155}
honghaiz7f777492016-02-02 21:54:01 -08004156
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004157// Tests that RTX codec is removed from the answer when it isn't supported
4158// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004159TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004160 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004161 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004162 std::string offer_sdp(kSdpWithRtx);
4163
4164 SessionDescriptionInterface* offer =
4165 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4166 EXPECT_TRUE(offer->ToString(&offer_sdp));
4167
4168 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004169 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004170 SetRemoteDescriptionWithoutError(offer);
4171
htaa2a49d92016-03-04 02:51:39 -08004172 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004173 // Answer SDP does not contain the RTX codec.
4174 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004175 SetLocalDescriptionWithoutError(answer);
4176}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004177
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004178// This verifies that the voice channel after bundle has both options from video
4179// and voice channels.
4180TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4181 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004182 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004183
4184 PeerConnectionInterface::RTCOfferAnswerOptions options;
4185 options.use_rtp_mux = true;
4186
4187 SessionDescriptionInterface* offer = CreateOffer(options);
4188 SetLocalDescriptionWithoutError(offer);
4189
4190 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4191 rtc::Socket::Option::OPT_SNDBUF, 4000);
4192
4193 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4194 rtc::Socket::Option::OPT_RCVBUF, 8000);
4195
4196 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004197 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004198 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4199 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004200 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004201 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4202
deadbeefcbecd352015-09-23 11:50:27 -07004203 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004204 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4205 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004206 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004207 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4208
deadbeefcbecd352015-09-23 11:50:27 -07004209 EXPECT_NE(session_->voice_rtp_transport_channel(),
4210 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004211
deadbeefab9b2d12015-10-14 11:33:11 -07004212 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004213 SessionDescriptionInterface* answer =
4214 CreateRemoteAnswer(session_->local_description());
4215 SetRemoteDescriptionWithoutError(answer);
4216
deadbeefcbecd352015-09-23 11:50:27 -07004217 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004218 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4219 EXPECT_EQ(4000, option_val);
4220
deadbeefcbecd352015-09-23 11:50:27 -07004221 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004222 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4223 EXPECT_EQ(8000, option_val);
4224}
4225
tommi0f620f42015-07-09 03:25:02 -07004226// Test creating a session, request multiple offers, destroy the session
4227// and make sure we got success/failure callbacks for all of the requests.
4228// Background: crbug.com/507307
4229TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4230 Init();
4231
4232 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4233 PeerConnectionInterface::RTCOfferAnswerOptions options;
4234 options.offer_to_receive_audio =
4235 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004236 cricket::MediaSessionOptions session_options;
4237 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004238
4239 for (auto& o : observers) {
4240 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004241 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004242 }
4243
4244 session_.reset();
4245
tommi0f620f42015-07-09 03:25:02 -07004246 for (auto& o : observers) {
4247 // We expect to have received a notification now even if the session was
4248 // terminated. The offer creation may or may not have succeeded, but we
4249 // must have received a notification which, so the only invalid state
4250 // is kInit.
4251 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4252 }
4253}
4254
stefanc1aeaf02015-10-15 07:26:07 -07004255TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4256 TestPacketOptions();
4257}
4258
deadbeef057ecf02016-01-20 14:30:43 -08004259// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4260// is destroyed.
4261TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4262 Init();
4263 session_.reset();
4264 EXPECT_TRUE(session_destroyed_);
4265}
4266
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004267// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4268// currently fails because upon disconnection and reconnection OnIceComplete is
4269// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004270
deadbeefcbecd352015-09-23 11:50:27 -07004271INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4272 WebRtcSessionTest,
4273 testing::Values(ALREADY_GENERATED,
4274 DTLS_IDENTITY_STORE));