blob: 088694cb16b6a07c5be0276be63e9423cf45e02c [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;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200161 virtual ~MockIceObserver() = default;
162
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceConnectionChange(
164 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700166 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
perkjdfb769d2016-02-09 03:09:43 -0800168 void OnIceGatheringChange(
169 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 // We can never transition back to "new".
171 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
172 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800173 oncandidatesready_ =
174 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 }
176
177 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800178 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000179 switch (candidate->sdp_mline_index()) {
180 case kMediaContentIndex0:
181 mline_0_candidates_.push_back(candidate->candidate());
182 break;
183 case kMediaContentIndex1:
184 mline_1_candidates_.push_back(candidate->candidate());
185 break;
186 default:
187 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000189
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // The ICE gathering state should always be Gathering when a candidate is
191 // received (or possibly Completed in the case of the final candidate).
192 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
193 }
194
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700195 // Some local candidates are removed.
196 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700197 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700198 num_candidates_removed_ += candidates.size();
199 }
200
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 bool oncandidatesready_;
202 std::vector<cricket::Candidate> mline_0_candidates_;
203 std::vector<cricket::Candidate> mline_1_candidates_;
204 PeerConnectionInterface::IceConnectionState ice_connection_state_;
205 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700206 std::vector<PeerConnectionInterface::IceConnectionState>
207 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700208 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209};
210
211class WebRtcSessionForTest : public webrtc::WebRtcSession {
212 public:
stefanc1aeaf02015-10-15 07:26:07 -0700213 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
danilchape9021a32016-05-17 01:52:02 -0700214 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000215 rtc::Thread* worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700216 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700218 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700219 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700220 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700221 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700222 signaling_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700223 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 RegisterIceObserver(ice_observer);
225 }
226 virtual ~WebRtcSessionForTest() {}
227
deadbeefcbecd352015-09-23 11:50:27 -0700228 // Note that these methods are only safe to use if the signaling thread
229 // is the same as the worker thread
230 cricket::TransportChannel* voice_rtp_transport_channel() {
231 return rtp_transport_channel(voice_channel());
232 }
233
234 cricket::TransportChannel* voice_rtcp_transport_channel() {
235 return rtcp_transport_channel(voice_channel());
236 }
237
238 cricket::TransportChannel* video_rtp_transport_channel() {
239 return rtp_transport_channel(video_channel());
240 }
241
242 cricket::TransportChannel* video_rtcp_transport_channel() {
243 return rtcp_transport_channel(video_channel());
244 }
245
246 cricket::TransportChannel* data_rtp_transport_channel() {
247 return rtp_transport_channel(data_channel());
248 }
249
250 cricket::TransportChannel* data_rtcp_transport_channel() {
251 return rtcp_transport_channel(data_channel());
252 }
253
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 using webrtc::WebRtcSession::SetAudioPlayout;
255 using webrtc::WebRtcSession::SetAudioSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 using webrtc::WebRtcSession::SetVideoPlayout;
257 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700258
259 private:
260 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
261 if (!ch) {
262 return nullptr;
263 }
264 return ch->transport_channel();
265 }
266
267 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
268 if (!ch) {
269 return nullptr;
270 }
271 return ch->rtcp_transport_channel();
272 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273};
274
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000276 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278 enum State {
279 kInit,
280 kFailed,
281 kSucceeded,
282 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000283 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284
285 // CreateSessionDescriptionObserver implementation.
286 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000287 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000288 state_ = kSucceeded;
289 }
290 virtual void OnFailure(const std::string& error) {
291 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
293
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000294 SessionDescriptionInterface* description() { return description_.get(); }
295
296 SessionDescriptionInterface* ReleaseDescription() {
297 return description_.release();
298 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299
wu@webrtc.org91053e72013-08-10 07:18:04 +0000300 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
wu@webrtc.org91053e72013-08-10 07:18:04 +0000302 protected:
303 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
305 private:
kwibergd1fe2812016-04-27 06:47:29 -0700306 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308};
309
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800310class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800312 FakeAudioSource() : sink_(NULL) {}
313 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000314 if (sink_)
315 sink_->OnClose();
316 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000318 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800320 const cricket::AudioSource::Sink* sink() const { return sink_; }
321
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800323 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324};
325
Henrik Boström87713d02015-08-25 09:53:21 +0200326class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700327 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
328 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 protected:
330 // TODO Investigate why ChannelManager crashes, if it's created
331 // after stun_server.
332 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700333 : media_engine_(new cricket::FakeMediaEngine()),
334 data_engine_(new cricket::FakeDataEngine()),
335 channel_manager_(
336 new cricket::ChannelManager(media_engine_,
337 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700338 rtc::Thread::Current())),
339 fake_call_(webrtc::Call::Config()),
340 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800341 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
342 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700343 channel_manager_.get())),
344 tdesc_factory_(new cricket::TransportDescriptionFactory()),
345 desc_factory_(
346 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
347 tdesc_factory_.get())),
348 pss_(new rtc::PhysicalSocketServer),
349 vss_(new rtc::VirtualSocketServer(pss_.get())),
350 fss_(new rtc::FirewallSocketServer(vss_.get())),
351 ss_scope_(fss_.get()),
352 stun_socket_addr_(
353 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
354 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
355 stun_socket_addr_)),
356 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
357 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000358 cricket::ServerAddresses stun_servers;
359 stun_servers.insert(stun_socket_addr_);
360 allocator_.reset(new cricket::BasicPortAllocator(
361 &network_manager_,
362 stun_servers,
363 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700365 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 EXPECT_TRUE(channel_manager_->Init());
367 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000368 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370
371 void AddInterface(const SocketAddress& addr) {
372 network_manager_.AddInterface(addr);
373 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700374 void RemoveInterface(const SocketAddress& addr) {
375 network_manager_.RemoveInterface(addr);
376 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377
Henrik Boströmd79599d2016-06-01 13:58:50 +0200378 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
379 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
380 // options. When DTLS is enabled a certificate will be used if provided,
381 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000382 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200383 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 ASSERT_TRUE(session_.get() == NULL);
385 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700386 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
danilchape9021a32016-05-17 01:52:02 -0700387 rtc::Thread::Current(), allocator_.get(), &observer_));
deadbeefab9b2d12015-10-14 11:33:11 -0700388 session_->SignalDataChannelOpenMessage.connect(
389 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800390 session_->GetOnDestroyedSignal()->connect(
391 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392
393 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
394 observer_.ice_connection_state_);
395 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
396 observer_.ice_gathering_state_);
397
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200398 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800399 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700400 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 }
402
deadbeefab9b2d12015-10-14 11:33:11 -0700403 void OnDataChannelOpenMessage(const std::string& label,
404 const InternalDataChannelInit& config) {
405 last_data_channel_label_ = label;
406 last_data_channel_config_ = config;
407 }
408
deadbeef057ecf02016-01-20 14:30:43 -0800409 void OnSessionDestroyed() { session_destroyed_ = true; }
410
htaa2a49d92016-03-04 02:51:39 -0800411 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 void InitWithBundlePolicy(
414 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800415 configuration_.bundle_policy = bundle_policy;
416 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700417 }
418
419 void InitWithRtcpMuxPolicy(
420 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
421 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800422 configuration_.rtcp_mux_policy = rtcp_mux_policy;
423 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000424 }
425
Henrik Boström87713d02015-08-25 09:53:21 +0200426 // Successfully init with DTLS; with a certificate generated and supplied or
427 // with a store that generates it for us.
428 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200429 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200430 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800431 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200432 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200433 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200434 cert_generator.reset(new FakeRTCCertificateGenerator());
435 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200436 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700437 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200438 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200439 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200440 }
441
442 // Init with DTLS with a store that will fail to generate a certificate.
443 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200444 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
445 new FakeRTCCertificateGenerator());
446 cert_generator->set_should_fail(true);
447 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000448 }
449
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 void InitWithDtmfCodec() {
451 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700452 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
453 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 std::vector<cricket::AudioCodec> codecs;
455 codecs.push_back(kTelephoneEventCodec);
456 media_engine_->SetAudioCodecs(codecs);
457 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000458 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 }
460
deadbeefab9b2d12015-10-14 11:33:11 -0700461 void SendAudioVideoStream1() {
462 send_stream_1_ = true;
463 send_stream_2_ = false;
464 send_audio_ = true;
465 send_video_ = true;
466 }
467
468 void SendAudioVideoStream2() {
469 send_stream_1_ = false;
470 send_stream_2_ = true;
471 send_audio_ = true;
472 send_video_ = true;
473 }
474
475 void SendAudioVideoStream1And2() {
476 send_stream_1_ = true;
477 send_stream_2_ = true;
478 send_audio_ = true;
479 send_video_ = true;
480 }
481
482 void SendNothing() {
483 send_stream_1_ = false;
484 send_stream_2_ = false;
485 send_audio_ = false;
486 send_video_ = false;
487 }
488
489 void SendAudioOnlyStream2() {
490 send_stream_1_ = false;
491 send_stream_2_ = true;
492 send_audio_ = true;
493 send_video_ = false;
494 }
495
496 void SendVideoOnlyStream2() {
497 send_stream_1_ = false;
498 send_stream_2_ = true;
499 send_audio_ = false;
500 send_video_ = true;
501 }
502
503 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
504 if (send_stream_1_ && send_audio_) {
505 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
506 kStream1);
507 }
508 if (send_stream_1_ && send_video_) {
509 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
510 kStream1);
511 }
512 if (send_stream_2_ && send_audio_) {
513 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
514 kStream2);
515 }
516 if (send_stream_2_ && send_video_) {
517 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
518 kStream2);
519 }
520 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
521 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
522 data_channel_->label(),
523 data_channel_->label());
524 }
525 }
526
527 void GetOptionsForOffer(
528 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
529 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800530 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700531
deadbeefc80741f2015-10-22 13:14:45 -0700532 AddStreamsToOptions(session_options);
533 if (rtc_options.offer_to_receive_audio ==
534 RTCOfferAnswerOptions::kUndefined) {
535 session_options->recv_audio =
536 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
537 }
538 if (rtc_options.offer_to_receive_video ==
539 RTCOfferAnswerOptions::kUndefined) {
540 session_options->recv_video =
541 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
542 }
543 session_options->bundle_enabled =
544 session_options->bundle_enabled &&
545 (session_options->has_audio() || session_options->has_video() ||
546 session_options->has_data());
547
deadbeefab9b2d12015-10-14 11:33:11 -0700548 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
549 session_options->data_channel_type = cricket::DCT_SCTP;
550 }
551 }
552
htaa2a49d92016-03-04 02:51:39 -0800553 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
554 // ParseConstraintsForAnswer is used to set some defaults.
555 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700556
deadbeefc80741f2015-10-22 13:14:45 -0700557 AddStreamsToOptions(session_options);
558 session_options->bundle_enabled =
559 session_options->bundle_enabled &&
560 (session_options->has_audio() || session_options->has_video() ||
561 session_options->has_data());
562
deadbeefab9b2d12015-10-14 11:33:11 -0700563 if (session_->data_channel_type() == cricket::DCT_SCTP) {
564 session_options->data_channel_type = cricket::DCT_SCTP;
565 }
566 }
567
568 // Creates a local offer and applies it. Starts ICE.
569 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // to decide which streams to create.
571 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000572 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 SetLocalDescriptionWithoutError(offer);
574 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
575 observer_.ice_gathering_state_,
576 kIceCandidatesTimeout);
577 }
578
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000579 SessionDescriptionInterface* CreateOffer() {
580 PeerConnectionInterface::RTCOfferAnswerOptions options;
581 options.offer_to_receive_audio =
582 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
583
584 return CreateOffer(options);
585 }
586
wu@webrtc.org91053e72013-08-10 07:18:04 +0000587 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800588 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000589 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000590 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700591 cricket::MediaSessionOptions session_options;
592 GetOptionsForOffer(options, &session_options);
593 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000594 EXPECT_TRUE_WAIT(
595 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000596 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000597 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000598 }
599
600 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800601 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000602 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000603 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800604 cricket::MediaSessionOptions session_options = options;
605 GetOptionsForAnswer(&session_options);
606 // Overwrite recv_audio and recv_video with passed-in values.
607 session_options.recv_video = options.recv_video;
608 session_options.recv_audio = options.recv_audio;
609 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000610 EXPECT_TRUE_WAIT(
611 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000612 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000613 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000614 }
615
htaa2a49d92016-03-04 02:51:39 -0800616 SessionDescriptionInterface* CreateAnswer() {
617 cricket::MediaSessionOptions options;
618 options.recv_video = true;
619 options.recv_audio = true;
620 return CreateAnswer(options);
621 }
622
wu@webrtc.org364f2042013-11-20 21:49:41 +0000623 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 return (session_->voice_channel() != NULL &&
625 session_->video_channel() != NULL);
626 }
627
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
629 ASSERT_TRUE(session_.get() != NULL);
630 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
631 ASSERT_TRUE(content != NULL);
632 const cricket::AudioContentDescription* audio_content =
633 static_cast<const cricket::AudioContentDescription*>(
634 content->description);
635 ASSERT_TRUE(audio_content != NULL);
636 ASSERT_EQ(1U, audio_content->cryptos().size());
637 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
638 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
639 audio_content->cryptos()[0].cipher_suite);
640 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
641 audio_content->protocol());
642
643 content = cricket::GetFirstVideoContent(sdp);
644 ASSERT_TRUE(content != NULL);
645 const cricket::VideoContentDescription* video_content =
646 static_cast<const cricket::VideoContentDescription*>(
647 content->description);
648 ASSERT_TRUE(video_content != NULL);
649 ASSERT_EQ(1U, video_content->cryptos().size());
650 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
651 video_content->cryptos()[0].cipher_suite);
652 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
653 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
654 video_content->protocol());
655 }
656
657 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
658 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
659 ASSERT_TRUE(content != NULL);
660 const cricket::AudioContentDescription* audio_content =
661 static_cast<const cricket::AudioContentDescription*>(
662 content->description);
663 ASSERT_TRUE(audio_content != NULL);
664 ASSERT_EQ(0U, audio_content->cryptos().size());
665
666 content = cricket::GetFirstVideoContent(sdp);
667 ASSERT_TRUE(content != NULL);
668 const cricket::VideoContentDescription* video_content =
669 static_cast<const cricket::VideoContentDescription*>(
670 content->description);
671 ASSERT_TRUE(video_content != NULL);
672 ASSERT_EQ(0U, video_content->cryptos().size());
673
674 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700675 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700677 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 video_content->protocol());
679 } else {
680 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
681 audio_content->protocol());
682 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
683 video_content->protocol());
684 }
685 }
686
687 // Set the internal fake description factories to do DTLS-SRTP.
688 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000689 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000691 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200692 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800693 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700694 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800695 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
697 }
698
699 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
700 bool expected) {
701 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
702 ASSERT_TRUE(audio != NULL);
703 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 const TransportInfo* video = sdp->GetTransportInfoByName("video");
705 ASSERT_TRUE(video != NULL);
706 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 }
708
709 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000710 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000712 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000713 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000715 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000717 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
718 offer);
htaa2a49d92016-03-04 02:51:39 -0800719 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 // Answer should be NULL as no crypto params in offer.
721 ASSERT_TRUE(answer == NULL);
722 }
723
724 void VerifyAnswerFromCryptoOffer() {
725 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000726 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700728 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
730 ASSERT_TRUE(offer.get() != NULL);
731 VerifyCryptoParams(offer->description());
732 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700733 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 ASSERT_TRUE(answer.get() != NULL);
735 VerifyCryptoParams(answer->description());
736 }
737
deadbeef0ed85b22016-02-23 17:24:52 -0800738 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
739 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800741 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 }
743
744 const cricket::ContentInfos& contents = desc1->contents();
745 cricket::ContentInfos::const_iterator it = contents.begin();
746
747 for (; it != contents.end(); ++it) {
748 const cricket::TransportDescription* transport_desc1 =
749 desc1->GetTransportDescriptionByName(it->name);
750 const cricket::TransportDescription* transport_desc2 =
751 desc2->GetTransportDescriptionByName(it->name);
752 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800753 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 }
755 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
756 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800757 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 }
759 }
deadbeef0ed85b22016-02-23 17:24:52 -0800760 return true;
761 }
762
763 // Compares ufrag/password only for the specified |media_type|.
764 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
765 const cricket::SessionDescription* desc2,
766 cricket::MediaType media_type) {
767 if (desc1->contents().size() != desc2->contents().size()) {
768 return false;
769 }
770
771 const cricket::ContentInfo* cinfo =
772 cricket::GetFirstMediaContent(desc1->contents(), media_type);
773 const cricket::TransportDescription* transport_desc1 =
774 desc1->GetTransportDescriptionByName(cinfo->name);
775 const cricket::TransportDescription* transport_desc2 =
776 desc2->GetTransportDescriptionByName(cinfo->name);
777 if (!transport_desc1 || !transport_desc2) {
778 return false;
779 }
780 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
781 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
782 return false;
783 }
784 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000786
787 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
788 std::string *sdp) {
789 const cricket::SessionDescription* desc = current_desc->description();
790 EXPECT_TRUE(current_desc->ToString(sdp));
791
792 const cricket::ContentInfos& contents = desc->contents();
793 cricket::ContentInfos::const_iterator it = contents.begin();
794 // Replace ufrag and pwd lines with empty strings.
795 for (; it != contents.end(); ++it) {
796 const cricket::TransportDescription* transport_desc =
797 desc->GetTransportDescriptionByName(it->name);
798 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
799 + "\r\n";
800 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
801 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000802 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000803 "", 0,
804 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000805 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000806 "", 0,
807 sdp);
808 }
809 }
810
deadbeef0ed85b22016-02-23 17:24:52 -0800811 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
812 const std::string& ufrag,
813 const std::string& pwd) {
814 cricket::SessionDescription* desc = current_desc->description();
815 for (TransportInfo& transport_info : desc->transport_infos()) {
816 cricket::TransportDescription& transport_desc =
817 transport_info.description;
818 transport_desc.ice_ufrag = ufrag;
819 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000820 }
821 }
822
deadbeef0ed85b22016-02-23 17:24:52 -0800823 // Sets ufrag/pwd for specified |media_type|.
824 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
825 cricket::MediaType media_type,
826 const std::string& ufrag,
827 const std::string& pwd) {
828 cricket::SessionDescription* desc = current_desc->description();
829 const cricket::ContentInfo* cinfo =
830 cricket::GetFirstMediaContent(desc->contents(), media_type);
831 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
832 cricket::TransportDescription* transport_desc =
833 &transport_info->description;
834 transport_desc->ice_ufrag = ufrag;
835 transport_desc->ice_pwd = pwd;
836 }
837
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 // Creates a remote offer and and applies it as a remote description,
839 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700840 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 // to decide which local and remote streams to create.
842 void CreateAndSetRemoteOfferAndLocalAnswer() {
843 SessionDescriptionInterface* offer = CreateRemoteOffer();
844 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800845 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 SetLocalDescriptionWithoutError(answer);
847 }
848 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
849 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700850 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 }
852 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700853 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 SetLocalDescriptionWithoutError(desc);
855 EXPECT_EQ(expected_state, session_->state());
856 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 void SetLocalDescriptionExpectError(const std::string& action,
858 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 SessionDescriptionInterface* desc) {
860 std::string error;
861 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000862 std::string sdp_type = "local ";
863 sdp_type.append(action);
864 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 EXPECT_NE(std::string::npos, error.find(expected_error));
866 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000867 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
868 SessionDescriptionInterface* desc) {
869 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
870 expected_error, desc);
871 }
872 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
873 SessionDescriptionInterface* desc) {
874 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
875 expected_error, desc);
876 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
878 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
879 }
880 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700881 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 SetRemoteDescriptionWithoutError(desc);
883 EXPECT_EQ(expected_state, session_->state());
884 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 void SetRemoteDescriptionExpectError(const std::string& action,
886 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 SessionDescriptionInterface* desc) {
888 std::string error;
889 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 std::string sdp_type = "remote ";
891 sdp_type.append(action);
892 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 EXPECT_NE(std::string::npos, error.find(expected_error));
894 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000895 void SetRemoteDescriptionOfferExpectError(
896 const std::string& expected_error, SessionDescriptionInterface* desc) {
897 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
898 expected_error, desc);
899 }
900 void SetRemoteDescriptionPranswerExpectError(
901 const std::string& expected_error, SessionDescriptionInterface* desc) {
902 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
903 expected_error, desc);
904 }
905 void SetRemoteDescriptionAnswerExpectError(
906 const std::string& expected_error, SessionDescriptionInterface* desc) {
907 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
908 expected_error, desc);
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910
911 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
912 SessionDescriptionInterface** nocrypto_answer) {
913 // Create a SDP without Crypto.
914 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000915 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 options.bundle_enabled = true;
917 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
918 ASSERT_TRUE(*offer != NULL);
919 VerifyCryptoParams((*offer)->description());
920
921 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
922 cricket::SEC_DISABLED);
923 EXPECT_TRUE(*nocrypto_answer != NULL);
924 }
925
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000926 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
927 SessionDescriptionInterface** nodtls_answer) {
928 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000929 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000930 options.bundle_enabled = true;
931
kwibergd1fe2812016-04-27 06:47:29 -0700932 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000933 CreateRemoteOffer(options, cricket::SEC_ENABLED));
934
935 *nodtls_answer =
936 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
937 EXPECT_TRUE(*nodtls_answer != NULL);
938 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
939 VerifyCryptoParams((*nodtls_answer)->description());
940
941 SetFactoryDtlsSrtp();
942 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
943 ASSERT_TRUE(*offer != NULL);
944 VerifyFingerprintStatus((*offer)->description(), true);
945 VerifyCryptoParams((*offer)->description());
946 }
947
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 JsepSessionDescription* CreateRemoteOfferWithVersion(
949 cricket::MediaSessionOptions options,
950 cricket::SecurePolicy secure_policy,
951 const std::string& session_version,
952 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000953 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 const cricket::SessionDescription* cricket_desc = NULL;
955 if (current_desc) {
956 cricket_desc = current_desc->description();
957 session_id = current_desc->session_id();
958 }
959
960 desc_factory_->set_secure(secure_policy);
961 JsepSessionDescription* offer(
962 new JsepSessionDescription(JsepSessionDescription::kOffer));
963 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
964 session_id, session_version)) {
965 delete offer;
966 offer = NULL;
967 }
968 return offer;
969 }
970 JsepSessionDescription* CreateRemoteOffer(
971 cricket::MediaSessionOptions options) {
972 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
973 kSessionVersion, NULL);
974 }
975 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000976 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
977 return CreateRemoteOfferWithVersion(
978 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 }
980 JsepSessionDescription* CreateRemoteOffer(
981 cricket::MediaSessionOptions options,
982 const SessionDescriptionInterface* current_desc) {
983 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
984 kSessionVersion, current_desc);
985 }
986
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000987 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
988 const char* sctp_stream_name, int new_port,
989 cricket::MediaSessionOptions options) {
990 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000991 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
992 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000993 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
994 }
995
996 // Takes ownership of offer_basis (and deletes it).
997 JsepSessionDescription* ChangeSDPSctpPort(
998 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
999 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1000 // SessionDescription from the mutated string.
1001 const char* default_port_str = "5000";
1002 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001003 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001004 std::string offer_str;
1005 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001006 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001007 new_port_str, strlen(new_port_str),
1008 &offer_str);
1009 JsepSessionDescription* offer = new JsepSessionDescription(
1010 offer_basis->type());
1011 delete offer_basis;
1012 offer->Initialize(offer_str, NULL);
1013 return offer;
1014 }
1015
deadbeefab9b2d12015-10-14 11:33:11 -07001016 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 // before this function to decide which streams to create.
1018 JsepSessionDescription* CreateRemoteOffer() {
1019 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001020 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 return CreateRemoteOffer(options, session_->remote_description());
1022 }
1023
1024 JsepSessionDescription* CreateRemoteAnswer(
1025 const SessionDescriptionInterface* offer,
1026 cricket::MediaSessionOptions options,
1027 cricket::SecurePolicy policy) {
1028 desc_factory_->set_secure(policy);
1029 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001030 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 JsepSessionDescription* answer(
1032 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1033 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1034 options, NULL),
1035 session_id, kSessionVersion)) {
1036 delete answer;
1037 answer = NULL;
1038 }
1039 return answer;
1040 }
1041
1042 JsepSessionDescription* CreateRemoteAnswer(
1043 const SessionDescriptionInterface* offer,
1044 cricket::MediaSessionOptions options) {
1045 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1046 }
1047
deadbeefab9b2d12015-10-14 11:33:11 -07001048 // Creates an answer session description.
1049 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 // to decide which streams to create.
1051 JsepSessionDescription* CreateRemoteAnswer(
1052 const SessionDescriptionInterface* offer) {
1053 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001054 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1056 }
1057
1058 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001059 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001060 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001061 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001062
1063 PeerConnectionInterface::RTCOfferAnswerOptions options;
1064 options.use_rtp_mux = bundle;
1065
1066 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1068 // and answer.
1069 SetLocalDescriptionWithoutError(offer);
1070
kwibergd1fe2812016-04-27 06:47:29 -07001071 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001072 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 std::string sdp;
1074 EXPECT_TRUE(answer->ToString(&sdp));
1075
1076 size_t expected_candidate_num = 2;
1077 if (!rtcp_mux) {
1078 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1079 // for rtp and rtcp.
1080 expected_candidate_num = 4;
1081 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 const std::string kRtcpMux = "a=rtcp-mux";
1083 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001084 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 kXRtcpMux.c_str(), kXRtcpMux.length(),
1086 &sdp);
1087 }
1088
1089 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1090 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091
1092 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001093 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1095 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001096 if (bundle) {
1097 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1098 } else {
1099 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 }
1101 }
1102 // Tests that we can only send DTMF when the dtmf codec is supported.
1103 void TestCanInsertDtmf(bool can) {
1104 if (can) {
1105 InitWithDtmfCodec();
1106 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001107 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 }
deadbeefab9b2d12015-10-14 11:33:11 -07001109 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 CreateAndSetRemoteOfferAndLocalAnswer();
1111 EXPECT_FALSE(session_->CanInsertDtmf(""));
1112 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1113 }
1114
zhihuang3a334652016-05-05 18:37:49 -07001115 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1116 const std::string& codec_name) {
1117 for (const auto& content : desc->description()->contents()) {
1118 if (static_cast<cricket::MediaContentDescription*>(content.description)
1119 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1120 const auto* mdesc =
1121 static_cast<cricket::VideoContentDescription*>(content.description);
1122 for (const auto& codec : mdesc->codecs()) {
1123 if (codec.name == codec_name) {
1124 return true;
1125 }
1126 }
1127 }
1128 }
1129 return false;
1130 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001131 // Helper class to configure loopback network and verify Best
1132 // Connection using right IP protocol for TestLoopbackCall
1133 // method. LoopbackNetworkManager applies firewall rules to block
1134 // all ping traffic once ICE completed, and remove them to observe
1135 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1136 // verifies the best connection is using the right IP protocol after
1137 // initial ICE convergences.
1138
1139 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001140 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001141 LoopbackNetworkConfiguration()
1142 : test_ipv6_network_(false),
1143 test_extra_ipv4_network_(false),
1144 best_connection_after_initial_ice_converged_(1, 0) {}
1145
1146 // Used to track the expected best connection count in each IP protocol.
1147 struct ExpectedBestConnection {
1148 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1149 : ipv4_count_(ipv4_count),
1150 ipv6_count_(ipv6_count) {}
1151
1152 int ipv4_count_;
1153 int ipv6_count_;
1154 };
1155
1156 bool test_ipv6_network_;
1157 bool test_extra_ipv4_network_;
1158 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1159
1160 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001161 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001162 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1163 }
1164
1165 private:
jbauchac8869e2015-07-03 01:36:14 -07001166 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167 const ExpectedBestConnection& expected) const {
1168 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001169 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1170 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171 expected.ipv4_count_);
1172 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001173 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1174 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001175 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001176 // This is used in the loopback call so there is only single host to host
1177 // candidate pair.
1178 EXPECT_EQ(metrics_observer->GetEnumCounter(
1179 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1180 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001181 0);
1182 EXPECT_EQ(metrics_observer->GetEnumCounter(
1183 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1184 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001185 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001186 }
1187 };
1188
1189 class LoopbackNetworkManager {
1190 public:
1191 LoopbackNetworkManager(WebRtcSessionTest* session,
1192 const LoopbackNetworkConfiguration& config)
1193 : config_(config) {
1194 session->AddInterface(
1195 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1196 if (config_.test_extra_ipv4_network_) {
1197 session->AddInterface(
1198 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1199 }
1200 if (config_.test_ipv6_network_) {
1201 session->AddInterface(
1202 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1203 }
1204 }
1205
1206 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1207 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1208 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1209 if (config_.test_extra_ipv4_network_) {
1210 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1211 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1212 }
1213 if (config_.test_ipv6_network_) {
1214 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1215 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1216 }
1217 }
1218
1219 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1220
1221 private:
1222 LoopbackNetworkConfiguration config_;
1223 };
1224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 // The method sets up a call from the session to itself, in a loopback
1226 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001227 // disconnection, and then a permanent disconnection.
1228 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1230 // While running the call, this method also checks if the session goes through
1231 // the correct sequence of ICE states when a connection is established,
1232 // broken, and re-established.
1233 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001234 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1235 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001237
stefanc1aeaf02015-10-15 07:26:07 -07001238 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001239 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001240 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001241 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242
1243 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1244 observer_.ice_gathering_state_);
1245 SetLocalDescriptionWithoutError(offer);
1246 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1247 observer_.ice_connection_state_);
1248 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001249 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001252 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253
1254 std::string sdp;
1255 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001256 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1257 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 ASSERT_TRUE(desc != NULL);
1259 SetRemoteDescriptionWithoutError(desc);
1260
1261 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001262 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001263
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001264 // The ice connection state is "Connected" too briefly to catch in a test.
1265 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001266 observer_.ice_connection_state_, kIceCandidatesTimeout);
1267 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268
stefanc1aeaf02015-10-15 07:26:07 -07001269 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1270 LoopbackNetworkManager loopback_network_manager(this, config);
1271 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001272 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 // Adding firewall rule to block ping requests, which should cause
1274 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275
1276 loopback_network_manager.ApplyFirewallRules(fss_.get());
1277
1278 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1280 observer_.ice_connection_state_,
1281 kIceCandidatesTimeout);
1282
jbauchac8869e2015-07-03 01:36:14 -07001283 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001284
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001286 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001288 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001289 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 observer_.ice_connection_state_,
1291 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001292
1293 // Now we block ping requests and wait until the ICE connection transitions
1294 // to the Failed state. This will take at least 30 seconds because it must
1295 // wait for the Port to timeout.
1296 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001297
1298 loopback_network_manager.ApplyFirewallRules(fss_.get());
1299 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001300 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001301 observer_.ice_connection_state_,
1302 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 }
1304
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001305 void TestLoopbackCall() {
1306 LoopbackNetworkConfiguration config;
1307 TestLoopbackCall(config);
1308 }
1309
stefanc1aeaf02015-10-15 07:26:07 -07001310 void TestPacketOptions() {
1311 media_controller_.reset(
1312 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1313 LoopbackNetworkConfiguration config;
1314 LoopbackNetworkManager loopback_network_manager(this, config);
1315
1316 SetupLoopbackCall();
1317
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001318 // Wait for channel to be ready for sending.
1319 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001320 uint8_t test_packet[15] = {0};
1321 rtc::PacketOptions options;
1322 options.packet_id = 10;
1323 media_engine_->GetVideoChannel(0)
1324 ->SendRtp(test_packet, sizeof(test_packet), options);
1325
1326 const int kPacketTimeout = 2000;
1327 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1328 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1329 }
1330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1332 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001333 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1334 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001335
1336 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1338 codecs.push_back(kCNCodec1);
1339 codecs.push_back(kCNCodec2);
1340 media_engine_->SetAudioCodecs(codecs);
1341 desc_factory_->set_audio_codecs(codecs);
1342 }
1343
1344 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1345 const cricket::ContentDescription* description = content->description;
1346 ASSERT(description != NULL);
1347 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001348 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 ASSERT(audio_content_desc != NULL);
1350 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1351 if (audio_content_desc->codecs()[i].name == "CN")
1352 return false;
1353 }
1354 return true;
1355 }
1356
deadbeefab9b2d12015-10-14 11:33:11 -07001357 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001358 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001359 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001360 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1361 data_channel_ = DataChannel::Create(
1362 session_.get(), session_->data_channel_type(), "datachannel", dci);
1363 }
1364
1365 void SetLocalDescriptionWithDataChannel() {
1366 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001367 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 SetLocalDescriptionWithoutError(offer);
1369 }
1370
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001372 RTCCertificateGenerationMethod cert_gen_method,
1373 CreateSessionDescriptionRequest::Type type) {
1374 InitWithDtls(cert_gen_method);
1375 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1376 }
1377
1378 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1379 CreateSessionDescriptionRequest::Type type) {
1380 InitWithDtlsIdentityGenFail();
1381 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1382 }
1383
1384 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001385 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001386 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001387 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 if (type == CreateSessionDescriptionRequest::kAnswer) {
1389 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001390 std::unique_ptr<JsepSessionDescription> offer(
1391 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001392 ASSERT_TRUE(offer.get() != NULL);
1393 SetRemoteDescriptionWithoutError(offer.release());
1394 }
1395
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001396 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001397 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001398 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001399 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001400 observers[kNumber];
1401 for (int i = 0; i < kNumber; ++i) {
1402 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1403 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001404 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 } else {
htaa2a49d92016-03-04 02:51:39 -08001406 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001407 }
1408 }
1409
1410 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1411 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1412 WebRtcSessionCreateSDPObserverForTest::kFailed;
1413
1414 for (int i = 0; i < kNumber; ++i) {
1415 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1416 if (success) {
1417 EXPECT_TRUE(observers[i]->description() != NULL);
1418 } else {
1419 EXPECT_TRUE(observers[i]->description() == NULL);
1420 }
1421 }
1422 }
1423
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001424 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001425 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001426 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001427 turn_server.credentials = credentials;
1428 turn_server.ports.push_back(
1429 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1430 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001431 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001432 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001433 }
1434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 cricket::FakeMediaEngine* media_engine_;
1436 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001437 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001438 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001439 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1440 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1441 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1442 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1443 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1444 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001445 rtc::SocketServerScope ss_scope_;
1446 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001447 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001448 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001449 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001450 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001451 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001452 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001453 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 MockIceObserver observer_;
1455 cricket::FakeVideoMediaChannel* video_channel_;
1456 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001457 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001458 // The following flags affect options created for CreateOffer/CreateAnswer.
1459 bool send_stream_1_ = false;
1460 bool send_stream_2_ = false;
1461 bool send_audio_ = false;
1462 bool send_video_ = false;
1463 rtc::scoped_refptr<DataChannel> data_channel_;
1464 // Last values received from data channel creation signal.
1465 std::string last_data_channel_label_;
1466 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001467 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468};
1469
Henrik Boström87713d02015-08-25 09:53:21 +02001470TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1471 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001472 // SDES is disabled when DTLS is on.
1473 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474}
1475
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001476TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001477 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001478 // SDES is required if DTLS is off.
1479 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001480}
1481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1483 TestSessionCandidatesWithBundleRtcpMux(false, false);
1484}
1485
1486// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1487// with rtcp-mux and/or bundle.
1488TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1489 TestSessionCandidatesWithBundleRtcpMux(false, true);
1490}
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1493 TestSessionCandidatesWithBundleRtcpMux(true, true);
1494}
1495
1496TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1498 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001499 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001500 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 InitiateCall();
1502 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1503 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1504 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1505}
1506
deadbeeff83a94a2016-06-03 16:05:26 -07001507// Crashes on Win only. See webrtc:5411.
1508#if defined(WEBRTC_WIN)
1509#define MAYBE_TestStunError DISABLED_TestStunError
1510#else
1511#define MAYBE_TestStunError TestStunError
1512#endif
1513TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001514 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1515 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001516 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001517 rtc::FP_UDP,
1518 rtc::FD_ANY,
1519 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001520 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001521 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001523 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff83a94a2016-06-03 16:05:26 -07001524 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1526 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1527}
1528
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001529TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001530 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001531 SessionDescriptionInterface* offer = NULL;
1532 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1533 std::string unknown_action;
1534 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1535 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1536}
1537
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538// Test creating offers and receive answers and make sure the
1539// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001541 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001542 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001543 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544 const std::string session_id_orig = offer->session_id();
1545 const std::string session_version_orig = offer->session_version();
1546 SetLocalDescriptionWithoutError(offer);
1547
deadbeefab9b2d12015-10-14 11:33:11 -07001548 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 SessionDescriptionInterface* answer =
1550 CreateRemoteAnswer(session_->local_description());
1551 SetRemoteDescriptionWithoutError(answer);
1552
1553 video_channel_ = media_engine_->GetVideoChannel(0);
1554 voice_channel_ = media_engine_->GetVoiceChannel(0);
1555
1556 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1557 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1558
1559 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1560 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1561
1562 ASSERT_EQ(1u, video_channel_->send_streams().size());
1563 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1564 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1565 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1566
1567 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001568 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001569 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570
1571 // Verify the session id is the same and the session version is
1572 // increased.
1573 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001574 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1575 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576
1577 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001578 EXPECT_EQ(0u, video_channel_->send_streams().size());
1579 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580
deadbeefab9b2d12015-10-14 11:33:11 -07001581 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 answer = CreateRemoteAnswer(session_->local_description());
1583 SetRemoteDescriptionWithoutError(answer);
1584
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 // Make sure the receive streams have not changed.
1586 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1587 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1588 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1589 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1590}
1591
1592// Test receiving offers and creating answers and make sure the
1593// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001595 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001597 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 SetRemoteDescriptionWithoutError(offer);
1600
deadbeefab9b2d12015-10-14 11:33:11 -07001601 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001602 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 SetLocalDescriptionWithoutError(answer);
1605
1606 const std::string session_id_orig = answer->session_id();
1607 const std::string session_version_orig = answer->session_version();
1608
1609 video_channel_ = media_engine_->GetVideoChannel(0);
1610 voice_channel_ = media_engine_->GetVoiceChannel(0);
1611
htaa2a49d92016-03-04 02:51:39 -08001612 ASSERT_TRUE(video_channel_);
1613 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1615 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1616
1617 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1618 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1619
1620 ASSERT_EQ(1u, video_channel_->send_streams().size());
1621 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1622 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1623 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1624
deadbeefab9b2d12015-10-14 11:33:11 -07001625 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001626 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 SetRemoteDescriptionWithoutError(offer);
1628
1629 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001630 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001631 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632
1633 // Verify the session id is the same and the session version is
1634 // increased.
1635 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001636 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1637 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 SetLocalDescriptionWithoutError(answer);
1639
1640 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1641 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1642 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1643 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1644 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1645 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1646
1647 // Make sure we have no send streams.
1648 EXPECT_EQ(0u, video_channel_->send_streams().size());
1649 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1650}
1651
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001652TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001653 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001654 media_engine_->set_fail_create_channel(true);
1655
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001656 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657 ASSERT_TRUE(offer != NULL);
1658 // SetRemoteDescription and SetLocalDescription will take the ownership of
1659 // the offer.
1660 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001662 ASSERT_TRUE(offer != NULL);
1663 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1664}
1665
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001666//
1667// Tests for creating/setting SDP under different SDES/DTLS polices:
1668//
1669// --DTLS off and SDES on
1670// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1671// set local/remote offer/answer with crypto --> success
1672// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1673// failure
1674// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1675// failure
1676// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1677// failure
1678//
1679// --DTLS on and SDES off
1680// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1681// set local/remote offer/answer with DTLS fingerprint --> success
1682// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1683// fingerprint --> failure
1684// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1685// --> failure
1686// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1687// --> failure
1688//
1689// --Encryption disabled: DTLS off and SDES off
1690// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1691// answer without SDES or DTLS --> success
1692// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1693// answer without SDES or DTLS --> success
1694//
1695
1696// Test that we return a failure when applying a remote/local offer that doesn't
1697// have cryptos enabled when DTLS is off.
1698TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001699 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001701 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 JsepSessionDescription* offer = CreateRemoteOffer(
1703 options, cricket::SEC_DISABLED);
1704 ASSERT_TRUE(offer != NULL);
1705 VerifyNoCryptoParams(offer->description(), false);
1706 // SetRemoteDescription and SetLocalDescription will take the ownership of
1707 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1710 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712}
1713
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001714// Test that we return a failure when applying a local answer that doesn't have
1715// cryptos enabled when DTLS is off.
1716TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001717 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SessionDescriptionInterface* offer = NULL;
1719 SessionDescriptionInterface* answer = NULL;
1720 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1721 // SetRemoteDescription and SetLocalDescription will take the ownership of
1722 // the offer.
1723 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001724 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725}
1726
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727// Test we will return fail when apply an remote answer that doesn't have
1728// crypto enabled when DTLS is off.
1729TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001730 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 SessionDescriptionInterface* offer = NULL;
1732 SessionDescriptionInterface* answer = NULL;
1733 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1734 // SetRemoteDescription and SetLocalDescription will take the ownership of
1735 // the offer.
1736 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738}
1739
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1741// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001742TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001743 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001744 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001745 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 SetFactoryDtlsSrtp();
1747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001748 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001749 JsepSessionDescription* offer =
1750 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 ASSERT_TRUE(offer != NULL);
1752 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001753 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
1755 // SetRemoteDescription will take the ownership of the offer.
1756 SetRemoteDescriptionWithoutError(offer);
1757
1758 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001759 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 ASSERT_TRUE(answer != NULL);
1761 VerifyFingerprintStatus(answer->description(), true);
1762 // Check that we don't have an a=crypto line in the answer.
1763 VerifyNoCryptoParams(answer->description(), true);
1764
1765 // Now set the local description, which should work, even without a=crypto.
1766 SetLocalDescriptionWithoutError(answer);
1767}
1768
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1770// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001771TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001772 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001773 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001774 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001775 SetFactoryDtlsSrtp();
1776
1777 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779 ASSERT_TRUE(offer != NULL);
1780 VerifyFingerprintStatus(offer->description(), true);
1781 // Check that we don't have an a=crypto line in the offer.
1782 VerifyNoCryptoParams(offer->description(), true);
1783
1784 // Now set the local description, which should work, even without a=crypto.
1785 SetLocalDescriptionWithoutError(offer);
1786
1787 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001788 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789 JsepSessionDescription* answer =
1790 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1791 ASSERT_TRUE(answer != NULL);
1792 VerifyFingerprintStatus(answer->description(), true);
1793 VerifyNoCryptoParams(answer->description(), true);
1794
1795 // SetRemoteDescription will take the ownership of the answer.
1796 SetRemoteDescriptionWithoutError(answer);
1797}
1798
1799// Test that if we support DTLS and the other side didn't offer a fingerprint,
1800// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001801TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001803 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001805 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 JsepSessionDescription* offer = CreateRemoteOffer(
1808 options, cricket::SEC_REQUIRED);
1809 ASSERT_TRUE(offer != NULL);
1810 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001811 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001813 // SetRemoteDescription will take the ownership of the offer.
1814 SetRemoteDescriptionOfferExpectError(
1815 kSdpWithoutDtlsFingerprint, offer);
1816
1817 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1818 // SetLocalDescription will take the ownership of the offer.
1819 SetLocalDescriptionOfferExpectError(
1820 kSdpWithoutDtlsFingerprint, offer);
1821}
1822
1823// Test that we return a failure when applying a local answer that doesn't have
1824// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001825TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001826 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001827 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 SessionDescriptionInterface* offer = NULL;
1829 SessionDescriptionInterface* answer = NULL;
1830 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1831
1832 // SetRemoteDescription and SetLocalDescription will take the ownership of
1833 // the offer and answer.
1834 SetRemoteDescriptionWithoutError(offer);
1835 SetLocalDescriptionAnswerExpectError(
1836 kSdpWithoutDtlsFingerprint, answer);
1837}
1838
1839// Test that we return a failure when applying a remote answer that doesn't have
1840// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001841TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001842 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001843 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001844 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001846 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001847 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001848 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001850 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001851
1852 // SetRemoteDescription and SetLocalDescription will take the ownership of
1853 // the offer and answer.
1854 SetLocalDescriptionWithoutError(offer);
1855 SetRemoteDescriptionAnswerExpectError(
1856 kSdpWithoutDtlsFingerprint, answer);
1857}
1858
1859// Test that we create a local offer without SDES or DTLS and accept a remote
1860// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001861TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001862 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001864 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865
1866 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001867 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 ASSERT_TRUE(offer != NULL);
1869 VerifyFingerprintStatus(offer->description(), false);
1870 // Check that we don't have an a=crypto line in the offer.
1871 VerifyNoCryptoParams(offer->description(), false);
1872
1873 // Now set the local description, which should work, even without a=crypto.
1874 SetLocalDescriptionWithoutError(offer);
1875
1876 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001877 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878 JsepSessionDescription* answer =
1879 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1880 ASSERT_TRUE(answer != NULL);
1881 VerifyFingerprintStatus(answer->description(), false);
1882 VerifyNoCryptoParams(answer->description(), false);
1883
1884 // SetRemoteDescription will take the ownership of the answer.
1885 SetRemoteDescriptionWithoutError(answer);
1886}
1887
1888// Test that we create a local answer without SDES or DTLS and accept a remote
1889// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001890TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001892 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001893
1894 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001895 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 JsepSessionDescription* offer =
1897 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1898 ASSERT_TRUE(offer != NULL);
1899 VerifyFingerprintStatus(offer->description(), false);
1900 VerifyNoCryptoParams(offer->description(), false);
1901
1902 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 SetRemoteDescriptionWithoutError(offer);
1904
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001906 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 ASSERT_TRUE(answer != NULL);
1908 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909 // Check that we don't have an a=crypto line in the answer.
1910 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 SetLocalDescriptionWithoutError(answer);
1914}
1915
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001916// Test that we can create and set an answer correctly when different
1917// SSL roles have been negotiated for different transports.
1918// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1919TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1920 SendAudioVideoStream1();
1921 InitWithDtls(GetParam());
1922 SetFactoryDtlsSrtp();
1923
1924 SessionDescriptionInterface* offer = CreateOffer();
1925 SetLocalDescriptionWithoutError(offer);
1926
1927 cricket::MediaSessionOptions options;
1928 options.recv_video = true;
1929
1930 // First, negotiate different SSL roles.
1931 SessionDescriptionInterface* answer =
1932 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1933 TransportInfo* audio_transport_info =
1934 answer->description()->GetTransportInfoByName("audio");
1935 audio_transport_info->description.connection_role =
1936 cricket::CONNECTIONROLE_ACTIVE;
1937 TransportInfo* video_transport_info =
1938 answer->description()->GetTransportInfoByName("video");
1939 video_transport_info->description.connection_role =
1940 cricket::CONNECTIONROLE_PASSIVE;
1941 SetRemoteDescriptionWithoutError(answer);
1942
1943 // Now create an offer in the reverse direction, and ensure the initial
1944 // offerer responds with an answer with correct SSL roles.
1945 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1946 kSessionVersion,
1947 session_->remote_description());
1948 SetRemoteDescriptionWithoutError(offer);
1949
htaa2a49d92016-03-04 02:51:39 -08001950 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001951 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1952 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1953 audio_transport_info->description.connection_role);
1954 video_transport_info = answer->description()->GetTransportInfoByName("video");
1955 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1956 video_transport_info->description.connection_role);
1957 SetLocalDescriptionWithoutError(answer);
1958
1959 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1960 // audio is transferred over to video in the answer that completes the BUNDLE
1961 // negotiation.
1962 options.bundle_enabled = true;
1963 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1964 kSessionVersion,
1965 session_->remote_description());
1966 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001967 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001968 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1969 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1970 audio_transport_info->description.connection_role);
1971 video_transport_info = answer->description()->GetTransportInfoByName("video");
1972 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1973 video_transport_info->description.connection_role);
1974 SetLocalDescriptionWithoutError(answer);
1975}
1976
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001978 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001979 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001981 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 SetLocalDescriptionWithoutError(offer);
1983
1984 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetLocalDescriptionWithoutError(offer2);
1987}
1988
1989TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001990 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001991 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001993 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 SetRemoteDescriptionWithoutError(offer);
1995
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001996 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 SetRemoteDescriptionWithoutError(offer2);
1998}
1999
2000TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002001 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002002 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002003 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002005 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002006 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2007 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008}
2009
2010TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002011 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002012 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002016 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002017 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018}
2019
2020TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002021 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002022 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002024 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025
htaa2a49d92016-03-04 02:51:39 -08002026 JsepSessionDescription* pranswer =
2027 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002029 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
deadbeefab9b2d12015-10-14 11:33:11 -07002031 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002032 JsepSessionDescription* pranswer2 =
2033 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2035
deadbeefd59daf82015-10-14 15:02:44 -07002036 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002039 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041}
2042
2043TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002044 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002045 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002046 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002047 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 JsepSessionDescription* pranswer =
2050 CreateRemoteAnswer(session_->local_description());
2051 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2052
2053 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002054 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 JsepSessionDescription* pranswer2 =
2058 CreateRemoteAnswer(session_->local_description());
2059 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2060
2061 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002062 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 SessionDescriptionInterface* answer =
2066 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002067 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068}
2069
2070TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002073 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 SessionDescriptionInterface* answer =
2076 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002077 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2078 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
2081TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002082 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002084 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 SessionDescriptionInterface* answer =
2087 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002088 SetRemoteDescriptionAnswerExpectError(
2089 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090}
2091
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002092// Tests that the remote candidates are added and removed successfully.
2093TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002094 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002095 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002097 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2098 "", "", "host", 0, "");
2099 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2101
deadbeefd59daf82015-10-14 15:02:44 -07002102 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2104
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002105 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002107
2108 // Fail since we have not set a remote description.
2109 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
2111 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2112 session_->local_description());
2113 SetRemoteDescriptionWithoutError(answer);
2114
deadbeefd59daf82015-10-14 15:02:44 -07002115 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2116 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002117 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002118 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2119 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 // Verifying the candidates are copied properly from internal vector.
2122 const SessionDescriptionInterface* remote_desc =
2123 session_->remote_description();
2124 ASSERT_TRUE(remote_desc != NULL);
2125 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2126 const IceCandidateCollection* candidates =
2127 remote_desc->candidates(kMediaContentIndex0);
2128 ASSERT_EQ(2u, candidates->count());
2129 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2130 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2131 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2132 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2133
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002134 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2135 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 candidate.set_component(2);
2137 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2138 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002139 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140
2141 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2142 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002143
2144 // Remove candidate1 and candidate2
2145 std::vector<cricket::Candidate> remote_candidates;
2146 remote_candidates.push_back(ice_candidate1.candidate());
2147 remote_candidates.push_back(ice_candidate2.candidate());
2148 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2149 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150}
2151
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002152// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153// that it is retained if the remote session description is changed.
2154TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 cricket::Candidate candidate1;
2157 candidate1.set_component(1);
2158 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2159 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002160 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 CreateAndSetRemoteOfferAndLocalAnswer();
2162
2163 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2164 const SessionDescriptionInterface* remote_desc =
2165 session_->remote_description();
2166 ASSERT_TRUE(remote_desc != NULL);
2167 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2168 const IceCandidateCollection* candidates =
2169 remote_desc->candidates(kMediaContentIndex0);
2170 ASSERT_EQ(1u, candidates->count());
2171 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2172
2173 // Update the RemoteSessionDescription with a new session description and
2174 // a candidate and check that the new remote session description contains both
2175 // candidates.
2176 SessionDescriptionInterface* offer = CreateRemoteOffer();
2177 cricket::Candidate candidate2;
2178 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2179 candidate2);
2180 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2181 SetRemoteDescriptionWithoutError(offer);
2182
2183 remote_desc = session_->remote_description();
2184 ASSERT_TRUE(remote_desc != NULL);
2185 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2186 candidates = remote_desc->candidates(kMediaContentIndex0);
2187 ASSERT_EQ(2u, candidates->count());
2188 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2189 // Username and password have be updated with the TransportInfo of the
2190 // SessionDescription, won't be equal to the original one.
2191 candidate2.set_username(candidates->at(0)->candidate().username());
2192 candidate2.set_password(candidates->at(0)->candidate().password());
2193 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2194 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2195 // No need to verify the username and password.
2196 candidate1.set_username(candidates->at(1)->candidate().username());
2197 candidate1.set_password(candidates->at(1)->candidate().password());
2198 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2199
2200 // Test that the candidate is ignored if we can add the same candidate again.
2201 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2202}
2203
2204// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002205// that they are retained if the local session description is changed. And if
2206// continual gathering is enabled, they are removed from the local session
2207// description when the network is down.
2208TEST_F(WebRtcSessionTest,
2209 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002210 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002211 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002212 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 CreateAndSetRemoteOfferAndLocalAnswer();
2214
2215 const SessionDescriptionInterface* local_desc = session_->local_description();
2216 const IceCandidateCollection* candidates =
2217 local_desc->candidates(kMediaContentIndex0);
2218 ASSERT_TRUE(candidates != NULL);
2219 EXPECT_EQ(0u, candidates->count());
2220
2221 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2222
2223 local_desc = session_->local_description();
2224 candidates = local_desc->candidates(kMediaContentIndex0);
2225 ASSERT_TRUE(candidates != NULL);
2226 EXPECT_LT(0u, candidates->count());
2227 candidates = local_desc->candidates(1);
2228 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002229 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230
2231 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002232 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 CreateAndSetRemoteOfferAndLocalAnswer();
2234
2235 local_desc = session_->local_description();
2236 candidates = local_desc->candidates(kMediaContentIndex0);
2237 ASSERT_TRUE(candidates != NULL);
2238 EXPECT_LT(0u, candidates->count());
2239 candidates = local_desc->candidates(1);
2240 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002241 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002242
2243 candidates = local_desc->candidates(kMediaContentIndex0);
2244 size_t num_local_candidates = candidates->count();
2245 // Enable Continual Gathering
2246 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2247 // Bring down the network interface to trigger candidate removals.
2248 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2249 // Verify that all local candidates are removed.
2250 EXPECT_EQ(0, observer_.num_candidates_removed_);
2251 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2252 kIceCandidatesTimeout);
2253 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2254}
2255
2256// Tests that if continual gathering is disabled, local candidates won't be
2257// removed when the interface is turned down.
2258TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2259 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2260 Init();
2261 SendAudioVideoStream1();
2262 CreateAndSetRemoteOfferAndLocalAnswer();
2263
2264 const SessionDescriptionInterface* local_desc = session_->local_description();
2265 const IceCandidateCollection* candidates =
2266 local_desc->candidates(kMediaContentIndex0);
2267 ASSERT_TRUE(candidates != NULL);
2268 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2269
2270 size_t num_local_candidates = candidates->count();
2271 EXPECT_LT(0u, num_local_candidates);
2272 // By default, Continual Gathering is disabled.
2273 // Bring down the network interface.
2274 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2275 // Verify that the local candidates are not removed.
2276 rtc::Thread::Current()->ProcessMessages(1000);
2277 EXPECT_EQ(0, observer_.num_candidates_removed_);
2278 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279}
2280
2281// Test that we can set a remote session description with remote candidates.
2282TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002283 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
2285 cricket::Candidate candidate1;
2286 candidate1.set_component(1);
2287 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2288 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002289 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002290 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
2292 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2293 SetRemoteDescriptionWithoutError(offer);
2294
2295 const SessionDescriptionInterface* remote_desc =
2296 session_->remote_description();
2297 ASSERT_TRUE(remote_desc != NULL);
2298 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2299 const IceCandidateCollection* candidates =
2300 remote_desc->candidates(kMediaContentIndex0);
2301 ASSERT_EQ(1u, candidates->count());
2302 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2303
htaa2a49d92016-03-04 02:51:39 -08002304 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 SetLocalDescriptionWithoutError(answer);
2306}
2307
2308// Test that offers and answers contains ice candidates when Ice candidates have
2309// been gathered.
2310TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002311 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002312 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002313 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 // Ice is started but candidates are not provided until SetLocalDescription
2315 // is called.
2316 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2317 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2318 CreateAndSetRemoteOfferAndLocalAnswer();
2319 // Wait until at least one local candidate has been collected.
2320 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2321 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322
kwibergd1fe2812016-04-27 06:47:29 -07002323 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2326 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
2328 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2329 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002330 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2332 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 SetLocalDescriptionWithoutError(answer);
2334}
2335
2336// Verifies TransportProxy and media channels are created with content names
2337// present in the SessionDescription.
2338TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002339 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002340 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002341 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342
2343 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002344 // "video". Goal is to modify these content names and verify transport
2345 // channels
2346 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 // present in SDP.
2348 std::string sdp;
2349 EXPECT_TRUE(offer->ToString(&sdp));
2350 const std::string kAudioMid = "a=mid:audio";
2351 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2352 const std::string kVideoMid = "a=mid:video";
2353 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2354
2355 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 kAudioMidReplaceStr.c_str(),
2358 kAudioMidReplaceStr.length(),
2359 &sdp);
2360 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002361 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 kVideoMidReplaceStr.c_str(),
2363 kVideoMidReplaceStr.length(),
2364 &sdp);
2365
2366 SessionDescriptionInterface* modified_offer =
2367 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2368
2369 SetRemoteDescriptionWithoutError(modified_offer);
2370
htaa2a49d92016-03-04 02:51:39 -08002371 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 SetLocalDescriptionWithoutError(answer);
2373
deadbeefcbecd352015-09-23 11:50:27 -07002374 cricket::TransportChannel* voice_transport_channel =
2375 session_->voice_rtp_transport_channel();
2376 EXPECT_TRUE(voice_transport_channel != NULL);
2377 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2378 cricket::TransportChannel* video_transport_channel =
2379 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002380 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002381 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2383 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2384}
2385
2386// Test that an offer contains the correct media content descriptions based on
2387// the send streams when no constraints have been set.
2388TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002389 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002390 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 ASSERT_TRUE(offer != NULL);
2393 const cricket::ContentInfo* content =
2394 cricket::GetFirstAudioContent(offer->description());
2395 EXPECT_TRUE(content != NULL);
2396 content = cricket::GetFirstVideoContent(offer->description());
2397 EXPECT_TRUE(content == NULL);
2398}
2399
2400// Test that an offer contains the correct media content descriptions based on
2401// the send streams when no constraints have been set.
2402TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002403 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002405 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002406 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 const cricket::ContentInfo* content =
2409 cricket::GetFirstAudioContent(offer->description());
2410 EXPECT_TRUE(content != NULL);
2411 content = cricket::GetFirstVideoContent(offer->description());
2412 EXPECT_TRUE(content == NULL);
2413
2414 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002415 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002416 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 content = cricket::GetFirstAudioContent(offer->description());
2418 EXPECT_TRUE(content != NULL);
2419 content = cricket::GetFirstVideoContent(offer->description());
2420 EXPECT_TRUE(content != NULL);
2421}
2422
2423// Test that an offer contains no media content descriptions if
2424// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2425TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002426 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002427 PeerConnectionInterface::RTCOfferAnswerOptions options;
2428 options.offer_to_receive_audio = 0;
2429 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
kwibergd1fe2812016-04-27 06:47:29 -07002431 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 ASSERT_TRUE(offer != NULL);
2434 const cricket::ContentInfo* content =
2435 cricket::GetFirstAudioContent(offer->description());
2436 EXPECT_TRUE(content == NULL);
2437 content = cricket::GetFirstVideoContent(offer->description());
2438 EXPECT_TRUE(content == NULL);
2439}
2440
2441// Test that an offer contains only audio media content descriptions if
2442// kOfferToReceiveAudio constraints are set to true.
2443TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002444 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002445 PeerConnectionInterface::RTCOfferAnswerOptions options;
2446 options.offer_to_receive_audio =
2447 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2448
kwibergd1fe2812016-04-27 06:47:29 -07002449 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450
2451 const cricket::ContentInfo* content =
2452 cricket::GetFirstAudioContent(offer->description());
2453 EXPECT_TRUE(content != NULL);
2454 content = cricket::GetFirstVideoContent(offer->description());
2455 EXPECT_TRUE(content == NULL);
2456}
2457
2458// Test that an offer contains audio and video media content descriptions if
2459// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2460TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002463 PeerConnectionInterface::RTCOfferAnswerOptions options;
2464 options.offer_to_receive_audio =
2465 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2466 options.offer_to_receive_video =
2467 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2468
kwibergd1fe2812016-04-27 06:47:29 -07002469 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 const cricket::ContentInfo* content =
2472 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002473 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 content = cricket::GetFirstVideoContent(offer->description());
2476 EXPECT_TRUE(content != NULL);
2477
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002478 // Sets constraints to false and verifies that audio/video contents are
2479 // removed.
2480 options.offer_to_receive_audio = 0;
2481 options.offer_to_receive_video = 0;
2482 offer.reset(CreateOffer(options));
2483
2484 content = cricket::GetFirstAudioContent(offer->description());
2485 EXPECT_TRUE(content == NULL);
2486 content = cricket::GetFirstVideoContent(offer->description());
2487 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488}
2489
2490// Test that an answer can not be created if the last remote description is not
2491// an offer.
2492TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002493 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002494 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 SetLocalDescriptionWithoutError(offer);
2496 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2497 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002498 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499}
2500
2501// Test that an answer contains the correct media content descriptions when no
2502// constraints have been set.
2503TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002504 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002506 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 const cricket::ContentInfo* content =
2510 cricket::GetFirstAudioContent(answer->description());
2511 ASSERT_TRUE(content != NULL);
2512 EXPECT_FALSE(content->rejected);
2513
2514 content = cricket::GetFirstVideoContent(answer->description());
2515 ASSERT_TRUE(content != NULL);
2516 EXPECT_FALSE(content->rejected);
2517}
2518
2519// Test that an answer contains the correct media content descriptions when no
2520// constraints have been set and the offer only contain audio.
2521TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 // Create a remote offer with audio only.
2524 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002525
kwibergd1fe2812016-04-27 06:47:29 -07002526 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2528 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2529
2530 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002531 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 const cricket::ContentInfo* content =
2533 cricket::GetFirstAudioContent(answer->description());
2534 ASSERT_TRUE(content != NULL);
2535 EXPECT_FALSE(content->rejected);
2536
2537 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2538}
2539
2540// Test that an answer contains the correct media content descriptions when no
2541// constraints have been set.
2542TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002543 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002545 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 SetRemoteDescriptionWithoutError(offer.release());
2547 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002548 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 const cricket::ContentInfo* content =
2551 cricket::GetFirstAudioContent(answer->description());
2552 ASSERT_TRUE(content != NULL);
2553 EXPECT_FALSE(content->rejected);
2554
2555 content = cricket::GetFirstVideoContent(answer->description());
2556 ASSERT_TRUE(content != NULL);
2557 EXPECT_FALSE(content->rejected);
2558}
2559
2560// Test that an answer contains the correct media content descriptions when
2561// constraints have been set but no stream is sent.
2562TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002563 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002565 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 SetRemoteDescriptionWithoutError(offer.release());
2567
htaa2a49d92016-03-04 02:51:39 -08002568 cricket::MediaSessionOptions session_options;
2569 session_options.recv_audio = false;
2570 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002571 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002572 CreateAnswer(session_options));
2573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 const cricket::ContentInfo* content =
2575 cricket::GetFirstAudioContent(answer->description());
2576 ASSERT_TRUE(content != NULL);
2577 EXPECT_TRUE(content->rejected);
2578
2579 content = cricket::GetFirstVideoContent(answer->description());
2580 ASSERT_TRUE(content != NULL);
2581 EXPECT_TRUE(content->rejected);
2582}
2583
2584// Test that an answer contains the correct media content descriptions when
2585// constraints have been set and streams are sent.
2586TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002587 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002589 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 SetRemoteDescriptionWithoutError(offer.release());
2591
htaa2a49d92016-03-04 02:51:39 -08002592 cricket::MediaSessionOptions options;
2593 options.recv_audio = false;
2594 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595
2596 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002597 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002598 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599
2600 // TODO(perkj): Should the direction be set to SEND_ONLY?
2601 const cricket::ContentInfo* content =
2602 cricket::GetFirstAudioContent(answer->description());
2603 ASSERT_TRUE(content != NULL);
2604 EXPECT_FALSE(content->rejected);
2605
2606 // TODO(perkj): Should the direction be set to SEND_ONLY?
2607 content = cricket::GetFirstVideoContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_FALSE(content->rejected);
2610}
2611
2612TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2613 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002614 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002615 PeerConnectionInterface::RTCOfferAnswerOptions options;
2616 options.offer_to_receive_audio =
2617 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2618 options.voice_activity_detection = false;
2619
kwibergd1fe2812016-04-27 06:47:29 -07002620 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002621
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 const cricket::ContentInfo* content =
2623 cricket::GetFirstAudioContent(offer->description());
2624 EXPECT_TRUE(content != NULL);
2625 EXPECT_TRUE(VerifyNoCNCodecs(content));
2626}
2627
2628TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2629 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002630 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002632 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 SetRemoteDescriptionWithoutError(offer.release());
2634
htaa2a49d92016-03-04 02:51:39 -08002635 cricket::MediaSessionOptions options;
2636 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002637 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 const cricket::ContentInfo* content =
2639 cricket::GetFirstAudioContent(answer->description());
2640 ASSERT_TRUE(content != NULL);
2641 EXPECT_TRUE(VerifyNoCNCodecs(content));
2642}
2643
2644// This test verifies the call setup when remote answer with audio only and
2645// later updates with video.
2646TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002647 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2649 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2650
deadbeefab9b2d12015-10-14 11:33:11 -07002651 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653
2654 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2656
2657 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2658 // and answer;
2659 SetLocalDescriptionWithoutError(offer);
2660 SetRemoteDescriptionWithoutError(answer);
2661
2662 video_channel_ = media_engine_->GetVideoChannel(0);
2663 voice_channel_ = media_engine_->GetVoiceChannel(0);
2664
2665 ASSERT_TRUE(video_channel_ == NULL);
2666
2667 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2668 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2669 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2670
2671 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002672 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673 CreateAndSetRemoteOfferAndLocalAnswer();
2674
2675 video_channel_ = media_engine_->GetVideoChannel(0);
2676 voice_channel_ = media_engine_->GetVoiceChannel(0);
2677
2678 ASSERT_TRUE(video_channel_ != NULL);
2679 ASSERT_TRUE(voice_channel_ != NULL);
2680
2681 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2682 ASSERT_EQ(1u, video_channel_->send_streams().size());
2683 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2684 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2685 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2686 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2687 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2688 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2689
2690 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002691 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 CreateAndSetRemoteOfferAndLocalAnswer();
2693
2694 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2695 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2696 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2697 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2698 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2699}
2700
2701// This test verifies the call setup when remote answer with video only and
2702// later updates with audio.
2703TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2706 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002707 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002708 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709
2710 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002711 options.recv_audio = false;
2712 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2714 offer, options, cricket::SEC_ENABLED);
2715
2716 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2717 // and answer.
2718 SetLocalDescriptionWithoutError(offer);
2719 SetRemoteDescriptionWithoutError(answer);
2720
2721 video_channel_ = media_engine_->GetVideoChannel(0);
2722 voice_channel_ = media_engine_->GetVoiceChannel(0);
2723
2724 ASSERT_TRUE(voice_channel_ == NULL);
2725 ASSERT_TRUE(video_channel_ != NULL);
2726
2727 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2728 ASSERT_EQ(1u, video_channel_->send_streams().size());
2729 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2730
2731 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002732 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 CreateAndSetRemoteOfferAndLocalAnswer();
2734
2735 voice_channel_ = media_engine_->GetVoiceChannel(0);
2736 ASSERT_TRUE(voice_channel_ != NULL);
2737
2738 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2739 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2740 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2741 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2742
2743 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002744 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002745 CreateAndSetRemoteOfferAndLocalAnswer();
2746
2747 video_channel_ = media_engine_->GetVideoChannel(0);
2748 voice_channel_ = media_engine_->GetVoiceChannel(0);
2749
2750 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2751 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2752 ASSERT_EQ(1u, video_channel_->send_streams().size());
2753 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2754}
2755
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002757 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002758 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002759 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 VerifyCryptoParams(offer->description());
2761 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002762 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763 VerifyCryptoParams(answer->description());
2764}
2765
2766TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002767 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002768 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002769 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002770 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 VerifyNoCryptoParams(offer->description(), false);
2772}
2773
2774TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyAnswerFromNonCryptoOffer();
2777}
2778
2779TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 VerifyAnswerFromCryptoOffer();
2782}
2783
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002784// This test verifies that setLocalDescription fails if
2785// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2786TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002788 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002789 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002790
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002791 std::string sdp;
2792 RemoveIceUfragPwdLines(offer.get(), &sdp);
2793 SessionDescriptionInterface* modified_offer =
2794 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002795 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002796}
2797
2798// This test verifies that setRemoteDescription fails if
2799// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2800TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002801 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002802 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002803 std::string sdp;
2804 RemoveIceUfragPwdLines(offer.get(), &sdp);
2805 SessionDescriptionInterface* modified_offer =
2806 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002807 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002808}
2809
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002810// This test verifies that setLocalDescription fails if local offer has
2811// too short ice ufrag and pwd strings.
2812TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002813 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002814 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002815 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002816 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2817 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002818 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002819 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002820 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002821
2822 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002823 offer.reset(CreateOffer());
2824 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2825 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002826}
2827
2828// This test verifies that setRemoteDescription fails if remote offer has
2829// too short ice ufrag and pwd strings.
2830TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002831 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002833 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2834 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002835 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002836 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002837 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002838
deadbeef0ed85b22016-02-23 17:24:52 -08002839 offer.reset(CreateRemoteOffer());
2840 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2841 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002842}
2843
Honghai Zhang04e91462015-12-11 14:26:22 -08002844// Test that if the remote offer indicates the peer requested ICE restart (via
2845// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2846TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002847 Init();
honghaiz503726c2015-07-31 12:37:38 -07002848
2849 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002850 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002851 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002852 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2853 0, "", "", "relay", 0, "");
2854 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2855 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002856 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2857 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002858 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2859
2860 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002861 offer.reset(CreateRemoteOffer());
2862 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002863 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2864 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2865 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002866 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2867 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002868 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2869
2870 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002871 offer.reset(CreateRemoteOffer());
2872 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002873 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2874 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2875 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002876 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2877 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002878 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2879
2880 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002881 offer.reset(CreateRemoteOffer());
2882 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2883 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002884 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2885}
2886
Honghai Zhang04e91462015-12-11 14:26:22 -08002887// Test that if the remote answer indicates the peer requested ICE restart (via
2888// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2889TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2890 Init();
2891 SessionDescriptionInterface* offer = CreateOffer();
2892 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002893
2894 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002895 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002896 answer->set_type(JsepSessionDescription::kPrAnswer);
2897 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002898 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2899 0, "", "", "relay", 0, "");
2900 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2901 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002902 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2903 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002904 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2905
2906 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002907 answer.reset(CreateRemoteAnswer(offer));
2908 answer->set_type(JsepSessionDescription::kPrAnswer);
2909 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002910 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2911 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2912 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002913 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2914 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002915 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2916
2917 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002918 answer.reset(CreateRemoteAnswer(offer));
2919 answer->set_type(JsepSessionDescription::kPrAnswer);
2920 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002921 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2922 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2923 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002924 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2925 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002926 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2927
2928 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002929 answer.reset(CreateRemoteAnswer(offer));
2930 answer->set_type(JsepSessionDescription::kPrAnswer);
2931 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2932 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002933 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2934}
2935
Donald Curtisd4f769d2015-05-28 09:48:21 -07002936// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002937// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002938TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2939 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2940
2941 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002942 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002943
2944 PeerConnectionInterface::RTCOfferAnswerOptions options;
2945 options.use_rtp_mux = true;
2946
2947 SessionDescriptionInterface* offer = CreateRemoteOffer();
2948 SetRemoteDescriptionWithoutError(offer);
2949
htaa2a49d92016-03-04 02:51:39 -08002950 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002951 SetLocalDescriptionWithoutError(answer);
2952
deadbeefcbecd352015-09-23 11:50:27 -07002953 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2954 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002955
deadbeefcbecd352015-09-23 11:50:27 -07002956 cricket::BaseChannel* voice_channel = session_->voice_channel();
2957 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002958
2959 // Checks if one of the transport channels contains a connection using a given
2960 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002961 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002962 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002963 session_->GetChannelTransportStats(voice_channel, &stats);
2964 for (auto& kv : stats.transport_stats) {
2965 for (auto& chan_stat : kv.second.channel_stats) {
2966 for (auto& conn_info : chan_stat.connection_infos) {
2967 if (conn_info.remote_candidate.address().port() == port) {
2968 return true;
2969 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002970 }
2971 }
2972 }
2973 return false;
2974 };
2975
2976 EXPECT_FALSE(connection_with_remote_port(5000));
2977 EXPECT_FALSE(connection_with_remote_port(5001));
2978 EXPECT_FALSE(connection_with_remote_port(6000));
2979
2980 // The way the *_WAIT checks work is they only wait if the condition fails,
2981 // which does not help in the case where state is not changing. This is
2982 // problematic in this test since we want to verify that adding a video
2983 // candidate does _not_ change state. So we interleave candidates and assume
2984 // that messages are executed in the order they were posted.
2985
2986 // First audio candidate.
2987 cricket::Candidate candidate0;
2988 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2989 candidate0.set_component(1);
2990 candidate0.set_protocol("udp");
2991 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2992 candidate0);
2993 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2994
2995 // Video candidate.
2996 cricket::Candidate candidate1;
2997 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2998 candidate1.set_component(1);
2999 candidate1.set_protocol("udp");
3000 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3001 candidate1);
3002 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3003
3004 // Second audio candidate.
3005 cricket::Candidate candidate2;
3006 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3007 candidate2.set_component(1);
3008 candidate2.set_protocol("udp");
3009 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3010 candidate2);
3011 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3012
3013 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3014 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3015
3016 // No need here for a _WAIT check since we are checking that state hasn't
3017 // changed: if this is false we would be doing waits for nothing and if this
3018 // is true then there will be no messages processed anyways.
3019 EXPECT_FALSE(connection_with_remote_port(6000));
3020}
3021
deadbeefcbecd352015-09-23 11:50:27 -07003022// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003023TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3024 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003025 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003026
3027 PeerConnectionInterface::RTCOfferAnswerOptions options;
3028 options.use_rtp_mux = true;
3029
3030 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
deadbeefcbecd352015-09-23 11:50:27 -07003033 EXPECT_NE(session_->voice_rtp_transport_channel(),
3034 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003035
deadbeefab9b2d12015-10-14 11:33:11 -07003036 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003037 SessionDescriptionInterface* answer =
3038 CreateRemoteAnswer(session_->local_description());
3039 SetRemoteDescriptionWithoutError(answer);
3040
deadbeefcbecd352015-09-23 11:50:27 -07003041 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3042 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003043}
3044
deadbeefcbecd352015-09-23 11:50:27 -07003045// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003046TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3047 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003048 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003049
Donald Curtis0e209b02015-03-24 09:29:54 -07003050 PeerConnectionInterface::RTCOfferAnswerOptions options;
3051 options.use_rtp_mux = true;
3052
3053 SessionDescriptionInterface* offer = CreateOffer(options);
3054 SetLocalDescriptionWithoutError(offer);
3055
deadbeefcbecd352015-09-23 11:50:27 -07003056 EXPECT_NE(session_->voice_rtp_transport_channel(),
3057 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003058
deadbeefab9b2d12015-10-14 11:33:11 -07003059 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003060
3061 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003062 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003063 CreateRemoteAnswer(session_->local_description()));
3064 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3065 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3066 JsepSessionDescription* modified_answer =
3067 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3068 modified_answer->Initialize(answer_copy, "1", "1");
3069 SetRemoteDescriptionWithoutError(modified_answer); //
3070
deadbeefcbecd352015-09-23 11:50:27 -07003071 EXPECT_NE(session_->voice_rtp_transport_channel(),
3072 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003073}
3074
3075// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3076TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3077 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003078 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003079
3080 PeerConnectionInterface::RTCOfferAnswerOptions options;
3081 options.use_rtp_mux = true;
3082
3083 SessionDescriptionInterface* offer = CreateOffer(options);
3084 SetLocalDescriptionWithoutError(offer);
3085
deadbeefcbecd352015-09-23 11:50:27 -07003086 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3087 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003088
deadbeefab9b2d12015-10-14 11:33:11 -07003089 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003090 SessionDescriptionInterface* answer =
3091 CreateRemoteAnswer(session_->local_description());
3092 SetRemoteDescriptionWithoutError(answer);
3093
deadbeefcbecd352015-09-23 11:50:27 -07003094 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3095 session_->video_rtp_transport_channel());
3096}
3097
3098// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3099// audio content in the answer.
3100TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3101 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003102 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003103
3104 PeerConnectionInterface::RTCOfferAnswerOptions options;
3105 options.use_rtp_mux = true;
3106
3107 SessionDescriptionInterface* offer = CreateOffer(options);
3108 SetLocalDescriptionWithoutError(offer);
3109
3110 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3111 session_->video_rtp_transport_channel());
3112
deadbeefab9b2d12015-10-14 11:33:11 -07003113 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003114 cricket::MediaSessionOptions recv_options;
3115 recv_options.recv_audio = false;
3116 recv_options.recv_video = true;
3117 SessionDescriptionInterface* answer =
3118 CreateRemoteAnswer(session_->local_description(), recv_options);
3119 SetRemoteDescriptionWithoutError(answer);
3120
deadbeefd59daf82015-10-14 15:02:44 -07003121 EXPECT_TRUE(nullptr == session_->voice_channel());
3122 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003123
deadbeefd59daf82015-10-14 15:02:44 -07003124 session_->Close();
3125 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3126 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3127 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3128 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129}
3130
3131// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3132TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003135
Donald Curtis0e209b02015-03-24 09:29:54 -07003136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
3138
3139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003146
3147 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003148 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149 CreateRemoteAnswer(session_->local_description()));
3150 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3151 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3152 JsepSessionDescription* modified_answer =
3153 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3154 modified_answer->Initialize(answer_copy, "1", "1");
3155 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156
deadbeefcbecd352015-09-23 11:50:27 -07003157 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
3159}
3160
3161// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003165
3166 SessionDescriptionInterface* offer = CreateRemoteOffer();
3167 SetRemoteDescriptionWithoutError(offer);
3168
3169 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3170 session_->video_rtp_transport_channel());
3171
deadbeefab9b2d12015-10-14 11:33:11 -07003172 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003173 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003174 SetLocalDescriptionWithoutError(answer);
3175
3176 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3177 session_->video_rtp_transport_channel());
3178}
3179
3180// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3181TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3182 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003183 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003184
3185 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003186 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003187 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3188 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3189 JsepSessionDescription* modified_offer =
3190 new JsepSessionDescription(JsepSessionDescription::kOffer);
3191 modified_offer->Initialize(offer_copy, "1", "1");
3192
3193 // Expect an error when applying the remote description
3194 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3195 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003196}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197
Peter Thatcher4eddf182015-04-30 10:55:59 -07003198// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003199TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3200 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003201 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
Donald Curtis0e209b02015-03-24 09:29:54 -07003203 PeerConnectionInterface::RTCOfferAnswerOptions options;
3204 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205
Donald Curtis0e209b02015-03-24 09:29:54 -07003206 SessionDescriptionInterface* offer = CreateOffer(options);
3207 SetLocalDescriptionWithoutError(offer);
3208
deadbeefcbecd352015-09-23 11:50:27 -07003209 EXPECT_NE(session_->voice_rtp_transport_channel(),
3210 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003211
deadbeefab9b2d12015-10-14 11:33:11 -07003212 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003213 SessionDescriptionInterface* answer =
3214 CreateRemoteAnswer(session_->local_description());
3215 SetRemoteDescriptionWithoutError(answer);
3216
3217 // This should lead to an audio-only call but isn't implemented
3218 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003219 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3220 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003221}
3222
deadbeefcbecd352015-09-23 11:50:27 -07003223// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003224TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3225 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003226 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003227 PeerConnectionInterface::RTCOfferAnswerOptions options;
3228 options.use_rtp_mux = true;
3229
3230 SessionDescriptionInterface* offer = CreateOffer(options);
3231 SetLocalDescriptionWithoutError(offer);
3232
deadbeefcbecd352015-09-23 11:50:27 -07003233 EXPECT_NE(session_->voice_rtp_transport_channel(),
3234 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003235
deadbeefab9b2d12015-10-14 11:33:11 -07003236 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003237
3238 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003239 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003240 CreateRemoteAnswer(session_->local_description()));
3241 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3242 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3243 JsepSessionDescription* modified_answer =
3244 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3245 modified_answer->Initialize(answer_copy, "1", "1");
3246 SetRemoteDescriptionWithoutError(modified_answer); //
3247
deadbeefcbecd352015-09-23 11:50:27 -07003248 EXPECT_NE(session_->voice_rtp_transport_channel(),
3249 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250}
3251
Peter Thatcher4eddf182015-04-30 10:55:59 -07003252// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3253TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3254 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003255 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003256
3257 PeerConnectionInterface::RTCOfferAnswerOptions options;
3258 options.use_rtp_mux = true;
3259
3260 SessionDescriptionInterface* offer = CreateOffer(options);
3261 SetRemoteDescriptionWithoutError(offer);
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3264 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003265}
3266
skvlad6c87a672016-05-17 17:49:52 -07003267// Adding a new channel to a BUNDLE which is already connected should directly
3268// assign the bundle transport to the channel, without first setting a
3269// disconnected non-bundle transport and then replacing it. The application
3270// should not receive any changes in the ICE state.
3271TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3272 LoopbackNetworkConfiguration config;
3273 LoopbackNetworkManager loopback_network_manager(this, config);
3274 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3275 // connected. Disabling either of these two means that we need to wait for the
3276 // answer to find out if more transports are needed.
3277 configuration_.bundle_policy =
3278 PeerConnectionInterface::kBundlePolicyMaxBundle;
3279 configuration_.rtcp_mux_policy =
3280 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3281 options_.disable_encryption = true;
3282 Init();
3283
3284 // Negotiate an audio channel with MAX_BUNDLE enabled.
3285 SendAudioOnlyStream2();
3286 SessionDescriptionInterface* offer = CreateOffer();
3287 SetLocalDescriptionWithoutError(offer);
3288 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3289 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3290 std::string sdp;
3291 offer->ToString(&sdp);
3292 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3293 JsepSessionDescription::kAnswer, sdp, nullptr);
3294 ASSERT_TRUE(answer != NULL);
3295 SetRemoteDescriptionWithoutError(answer);
3296
3297 // Wait for the ICE state to stabilize.
3298 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3299 observer_.ice_connection_state_, kIceCandidatesTimeout);
3300 observer_.ice_connection_state_history_.clear();
3301
3302 // Now add a video channel which should be using the same bundle transport.
3303 SendAudioVideoStream2();
3304 offer = CreateOffer();
3305 offer->ToString(&sdp);
3306 SetLocalDescriptionWithoutError(offer);
3307 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3308 sdp, nullptr);
3309 ASSERT_TRUE(answer != NULL);
3310 SetRemoteDescriptionWithoutError(answer);
3311
3312 // Wait for ICE state to stabilize
3313 rtc::Thread::Current()->ProcessMessages(0);
3314 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3315 observer_.ice_connection_state_, kIceCandidatesTimeout);
3316
3317 // No ICE state changes are expected to happen.
3318 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3319}
3320
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003321TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3322 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003323 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003324
3325 PeerConnectionInterface::RTCOfferAnswerOptions options;
3326 SessionDescriptionInterface* offer = CreateOffer(options);
3327 SetLocalDescriptionWithoutError(offer);
3328
deadbeefcbecd352015-09-23 11:50:27 -07003329 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3330 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003331
deadbeefab9b2d12015-10-14 11:33:11 -07003332 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003333 SessionDescriptionInterface* answer =
3334 CreateRemoteAnswer(session_->local_description());
3335 SetRemoteDescriptionWithoutError(answer);
3336
deadbeefcbecd352015-09-23 11:50:27 -07003337 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3338 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003339}
3340
3341TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3342 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003343 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003344
3345 PeerConnectionInterface::RTCOfferAnswerOptions options;
3346 SessionDescriptionInterface* offer = CreateOffer(options);
3347 SetLocalDescriptionWithoutError(offer);
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3350 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003351
deadbeefab9b2d12015-10-14 11:33:11 -07003352 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003353 SessionDescriptionInterface* answer =
3354 CreateRemoteAnswer(session_->local_description());
3355 SetRemoteDescriptionWithoutError(answer);
3356
deadbeefcbecd352015-09-23 11:50:27 -07003357 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3358 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003359}
3360
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003361// This test verifies that SetLocalDescription and SetRemoteDescription fails
3362// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3363TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003364 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003365 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003366
3367 PeerConnectionInterface::RTCOfferAnswerOptions options;
3368 options.use_rtp_mux = true;
3369
3370 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003371 std::string offer_str;
3372 offer->ToString(&offer_str);
3373 // Disable rtcp-mux
3374 const std::string rtcp_mux = "rtcp-mux";
3375 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003376 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003377 xrtcp_mux.c_str(), xrtcp_mux.length(),
3378 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003379 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003380 new JsepSessionDescription(JsepSessionDescription::kOffer);
3381 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003382 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003383 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003384 new JsepSessionDescription(JsepSessionDescription::kOffer);
3385 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003386 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003387 // Trying unmodified SDP.
3388 SetLocalDescriptionWithoutError(offer);
3389}
3390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003392 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003393 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 CreateAndSetRemoteOfferAndLocalAnswer();
3395 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3396 ASSERT_TRUE(channel != NULL);
3397 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003398 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003399 double volume;
3400 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3401 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003402 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003403 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3404 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003405 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003406 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3407 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408}
3409
skvlade0d46372016-04-07 22:59:22 -07003410TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003411 Init();
3412 SendAudioVideoStream1();
3413 CreateAndSetRemoteOfferAndLocalAnswer();
3414 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3415 ASSERT_TRUE(channel != NULL);
3416 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003417 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003418 webrtc::RtpParameters params = session_->GetAudioRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003419 EXPECT_EQ(1, params.encodings.size());
3420 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3421 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003422 EXPECT_TRUE(session_->SetAudioRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003423
skvlade0d46372016-04-07 22:59:22 -07003424 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003425 params = session_->GetAudioRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003426 EXPECT_EQ(1, params.encodings.size());
3427 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3428
3429 // Verify that the audio channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003430 params = channel->GetRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003431 EXPECT_EQ(1, params.encodings.size());
3432 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3433
3434 // Verify that the global bitrate limit has not been changed.
3435 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003436}
3437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003439 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003440 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 CreateAndSetRemoteOfferAndLocalAnswer();
3442 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3443 ASSERT_TRUE(channel != NULL);
3444 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003445 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3447
3448 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003449 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450
kwibergd1fe2812016-04-27 06:47:29 -07003451 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003452 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003454 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003455 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003457 // This will trigger SetSink(nullptr) to the |source|.
3458 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003460 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003461 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003462}
3463
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003464TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003465 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003466 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003467 CreateAndSetRemoteOfferAndLocalAnswer();
3468 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3469 ASSERT_TRUE(channel != NULL);
3470 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003471 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003472
kwibergd1fe2812016-04-27 06:47:29 -07003473 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003474 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003475 session_->SetAudioSend(send_ssrc, true, options, source.get());
3476 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003477
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003478 // Delete the |source| and it will trigger OnClose() to the sink, and this
3479 // will invalidate the |source_| pointer in the sink and prevent getting a
3480 // SetSink(nullptr) callback afterwards.
3481 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003482
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003483 // This will trigger SetSink(nullptr) if no OnClose() callback.
3484 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485}
3486
3487TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003488 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003489 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 CreateAndSetRemoteOfferAndLocalAnswer();
3491 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3492 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003493 ASSERT_LT(0u, channel->sinks().size());
3494 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003496 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 cricket::FakeVideoRenderer renderer;
3498 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003499 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003501 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502}
3503
skvladdc1c62c2016-03-16 19:07:43 -07003504TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3505 Init();
3506 SendAudioVideoStream1();
3507 CreateAndSetRemoteOfferAndLocalAnswer();
3508 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3509 ASSERT_TRUE(channel != NULL);
3510 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3511 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003512 webrtc::RtpParameters params = session_->GetVideoRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003513 EXPECT_EQ(1, params.encodings.size());
3514 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3515 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003516 EXPECT_TRUE(session_->SetVideoRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003517
3518 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003519 params = session_->GetVideoRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003520 EXPECT_EQ(1, params.encodings.size());
3521 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3522
3523 // Verify that the video channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003524 params = channel->GetRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003525 EXPECT_EQ(1, params.encodings.size());
3526 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3527
3528 // Verify that the global bitrate limit has not been changed.
3529 EXPECT_EQ(-1, channel->max_bps());
3530}
3531
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003533 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003534 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 CreateAndSetRemoteOfferAndLocalAnswer();
3536 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3537 ASSERT_TRUE(channel != NULL);
3538 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003539 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3541 cricket::VideoOptions* options = NULL;
deadbeef5a4a75a2016-06-02 16:23:38 -07003542 session_->SetVideoSend(send_ssrc, false, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003543 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
deadbeef5a4a75a2016-06-02 16:23:38 -07003544 session_->SetVideoSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3546}
3547
3548TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3549 TestCanInsertDtmf(false);
3550}
3551
3552TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3553 TestCanInsertDtmf(true);
3554}
3555
3556TEST_F(WebRtcSessionTest, InsertDtmf) {
3557 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003558 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003559 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 CreateAndSetRemoteOfferAndLocalAnswer();
3561 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3562 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3563
3564 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565 const int expected_duration = 90;
3566 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3567 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3568 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3569
3570 // Verify
3571 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003572 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003574 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003576 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003578 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579}
3580
deadbeefd59daf82015-10-14 15:02:44 -07003581// This test verifies the |initial_offerer| flag when session initiates the
3582// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003584 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003585 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003586 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3588 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003589 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003590 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003591 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592}
3593
deadbeefd59daf82015-10-14 15:02:44 -07003594// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003596 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003597 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 SessionDescriptionInterface* offer = CreateRemoteOffer();
3599 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003600 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601
deadbeefd59daf82015-10-14 15:02:44 -07003602 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003604 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605}
3606
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3608TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003609 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003610 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003611 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003613 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614 CreateRemoteAnswer(session_->local_description()));
3615
3616 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3617 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003618 JsepSessionDescription* modified_answer =
3619 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003620
3621 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3622 answer->session_id(),
3623 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003624 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625
wu@webrtc.org4e393072014-04-07 17:04:35 +00003626 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003627 std::string sdp;
3628 EXPECT_TRUE(answer->ToString(&sdp));
3629 const std::string kAudioMid = "a=mid:audio";
3630 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003631 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 kAudioMidReplaceStr.c_str(),
3633 kAudioMidReplaceStr.length(),
3634 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003635 SessionDescriptionInterface* modified_answer1 =
3636 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003637 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638
wu@webrtc.org4e393072014-04-07 17:04:35 +00003639 // Different media types.
3640 EXPECT_TRUE(answer->ToString(&sdp));
3641 const std::string kAudioMline = "m=audio";
3642 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003643 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003644 kAudioMlineReplaceStr.c_str(),
3645 kAudioMlineReplaceStr.length(),
3646 &sdp);
3647 SessionDescriptionInterface* modified_answer2 =
3648 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3649 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3650
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651 SetRemoteDescriptionWithoutError(answer.release());
3652}
3653
3654// Verifying remote offer and local answer have matching m-lines as per
3655// RFC 3264.
3656TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003657 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003658 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 SessionDescriptionInterface* offer = CreateRemoteOffer();
3660 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003661 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003662
3663 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3664 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003665 JsepSessionDescription* modified_answer =
3666 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
3668 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3669 answer->session_id(),
3670 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003671 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672 SetLocalDescriptionWithoutError(answer);
3673}
3674
3675// This test verifies that WebRtcSession does not start candidate allocation
3676// before SetLocalDescription is called.
3677TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003678 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003679 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 SessionDescriptionInterface* offer = CreateRemoteOffer();
3681 cricket::Candidate candidate;
3682 candidate.set_component(1);
3683 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3684 candidate);
3685 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3686 cricket::Candidate candidate1;
3687 candidate1.set_component(1);
3688 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3689 candidate1);
3690 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3691 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003692 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3693 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003694
3695 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003696 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003697 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3698 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3699
htaa2a49d92016-03-04 02:51:39 -08003700 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003701 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003702 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3703}
3704
3705// This test verifies that crypto parameter is updated in local session
3706// description as per security policy set in MediaSessionDescriptionFactory.
3707TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003708 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003709 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003710 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003711
3712 // Making sure SetLocalDescription correctly sets crypto value in
3713 // SessionDescription object after de-serialization of sdp string. The value
3714 // will be set as per MediaSessionDescriptionFactory.
3715 std::string offer_str;
3716 offer->ToString(&offer_str);
3717 SessionDescriptionInterface* jsep_offer_str =
3718 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3719 SetLocalDescriptionWithoutError(jsep_offer_str);
3720 EXPECT_TRUE(session_->voice_channel()->secure_required());
3721 EXPECT_TRUE(session_->video_channel()->secure_required());
3722}
3723
3724// This test verifies the crypto parameter when security is disabled.
3725TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003726 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003727 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003728 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003729 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003730
3731 // Making sure SetLocalDescription correctly sets crypto value in
3732 // SessionDescription object after de-serialization of sdp string. The value
3733 // will be set as per MediaSessionDescriptionFactory.
3734 std::string offer_str;
3735 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003736 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3738 SetLocalDescriptionWithoutError(jsep_offer_str);
3739 EXPECT_FALSE(session_->voice_channel()->secure_required());
3740 EXPECT_FALSE(session_->video_channel()->secure_required());
3741}
3742
3743// This test verifies that an answer contains new ufrag and password if an offer
3744// with new ufrag and password is received.
3745TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003746 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003748 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003749 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750 SetRemoteDescriptionWithoutError(offer.release());
3751
deadbeefab9b2d12015-10-14 11:33:11 -07003752 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003753 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754 SetLocalDescriptionWithoutError(answer.release());
3755
3756 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003757 for (const cricket::ContentInfo& content :
3758 session_->local_description()->description()->contents()) {
3759 options.transport_options[content.name].ice_restart = true;
3760 }
kwibergd1fe2812016-04-27 06:47:29 -07003761 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003762 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003763 SetRemoteDescriptionWithoutError(updated_offer1.release());
3764
kwibergd1fe2812016-04-27 06:47:29 -07003765 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766
deadbeef0ed85b22016-02-23 17:24:52 -08003767 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3768 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003769
deadbeef0ed85b22016-02-23 17:24:52 -08003770 // Even a second answer (created before the description is set) should have
3771 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003772 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003773
3774 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3775 session_->local_description()->description()));
3776
3777 SetLocalDescriptionWithoutError(updated_answer2.release());
3778}
3779
3780// This test verifies that an answer contains new ufrag and password if an offer
3781// that changes either the ufrag or password (but not both) is received.
3782// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3783// a=ice-pwd attributes compared to the previous SDP from the peer, it
3784// indicates that ICE is restarting for this media stream."
3785TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3786 Init();
3787 cricket::MediaSessionOptions options;
3788 options.recv_audio = true;
3789 options.recv_video = true;
3790 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003791 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003792 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3793 SetRemoteDescriptionWithoutError(offer.release());
3794
3795 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003796 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003797 SetLocalDescriptionWithoutError(answer.release());
3798
3799 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003800 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003801 CreateRemoteOffer(options, session_->remote_description()));
3802 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3803 "original_password12345");
3804 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3805
kwibergd1fe2812016-04-27 06:47:29 -07003806 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003807 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3808 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003809 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003810
3811 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003812 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003813 CreateRemoteOffer(options, session_->remote_description()));
3814 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3815 "modified_password12345");
3816 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3817
kwibergd1fe2812016-04-27 06:47:29 -07003818 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003819 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3820 session_->local_description()->description()));
3821 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003822}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003823
wu@webrtc.org91053e72013-08-10 07:18:04 +00003824// This test verifies that an answer contains old ufrag and password if an offer
3825// with old ufrag and password is received.
3826TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003827 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003828 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003829 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003830 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003831 SetRemoteDescriptionWithoutError(offer.release());
3832
deadbeefab9b2d12015-10-14 11:33:11 -07003833 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003834 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003835 SetLocalDescriptionWithoutError(answer.release());
3836
3837 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003838 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003839 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003840 SetRemoteDescriptionWithoutError(updated_offer2.release());
3841
kwibergd1fe2812016-04-27 06:47:29 -07003842 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003843
deadbeef0ed85b22016-02-23 17:24:52 -08003844 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3845 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003846
3847 SetLocalDescriptionWithoutError(updated_answer2.release());
3848}
3849
deadbeef0ed85b22016-02-23 17:24:52 -08003850// This test verifies that if an offer does an ICE restart on some, but not all
3851// media sections, the answer will change the ufrag/password in the correct
3852// media sections.
3853TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3854 Init();
3855 cricket::MediaSessionOptions options;
3856 options.recv_video = true;
3857 options.recv_audio = true;
3858 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003859 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003860
3861 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3862 "aaaaaaaaaaaaaaaaaaaaaa");
3863 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3864 "bbbbbbbbbbbbbbbbbbbbbb");
3865 SetRemoteDescriptionWithoutError(offer.release());
3866
3867 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003868 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003869 SetLocalDescriptionWithoutError(answer.release());
3870
3871 // Receive an offer with new ufrag and password, but only for the video media
3872 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003873 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003874 CreateRemoteOffer(options, session_->remote_description()));
3875 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3876 "cccccccccccccccccccccc");
3877 SetRemoteDescriptionWithoutError(updated_offer.release());
3878
kwibergd1fe2812016-04-27 06:47:29 -07003879 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003880
3881 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3882 session_->local_description()->description(),
3883 cricket::MEDIA_TYPE_AUDIO));
3884
3885 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3886 session_->local_description()->description(),
3887 cricket::MEDIA_TYPE_VIDEO));
3888
3889 SetLocalDescriptionWithoutError(updated_answer.release());
3890}
3891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003892TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003893 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003894 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003895 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003896 const std::string session_id_orig = offer->session_id();
3897 const std::string session_version_orig = offer->session_version();
3898 SetLocalDescriptionWithoutError(offer);
3899
3900 video_channel_ = media_engine_->GetVideoChannel(0);
3901 video_channel_->set_fail_set_send_codecs(true);
3902
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003903 SessionDescriptionInterface* answer =
3904 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003905 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003906
3907 // Test that after a content error, setting any description will
3908 // result in an error.
3909 video_channel_->set_fail_set_send_codecs(false);
3910 answer = CreateRemoteAnswer(session_->local_description());
3911 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3912 offer = CreateRemoteOffer();
3913 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003914}
3915
3916// Runs the loopback call test with BUNDLE and STUN disabled.
3917TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3918 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003919 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003920 cricket::PORTALLOCATOR_DISABLE_STUN |
3921 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003922 TestLoopbackCall();
3923}
3924
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003925TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003926 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003927 cricket::PORTALLOCATOR_DISABLE_STUN |
3928 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3929 cricket::PORTALLOCATOR_DISABLE_RELAY);
3930
3931 // best connection is IPv6 since it has higher network preference.
3932 LoopbackNetworkConfiguration config;
3933 config.test_ipv6_network_ = true;
3934 config.best_connection_after_initial_ice_converged_ =
3935 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3936
3937 TestLoopbackCall(config);
3938}
3939
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003940// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003941TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003942 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3943 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003944 TestLoopbackCall();
3945}
3946
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003947TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003948 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003949 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003950 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003951 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003952 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3953}
3954
Henrik Boström87713d02015-08-25 09:53:21 +02003955TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003956 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003957
htaa2a49d92016-03-04 02:51:39 -08003958 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003959 options_.disable_sctp_data_channels = false;
3960
Henrik Boström87713d02015-08-25 09:53:21 +02003961 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003962
3963 SetLocalDescriptionWithDataChannel();
3964 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3965}
3966
Henrik Boström87713d02015-08-25 09:53:21 +02003967TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003968 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003969
Henrik Boström87713d02015-08-25 09:53:21 +02003970 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003971
kwibergd1fe2812016-04-27 06:47:29 -07003972 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003973 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003974 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3975}
3976
Henrik Boström87713d02015-08-25 09:53:21 +02003977TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003978 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003979 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003980 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003981
3982 // Create remote offer with SCTP.
3983 cricket::MediaSessionOptions options;
3984 options.data_channel_type = cricket::DCT_SCTP;
3985 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003986 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003987 SetRemoteDescriptionWithoutError(offer);
3988
3989 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003990 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003991 EXPECT_TRUE(answer != NULL);
3992 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3993 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003994}
3995
Henrik Boström87713d02015-08-25 09:53:21 +02003996TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003997 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003998 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003999
4000 SetLocalDescriptionWithDataChannel();
4001 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4002}
4003
Henrik Boström87713d02015-08-25 09:53:21 +02004004TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004005 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004006
Henrik Boström87713d02015-08-25 09:53:21 +02004007 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004008
4009 SetLocalDescriptionWithDataChannel();
4010 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4011}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004012
Henrik Boström87713d02015-08-25 09:53:21 +02004013TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004014 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004015 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004016 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004017
4018 SetLocalDescriptionWithDataChannel();
4019 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4020}
4021
Henrik Boström87713d02015-08-25 09:53:21 +02004022TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004023 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004024 const int new_send_port = 9998;
4025 const int new_recv_port = 7775;
4026
Henrik Boström87713d02015-08-25 09:53:21 +02004027 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004028 SetFactoryDtlsSrtp();
4029
4030 // By default, don't actually add the codecs to desc_factory_; they don't
4031 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4032 // let the session description get parsed. That'll get the proper codecs
4033 // into the stream.
4034 cricket::MediaSessionOptions options;
4035 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4036 "stream1", new_send_port, options);
4037
4038 // SetRemoteDescription will take the ownership of the offer.
4039 SetRemoteDescriptionWithoutError(offer);
4040
htaa2a49d92016-03-04 02:51:39 -08004041 SessionDescriptionInterface* answer =
4042 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004043 ASSERT_TRUE(answer != NULL);
4044
4045 // Now set the local description, which'll take ownership of the answer.
4046 SetLocalDescriptionWithoutError(answer);
4047
4048 // TEST PLAN: Set the port number to something new, set it in the SDP,
4049 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004050 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004051 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004052
4053 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4054 int portnum = -1;
4055 ASSERT_TRUE(ch != NULL);
4056 ASSERT_EQ(1UL, ch->send_codecs().size());
4057 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004058 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004059 ch->send_codecs()[0].name.c_str()));
4060 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4061 &portnum));
4062 EXPECT_EQ(new_send_port, portnum);
4063
4064 ASSERT_EQ(1UL, ch->recv_codecs().size());
4065 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004066 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004067 ch->recv_codecs()[0].name.c_str()));
4068 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4069 &portnum));
4070 EXPECT_EQ(new_recv_port, portnum);
4071}
4072
deadbeefab9b2d12015-10-14 11:33:11 -07004073// Verifies that when a session's DataChannel receives an OPEN message,
4074// WebRtcSession signals the DataChannel creation request with the expected
4075// config.
4076TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4077 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4078
4079 InitWithDtls(GetParam());
4080
4081 SetLocalDescriptionWithDataChannel();
4082 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4083
4084 webrtc::DataChannelInit config;
4085 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004086 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004087 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4088 cricket::ReceiveDataParams params;
4089 params.ssrc = config.id;
4090 params.type = cricket::DMT_CONTROL;
4091
4092 cricket::DataChannel* data_channel = session_->data_channel();
4093 data_channel->SignalDataReceived(data_channel, params, payload);
4094
4095 EXPECT_EQ("a", last_data_channel_label_);
4096 EXPECT_EQ(config.id, last_data_channel_config_.id);
4097 EXPECT_FALSE(last_data_channel_config_.negotiated);
4098 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4099 last_data_channel_config_.open_handshake_role);
4100}
4101
4102TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004103 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004104 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004105
htaa2a49d92016-03-04 02:51:39 -08004106 configuration_.certificates.push_back(certificate);
4107 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004108 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4109
4110 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4111}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004112
Henrik Boström87713d02015-08-25 09:53:21 +02004113// Verifies that CreateOffer succeeds when CreateOffer is called before async
4114// identity generation is finished (even if a certificate is provided this is
4115// an async op).
4116TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4117 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4118 InitWithDtls(GetParam());
4119
Henrik Boströmd8281982015-08-27 10:12:24 +02004120 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004121 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004122 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004123
wu@webrtc.org91053e72013-08-10 07:18:04 +00004124 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004125 VerifyNoCryptoParams(offer->description(), true);
4126 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004127}
4128
4129// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004130// identity generation is finished (even if a certificate is provided this is
4131// an async op).
4132TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004133 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004134 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004135 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004136
4137 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004138 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004139 std::unique_ptr<JsepSessionDescription> offer(
4140 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141 ASSERT_TRUE(offer.get() != NULL);
4142 SetRemoteDescriptionWithoutError(offer.release());
4143
kwibergd1fe2812016-04-27 06:47:29 -07004144 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004145 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004146 VerifyNoCryptoParams(answer->description(), true);
4147 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004148}
4149
4150// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004151// identity generation is finished (even if a certificate is provided this is
4152// an async op).
4153TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004154 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004155 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004156
Henrik Boströmd8281982015-08-27 10:12:24 +02004157 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004158
kwibergd1fe2812016-04-27 06:47:29 -07004159 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004160 EXPECT_TRUE(offer != NULL);
4161}
4162
4163// Verifies that CreateOffer fails when CreateOffer is called after async
4164// identity generation fails.
4165TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004166 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004167 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004168
Henrik Boströmd8281982015-08-27 10:12:24 +02004169 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004170
kwibergd1fe2812016-04-27 06:47:29 -07004171 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004172 EXPECT_TRUE(offer == NULL);
4173}
4174
4175// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4176// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004177TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004178 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004179 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004180 VerifyMultipleAsyncCreateDescription(GetParam(),
4181 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004182}
4183
4184// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4185// before async identity generation fails.
4186TEST_F(WebRtcSessionTest,
4187 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004188 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004189 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4190 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004191}
4192
4193// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4194// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004195TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004196 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004197 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004198 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004199 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004200}
4201
4202// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4203// before async identity generation fails.
4204TEST_F(WebRtcSessionTest,
4205 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004206 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004207 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4208 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004209}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004210
4211// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4212// offer has no SDES crypto but only DTLS fingerprint.
4213TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4214 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004215 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004216 // Create a remote offer with secured transport disabled.
4217 cricket::MediaSessionOptions options;
4218 JsepSessionDescription* offer(CreateRemoteOffer(
4219 options, cricket::SEC_DISABLED));
4220 // Adds a DTLS fingerprint to the remote offer.
4221 cricket::SessionDescription* sdp = offer->description();
4222 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4223 ASSERT_TRUE(audio != NULL);
4224 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4225 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004226 rtc::SSLFingerprint::CreateFromRfc4572(
4227 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004228 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004229 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004230}
4231
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004232TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004233 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004234 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004235 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004236 SessionDescriptionInterface* offer = CreateOffer();
4237
4238 SetLocalDescriptionWithoutError(offer);
4239
4240 voice_channel_ = media_engine_->GetVoiceChannel(0);
4241
4242 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004243 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004244 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004245}
4246
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004247// Tests that we can renegotiate new media content with ICE candidates in the
4248// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004249TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004250 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004251 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004252 SetFactoryDtlsSrtp();
4253
deadbeefab9b2d12015-10-14 11:33:11 -07004254 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004255 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004256 SetLocalDescriptionWithoutError(offer);
4257
4258 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4259 SetRemoteDescriptionWithoutError(answer);
4260
4261 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004262 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004263 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4264
4265 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004266 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267 candidate1.set_component(1);
4268 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4269 candidate1);
4270 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4271 SetRemoteDescriptionWithoutError(offer);
4272
htaa2a49d92016-03-04 02:51:39 -08004273 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004274 SetLocalDescriptionWithoutError(answer);
4275}
4276
4277// Tests that we can renegotiate new media content with ICE candidates separated
4278// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004279TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004280 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004281 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004282 SetFactoryDtlsSrtp();
4283
deadbeefab9b2d12015-10-14 11:33:11 -07004284 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004285 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004286 SetLocalDescriptionWithoutError(offer);
4287
4288 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4289 SetRemoteDescriptionWithoutError(answer);
4290
4291 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004292 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004293 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4294 SetRemoteDescriptionWithoutError(offer);
4295
4296 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004297 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004298 candidate1.set_component(1);
4299 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4300 candidate1);
4301 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4302
htaa2a49d92016-03-04 02:51:39 -08004303 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004304 SetLocalDescriptionWithoutError(answer);
4305}
honghaiz7f777492016-02-02 21:54:01 -08004306
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004307// Tests that RTX codec is removed from the answer when it isn't supported
4308// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004309TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004310 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004311 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004312 std::string offer_sdp(kSdpWithRtx);
4313
4314 SessionDescriptionInterface* offer =
4315 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4316 EXPECT_TRUE(offer->ToString(&offer_sdp));
4317
4318 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004319 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004320 SetRemoteDescriptionWithoutError(offer);
4321
htaa2a49d92016-03-04 02:51:39 -08004322 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004323 // Answer SDP does not contain the RTX codec.
4324 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004325 SetLocalDescriptionWithoutError(answer);
4326}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004327
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004328// This verifies that the voice channel after bundle has both options from video
4329// and voice channels.
4330TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4331 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004332 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004333
4334 PeerConnectionInterface::RTCOfferAnswerOptions options;
4335 options.use_rtp_mux = true;
4336
4337 SessionDescriptionInterface* offer = CreateOffer(options);
4338 SetLocalDescriptionWithoutError(offer);
4339
4340 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4341 rtc::Socket::Option::OPT_SNDBUF, 4000);
4342
4343 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4344 rtc::Socket::Option::OPT_RCVBUF, 8000);
4345
4346 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004347 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004348 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4349 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004350 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004351 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4352
deadbeefcbecd352015-09-23 11:50:27 -07004353 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004354 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4355 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004356 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004357 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4358
deadbeefcbecd352015-09-23 11:50:27 -07004359 EXPECT_NE(session_->voice_rtp_transport_channel(),
4360 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004361
deadbeefab9b2d12015-10-14 11:33:11 -07004362 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004363 SessionDescriptionInterface* answer =
4364 CreateRemoteAnswer(session_->local_description());
4365 SetRemoteDescriptionWithoutError(answer);
4366
deadbeefcbecd352015-09-23 11:50:27 -07004367 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004368 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4369 EXPECT_EQ(4000, option_val);
4370
deadbeefcbecd352015-09-23 11:50:27 -07004371 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004372 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4373 EXPECT_EQ(8000, option_val);
4374}
4375
tommi0f620f42015-07-09 03:25:02 -07004376// Test creating a session, request multiple offers, destroy the session
4377// and make sure we got success/failure callbacks for all of the requests.
4378// Background: crbug.com/507307
4379TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4380 Init();
4381
4382 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4383 PeerConnectionInterface::RTCOfferAnswerOptions options;
4384 options.offer_to_receive_audio =
4385 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004386 cricket::MediaSessionOptions session_options;
4387 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004388
4389 for (auto& o : observers) {
4390 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004391 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004392 }
4393
4394 session_.reset();
4395
tommi0f620f42015-07-09 03:25:02 -07004396 for (auto& o : observers) {
4397 // We expect to have received a notification now even if the session was
4398 // terminated. The offer creation may or may not have succeeded, but we
4399 // must have received a notification which, so the only invalid state
4400 // is kInit.
4401 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4402 }
4403}
4404
stefanc1aeaf02015-10-15 07:26:07 -07004405TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4406 TestPacketOptions();
4407}
4408
deadbeef057ecf02016-01-20 14:30:43 -08004409// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4410// is destroyed.
4411TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4412 Init();
4413 session_.reset();
4414 EXPECT_TRUE(session_destroyed_);
4415}
4416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004417// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4418// currently fails because upon disconnection and reconnection OnIceComplete is
4419// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004420
deadbeefcbecd352015-09-23 11:50:27 -07004421INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4422 WebRtcSessionTest,
4423 testing::Values(ALREADY_GENERATED,
4424 DTLS_IDENTITY_STORE));