blob: 571e1994f441a6defbe21ba292ae3fa67ae25507 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/test/fakedtlsidentitystore.h"
23#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/media/base/fakemediaengine.h"
39#include "webrtc/media/base/fakevideorenderer.h"
40#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080042#include "webrtc/p2p/base/stunserver.h"
43#include "webrtc/p2p/base/teststunserver.h"
44#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/base/transportchannel.h"
46#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010047#include "webrtc/pc/channelmanager.h"
48#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
51 if (!(feature())) { \
52 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200161 virtual ~MockIceObserver() = default;
162
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceConnectionChange(
164 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 ice_connection_state_ = new_state;
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;
nisse2ded9b12016-04-08 02:23:55 -0700256 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 using webrtc::WebRtcSession::SetVideoPlayout;
258 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700259
260 private:
261 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
262 if (!ch) {
263 return nullptr;
264 }
265 return ch->transport_channel();
266 }
267
268 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
269 if (!ch) {
270 return nullptr;
271 }
272 return ch->rtcp_transport_channel();
273 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274};
275
wu@webrtc.org91053e72013-08-10 07:18:04 +0000276class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000277 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000279 enum State {
280 kInit,
281 kFailed,
282 kSucceeded,
283 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000284 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285
286 // CreateSessionDescriptionObserver implementation.
287 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289 state_ = kSucceeded;
290 }
291 virtual void OnFailure(const std::string& error) {
292 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000295 SessionDescriptionInterface* description() { return description_.get(); }
296
297 SessionDescriptionInterface* ReleaseDescription() {
298 return description_.release();
299 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
wu@webrtc.org91053e72013-08-10 07:18:04 +0000301 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 protected:
304 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305
306 private:
kwibergd1fe2812016-04-27 06:47:29 -0700307 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000308 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309};
310
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800311class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800313 FakeAudioSource() : sink_(NULL) {}
314 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000315 if (sink_)
316 sink_->OnClose();
317 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000319 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800321 const cricket::AudioSource::Sink* sink() const { return sink_; }
322
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000323 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800324 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000325};
326
Henrik Boström87713d02015-08-25 09:53:21 +0200327class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700328 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
329 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 protected:
331 // TODO Investigate why ChannelManager crashes, if it's created
332 // after stun_server.
333 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700334 : media_engine_(new cricket::FakeMediaEngine()),
335 data_engine_(new cricket::FakeDataEngine()),
336 channel_manager_(
337 new cricket::ChannelManager(media_engine_,
338 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700339 rtc::Thread::Current())),
340 fake_call_(webrtc::Call::Config()),
341 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800342 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
343 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700344 channel_manager_.get())),
345 tdesc_factory_(new cricket::TransportDescriptionFactory()),
346 desc_factory_(
347 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
348 tdesc_factory_.get())),
349 pss_(new rtc::PhysicalSocketServer),
350 vss_(new rtc::VirtualSocketServer(pss_.get())),
351 fss_(new rtc::FirewallSocketServer(vss_.get())),
352 ss_scope_(fss_.get()),
353 stun_socket_addr_(
354 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
355 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
356 stun_socket_addr_)),
357 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
358 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000359 cricket::ServerAddresses stun_servers;
360 stun_servers.insert(stun_socket_addr_);
361 allocator_.reset(new cricket::BasicPortAllocator(
362 &network_manager_,
363 stun_servers,
364 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000365 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700366 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 EXPECT_TRUE(channel_manager_->Init());
368 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000369 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 }
371
372 void AddInterface(const SocketAddress& addr) {
373 network_manager_.AddInterface(addr);
374 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700375 void RemoveInterface(const SocketAddress& addr) {
376 network_manager_.RemoveInterface(addr);
377 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378
Henrik Boström87713d02015-08-25 09:53:21 +0200379 // If |dtls_identity_store| != null or |rtc_configuration| contains
380 // |certificates| then DTLS will be enabled unless explicitly disabled by
381 // |rtc_configuration| options. When DTLS is enabled a certificate will be
382 // used if provided, otherwise one will be generated using the
383 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 void Init(
kwibergd1fe2812016-04-27 06:47:29 -0700385 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 ASSERT_TRUE(session_.get() == NULL);
387 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700388 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
danilchape9021a32016-05-17 01:52:02 -0700389 rtc::Thread::Current(), allocator_.get(), &observer_));
deadbeefab9b2d12015-10-14 11:33:11 -0700390 session_->SignalDataChannelOpenMessage.connect(
391 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800392 session_->GetOnDestroyedSignal()->connect(
393 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
395 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
396 observer_.ice_connection_state_);
397 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
398 observer_.ice_gathering_state_);
399
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200400 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator(
401 dtls_identity_store ? new webrtc::RTCCertificateGeneratorStoreWrapper(
402 std::move(dtls_identity_store)) : nullptr);
403 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800404 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700405 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 }
407
deadbeefab9b2d12015-10-14 11:33:11 -0700408 void OnDataChannelOpenMessage(const std::string& label,
409 const InternalDataChannelInit& config) {
410 last_data_channel_label_ = label;
411 last_data_channel_config_ = config;
412 }
413
deadbeef057ecf02016-01-20 14:30:43 -0800414 void OnSessionDestroyed() { session_destroyed_ = true; }
415
htaa2a49d92016-03-04 02:51:39 -0800416 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000417
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 void InitWithBundlePolicy(
419 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800420 configuration_.bundle_policy = bundle_policy;
421 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700422 }
423
424 void InitWithRtcpMuxPolicy(
425 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
426 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800427 configuration_.rtcp_mux_policy = rtcp_mux_policy;
428 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000429 }
430
Henrik Boström87713d02015-08-25 09:53:21 +0200431 // Successfully init with DTLS; with a certificate generated and supplied or
432 // with a store that generates it for us.
433 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
kwibergd1fe2812016-04-27 06:47:29 -0700434 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200435 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800436 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200437 FakeDtlsIdentityStore::GenerateCertificate());
438 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
439 dtls_identity_store.reset(new FakeDtlsIdentityStore());
440 dtls_identity_store->set_should_fail(false);
441 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700442 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200443 }
htaa2a49d92016-03-04 02:51:39 -0800444 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200445 }
446
447 // Init with DTLS with a store that will fail to generate a certificate.
448 void InitWithDtlsIdentityGenFail() {
kwibergd1fe2812016-04-27 06:47:29 -0700449 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
Henrik Boström5e56c592015-08-11 10:33:13 +0200450 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200451 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800452 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000453 }
454
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 void InitWithDtmfCodec() {
456 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700457 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
458 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 std::vector<cricket::AudioCodec> codecs;
460 codecs.push_back(kTelephoneEventCodec);
461 media_engine_->SetAudioCodecs(codecs);
462 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000463 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 }
465
deadbeefab9b2d12015-10-14 11:33:11 -0700466 void SendAudioVideoStream1() {
467 send_stream_1_ = true;
468 send_stream_2_ = false;
469 send_audio_ = true;
470 send_video_ = true;
471 }
472
473 void SendAudioVideoStream2() {
474 send_stream_1_ = false;
475 send_stream_2_ = true;
476 send_audio_ = true;
477 send_video_ = true;
478 }
479
480 void SendAudioVideoStream1And2() {
481 send_stream_1_ = true;
482 send_stream_2_ = true;
483 send_audio_ = true;
484 send_video_ = true;
485 }
486
487 void SendNothing() {
488 send_stream_1_ = false;
489 send_stream_2_ = false;
490 send_audio_ = false;
491 send_video_ = false;
492 }
493
494 void SendAudioOnlyStream2() {
495 send_stream_1_ = false;
496 send_stream_2_ = true;
497 send_audio_ = true;
498 send_video_ = false;
499 }
500
501 void SendVideoOnlyStream2() {
502 send_stream_1_ = false;
503 send_stream_2_ = true;
504 send_audio_ = false;
505 send_video_ = true;
506 }
507
508 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
509 if (send_stream_1_ && send_audio_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
511 kStream1);
512 }
513 if (send_stream_1_ && send_video_) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
515 kStream1);
516 }
517 if (send_stream_2_ && send_audio_) {
518 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
519 kStream2);
520 }
521 if (send_stream_2_ && send_video_) {
522 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
523 kStream2);
524 }
525 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
526 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
527 data_channel_->label(),
528 data_channel_->label());
529 }
530 }
531
532 void GetOptionsForOffer(
533 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
534 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800535 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700536
deadbeefc80741f2015-10-22 13:14:45 -0700537 AddStreamsToOptions(session_options);
538 if (rtc_options.offer_to_receive_audio ==
539 RTCOfferAnswerOptions::kUndefined) {
540 session_options->recv_audio =
541 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
542 }
543 if (rtc_options.offer_to_receive_video ==
544 RTCOfferAnswerOptions::kUndefined) {
545 session_options->recv_video =
546 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
547 }
548 session_options->bundle_enabled =
549 session_options->bundle_enabled &&
550 (session_options->has_audio() || session_options->has_video() ||
551 session_options->has_data());
552
deadbeefab9b2d12015-10-14 11:33:11 -0700553 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
554 session_options->data_channel_type = cricket::DCT_SCTP;
555 }
556 }
557
htaa2a49d92016-03-04 02:51:39 -0800558 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
559 // ParseConstraintsForAnswer is used to set some defaults.
560 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700561
deadbeefc80741f2015-10-22 13:14:45 -0700562 AddStreamsToOptions(session_options);
563 session_options->bundle_enabled =
564 session_options->bundle_enabled &&
565 (session_options->has_audio() || session_options->has_video() ||
566 session_options->has_data());
567
deadbeefab9b2d12015-10-14 11:33:11 -0700568 if (session_->data_channel_type() == cricket::DCT_SCTP) {
569 session_options->data_channel_type = cricket::DCT_SCTP;
570 }
571 }
572
573 // Creates a local offer and applies it. Starts ICE.
574 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 // to decide which streams to create.
576 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000577 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 SetLocalDescriptionWithoutError(offer);
579 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
580 observer_.ice_gathering_state_,
581 kIceCandidatesTimeout);
582 }
583
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000584 SessionDescriptionInterface* CreateOffer() {
585 PeerConnectionInterface::RTCOfferAnswerOptions options;
586 options.offer_to_receive_audio =
587 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
588
589 return CreateOffer(options);
590 }
591
wu@webrtc.org91053e72013-08-10 07:18:04 +0000592 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800593 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000594 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700596 cricket::MediaSessionOptions session_options;
597 GetOptionsForOffer(options, &session_options);
598 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000599 EXPECT_TRUE_WAIT(
600 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000601 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000602 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000603 }
604
605 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800606 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000607 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000608 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800609 cricket::MediaSessionOptions session_options = options;
610 GetOptionsForAnswer(&session_options);
611 // Overwrite recv_audio and recv_video with passed-in values.
612 session_options.recv_video = options.recv_video;
613 session_options.recv_audio = options.recv_audio;
614 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 EXPECT_TRUE_WAIT(
616 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000617 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000618 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000619 }
620
htaa2a49d92016-03-04 02:51:39 -0800621 SessionDescriptionInterface* CreateAnswer() {
622 cricket::MediaSessionOptions options;
623 options.recv_video = true;
624 options.recv_audio = true;
625 return CreateAnswer(options);
626 }
627
wu@webrtc.org364f2042013-11-20 21:49:41 +0000628 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 return (session_->voice_channel() != NULL &&
630 session_->video_channel() != NULL);
631 }
632
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
634 ASSERT_TRUE(session_.get() != NULL);
635 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
636 ASSERT_TRUE(content != NULL);
637 const cricket::AudioContentDescription* audio_content =
638 static_cast<const cricket::AudioContentDescription*>(
639 content->description);
640 ASSERT_TRUE(audio_content != NULL);
641 ASSERT_EQ(1U, audio_content->cryptos().size());
642 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
643 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
644 audio_content->cryptos()[0].cipher_suite);
645 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
646 audio_content->protocol());
647
648 content = cricket::GetFirstVideoContent(sdp);
649 ASSERT_TRUE(content != NULL);
650 const cricket::VideoContentDescription* video_content =
651 static_cast<const cricket::VideoContentDescription*>(
652 content->description);
653 ASSERT_TRUE(video_content != NULL);
654 ASSERT_EQ(1U, video_content->cryptos().size());
655 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
656 video_content->cryptos()[0].cipher_suite);
657 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
658 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
659 video_content->protocol());
660 }
661
662 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
663 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
664 ASSERT_TRUE(content != NULL);
665 const cricket::AudioContentDescription* audio_content =
666 static_cast<const cricket::AudioContentDescription*>(
667 content->description);
668 ASSERT_TRUE(audio_content != NULL);
669 ASSERT_EQ(0U, audio_content->cryptos().size());
670
671 content = cricket::GetFirstVideoContent(sdp);
672 ASSERT_TRUE(content != NULL);
673 const cricket::VideoContentDescription* video_content =
674 static_cast<const cricket::VideoContentDescription*>(
675 content->description);
676 ASSERT_TRUE(video_content != NULL);
677 ASSERT_EQ(0U, video_content->cryptos().size());
678
679 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700680 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700682 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 video_content->protocol());
684 } else {
685 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
686 audio_content->protocol());
687 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
688 video_content->protocol());
689 }
690 }
691
692 // Set the internal fake description factories to do DTLS-SRTP.
693 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000694 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000696 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200697 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800698 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700699 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800700 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
702 }
703
704 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
705 bool expected) {
706 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
707 ASSERT_TRUE(audio != NULL);
708 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 const TransportInfo* video = sdp->GetTransportInfoByName("video");
710 ASSERT_TRUE(video != NULL);
711 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 }
713
714 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000715 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000717 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000718 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000720 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000722 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
723 offer);
htaa2a49d92016-03-04 02:51:39 -0800724 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 // Answer should be NULL as no crypto params in offer.
726 ASSERT_TRUE(answer == NULL);
727 }
728
729 void VerifyAnswerFromCryptoOffer() {
730 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000731 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700733 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
735 ASSERT_TRUE(offer.get() != NULL);
736 VerifyCryptoParams(offer->description());
737 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700738 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 ASSERT_TRUE(answer.get() != NULL);
740 VerifyCryptoParams(answer->description());
741 }
742
deadbeef0ed85b22016-02-23 17:24:52 -0800743 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
744 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800746 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 }
748
749 const cricket::ContentInfos& contents = desc1->contents();
750 cricket::ContentInfos::const_iterator it = contents.begin();
751
752 for (; it != contents.end(); ++it) {
753 const cricket::TransportDescription* transport_desc1 =
754 desc1->GetTransportDescriptionByName(it->name);
755 const cricket::TransportDescription* transport_desc2 =
756 desc2->GetTransportDescriptionByName(it->name);
757 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800758 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
761 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800762 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 }
764 }
deadbeef0ed85b22016-02-23 17:24:52 -0800765 return true;
766 }
767
768 // Compares ufrag/password only for the specified |media_type|.
769 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
770 const cricket::SessionDescription* desc2,
771 cricket::MediaType media_type) {
772 if (desc1->contents().size() != desc2->contents().size()) {
773 return false;
774 }
775
776 const cricket::ContentInfo* cinfo =
777 cricket::GetFirstMediaContent(desc1->contents(), media_type);
778 const cricket::TransportDescription* transport_desc1 =
779 desc1->GetTransportDescriptionByName(cinfo->name);
780 const cricket::TransportDescription* transport_desc2 =
781 desc2->GetTransportDescriptionByName(cinfo->name);
782 if (!transport_desc1 || !transport_desc2) {
783 return false;
784 }
785 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
786 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
787 return false;
788 }
789 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000791
792 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
793 std::string *sdp) {
794 const cricket::SessionDescription* desc = current_desc->description();
795 EXPECT_TRUE(current_desc->ToString(sdp));
796
797 const cricket::ContentInfos& contents = desc->contents();
798 cricket::ContentInfos::const_iterator it = contents.begin();
799 // Replace ufrag and pwd lines with empty strings.
800 for (; it != contents.end(); ++it) {
801 const cricket::TransportDescription* transport_desc =
802 desc->GetTransportDescriptionByName(it->name);
803 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
804 + "\r\n";
805 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
806 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000808 "", 0,
809 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000810 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000811 "", 0,
812 sdp);
813 }
814 }
815
deadbeef0ed85b22016-02-23 17:24:52 -0800816 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
817 const std::string& ufrag,
818 const std::string& pwd) {
819 cricket::SessionDescription* desc = current_desc->description();
820 for (TransportInfo& transport_info : desc->transport_infos()) {
821 cricket::TransportDescription& transport_desc =
822 transport_info.description;
823 transport_desc.ice_ufrag = ufrag;
824 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000825 }
826 }
827
deadbeef0ed85b22016-02-23 17:24:52 -0800828 // Sets ufrag/pwd for specified |media_type|.
829 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
830 cricket::MediaType media_type,
831 const std::string& ufrag,
832 const std::string& pwd) {
833 cricket::SessionDescription* desc = current_desc->description();
834 const cricket::ContentInfo* cinfo =
835 cricket::GetFirstMediaContent(desc->contents(), media_type);
836 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
837 cricket::TransportDescription* transport_desc =
838 &transport_info->description;
839 transport_desc->ice_ufrag = ufrag;
840 transport_desc->ice_pwd = pwd;
841 }
842
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // Creates a remote offer and and applies it as a remote description,
844 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700845 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 // to decide which local and remote streams to create.
847 void CreateAndSetRemoteOfferAndLocalAnswer() {
848 SessionDescriptionInterface* offer = CreateRemoteOffer();
849 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800850 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 SetLocalDescriptionWithoutError(answer);
852 }
853 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
854 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700855 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700858 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 SetLocalDescriptionWithoutError(desc);
860 EXPECT_EQ(expected_state, session_->state());
861 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000862 void SetLocalDescriptionExpectError(const std::string& action,
863 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 SessionDescriptionInterface* desc) {
865 std::string error;
866 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000867 std::string sdp_type = "local ";
868 sdp_type.append(action);
869 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_NE(std::string::npos, error.find(expected_error));
871 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000872 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
873 SessionDescriptionInterface* desc) {
874 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
875 expected_error, desc);
876 }
877 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
878 SessionDescriptionInterface* desc) {
879 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
880 expected_error, desc);
881 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
883 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
884 }
885 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700886 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 SetRemoteDescriptionWithoutError(desc);
888 EXPECT_EQ(expected_state, session_->state());
889 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 void SetRemoteDescriptionExpectError(const std::string& action,
891 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 SessionDescriptionInterface* desc) {
893 std::string error;
894 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000895 std::string sdp_type = "remote ";
896 sdp_type.append(action);
897 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 EXPECT_NE(std::string::npos, error.find(expected_error));
899 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000900 void SetRemoteDescriptionOfferExpectError(
901 const std::string& expected_error, SessionDescriptionInterface* desc) {
902 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
903 expected_error, desc);
904 }
905 void SetRemoteDescriptionPranswerExpectError(
906 const std::string& expected_error, SessionDescriptionInterface* desc) {
907 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
908 expected_error, desc);
909 }
910 void SetRemoteDescriptionAnswerExpectError(
911 const std::string& expected_error, SessionDescriptionInterface* desc) {
912 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
913 expected_error, desc);
914 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
916 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
917 SessionDescriptionInterface** nocrypto_answer) {
918 // Create a SDP without Crypto.
919 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000920 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 options.bundle_enabled = true;
922 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
923 ASSERT_TRUE(*offer != NULL);
924 VerifyCryptoParams((*offer)->description());
925
926 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
927 cricket::SEC_DISABLED);
928 EXPECT_TRUE(*nocrypto_answer != NULL);
929 }
930
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000931 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
932 SessionDescriptionInterface** nodtls_answer) {
933 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000934 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000935 options.bundle_enabled = true;
936
kwibergd1fe2812016-04-27 06:47:29 -0700937 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000938 CreateRemoteOffer(options, cricket::SEC_ENABLED));
939
940 *nodtls_answer =
941 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
942 EXPECT_TRUE(*nodtls_answer != NULL);
943 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
944 VerifyCryptoParams((*nodtls_answer)->description());
945
946 SetFactoryDtlsSrtp();
947 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
948 ASSERT_TRUE(*offer != NULL);
949 VerifyFingerprintStatus((*offer)->description(), true);
950 VerifyCryptoParams((*offer)->description());
951 }
952
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 JsepSessionDescription* CreateRemoteOfferWithVersion(
954 cricket::MediaSessionOptions options,
955 cricket::SecurePolicy secure_policy,
956 const std::string& session_version,
957 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000958 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 const cricket::SessionDescription* cricket_desc = NULL;
960 if (current_desc) {
961 cricket_desc = current_desc->description();
962 session_id = current_desc->session_id();
963 }
964
965 desc_factory_->set_secure(secure_policy);
966 JsepSessionDescription* offer(
967 new JsepSessionDescription(JsepSessionDescription::kOffer));
968 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
969 session_id, session_version)) {
970 delete offer;
971 offer = NULL;
972 }
973 return offer;
974 }
975 JsepSessionDescription* CreateRemoteOffer(
976 cricket::MediaSessionOptions options) {
977 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
978 kSessionVersion, NULL);
979 }
980 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000981 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
982 return CreateRemoteOfferWithVersion(
983 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 }
985 JsepSessionDescription* CreateRemoteOffer(
986 cricket::MediaSessionOptions options,
987 const SessionDescriptionInterface* current_desc) {
988 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
989 kSessionVersion, current_desc);
990 }
991
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000992 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
993 const char* sctp_stream_name, int new_port,
994 cricket::MediaSessionOptions options) {
995 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000996 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
997 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000998 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
999 }
1000
1001 // Takes ownership of offer_basis (and deletes it).
1002 JsepSessionDescription* ChangeSDPSctpPort(
1003 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1004 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1005 // SessionDescription from the mutated string.
1006 const char* default_port_str = "5000";
1007 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001008 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001009 std::string offer_str;
1010 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001011 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001012 new_port_str, strlen(new_port_str),
1013 &offer_str);
1014 JsepSessionDescription* offer = new JsepSessionDescription(
1015 offer_basis->type());
1016 delete offer_basis;
1017 offer->Initialize(offer_str, NULL);
1018 return offer;
1019 }
1020
deadbeefab9b2d12015-10-14 11:33:11 -07001021 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 // before this function to decide which streams to create.
1023 JsepSessionDescription* CreateRemoteOffer() {
1024 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001025 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 return CreateRemoteOffer(options, session_->remote_description());
1027 }
1028
1029 JsepSessionDescription* CreateRemoteAnswer(
1030 const SessionDescriptionInterface* offer,
1031 cricket::MediaSessionOptions options,
1032 cricket::SecurePolicy policy) {
1033 desc_factory_->set_secure(policy);
1034 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001035 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 JsepSessionDescription* answer(
1037 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1038 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1039 options, NULL),
1040 session_id, kSessionVersion)) {
1041 delete answer;
1042 answer = NULL;
1043 }
1044 return answer;
1045 }
1046
1047 JsepSessionDescription* CreateRemoteAnswer(
1048 const SessionDescriptionInterface* offer,
1049 cricket::MediaSessionOptions options) {
1050 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1051 }
1052
deadbeefab9b2d12015-10-14 11:33:11 -07001053 // Creates an answer session description.
1054 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 // to decide which streams to create.
1056 JsepSessionDescription* CreateRemoteAnswer(
1057 const SessionDescriptionInterface* offer) {
1058 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001059 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1061 }
1062
1063 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001064 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001066 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001067
1068 PeerConnectionInterface::RTCOfferAnswerOptions options;
1069 options.use_rtp_mux = bundle;
1070
1071 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1073 // and answer.
1074 SetLocalDescriptionWithoutError(offer);
1075
kwibergd1fe2812016-04-27 06:47:29 -07001076 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001077 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 std::string sdp;
1079 EXPECT_TRUE(answer->ToString(&sdp));
1080
1081 size_t expected_candidate_num = 2;
1082 if (!rtcp_mux) {
1083 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1084 // for rtp and rtcp.
1085 expected_candidate_num = 4;
1086 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 const std::string kRtcpMux = "a=rtcp-mux";
1088 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001089 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 kXRtcpMux.c_str(), kXRtcpMux.length(),
1091 &sdp);
1092 }
1093
1094 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1095 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096
1097 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001098 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1100 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001101 if (bundle) {
1102 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1103 } else {
1104 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 }
1106 }
1107 // Tests that we can only send DTMF when the dtmf codec is supported.
1108 void TestCanInsertDtmf(bool can) {
1109 if (can) {
1110 InitWithDtmfCodec();
1111 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001112 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 }
deadbeefab9b2d12015-10-14 11:33:11 -07001114 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 CreateAndSetRemoteOfferAndLocalAnswer();
1116 EXPECT_FALSE(session_->CanInsertDtmf(""));
1117 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1118 }
1119
zhihuang3a334652016-05-05 18:37:49 -07001120 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1121 const std::string& codec_name) {
1122 for (const auto& content : desc->description()->contents()) {
1123 if (static_cast<cricket::MediaContentDescription*>(content.description)
1124 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1125 const auto* mdesc =
1126 static_cast<cricket::VideoContentDescription*>(content.description);
1127 for (const auto& codec : mdesc->codecs()) {
1128 if (codec.name == codec_name) {
1129 return true;
1130 }
1131 }
1132 }
1133 }
1134 return false;
1135 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136 // Helper class to configure loopback network and verify Best
1137 // Connection using right IP protocol for TestLoopbackCall
1138 // method. LoopbackNetworkManager applies firewall rules to block
1139 // all ping traffic once ICE completed, and remove them to observe
1140 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1141 // verifies the best connection is using the right IP protocol after
1142 // initial ICE convergences.
1143
1144 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001145 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001146 LoopbackNetworkConfiguration()
1147 : test_ipv6_network_(false),
1148 test_extra_ipv4_network_(false),
1149 best_connection_after_initial_ice_converged_(1, 0) {}
1150
1151 // Used to track the expected best connection count in each IP protocol.
1152 struct ExpectedBestConnection {
1153 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1154 : ipv4_count_(ipv4_count),
1155 ipv6_count_(ipv6_count) {}
1156
1157 int ipv4_count_;
1158 int ipv6_count_;
1159 };
1160
1161 bool test_ipv6_network_;
1162 bool test_extra_ipv4_network_;
1163 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1164
1165 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001166 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1168 }
1169
1170 private:
jbauchac8869e2015-07-03 01:36:14 -07001171 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172 const ExpectedBestConnection& expected) const {
1173 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001174 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1175 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001176 expected.ipv4_count_);
1177 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001178 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1179 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001180 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001181 // This is used in the loopback call so there is only single host to host
1182 // candidate pair.
1183 EXPECT_EQ(metrics_observer->GetEnumCounter(
1184 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1185 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001186 0);
1187 EXPECT_EQ(metrics_observer->GetEnumCounter(
1188 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1189 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001190 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001191 }
1192 };
1193
1194 class LoopbackNetworkManager {
1195 public:
1196 LoopbackNetworkManager(WebRtcSessionTest* session,
1197 const LoopbackNetworkConfiguration& config)
1198 : config_(config) {
1199 session->AddInterface(
1200 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1201 if (config_.test_extra_ipv4_network_) {
1202 session->AddInterface(
1203 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1204 }
1205 if (config_.test_ipv6_network_) {
1206 session->AddInterface(
1207 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1208 }
1209 }
1210
1211 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1212 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1213 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1214 if (config_.test_extra_ipv4_network_) {
1215 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1216 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1217 }
1218 if (config_.test_ipv6_network_) {
1219 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1220 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1221 }
1222 }
1223
1224 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1225
1226 private:
1227 LoopbackNetworkConfiguration config_;
1228 };
1229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // The method sets up a call from the session to itself, in a loopback
1231 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001232 // disconnection, and then a permanent disconnection.
1233 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1235 // While running the call, this method also checks if the session goes through
1236 // the correct sequence of ICE states when a connection is established,
1237 // broken, and re-established.
1238 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001239 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1240 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001242
stefanc1aeaf02015-10-15 07:26:07 -07001243 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001244 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001245 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001246 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247
1248 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1249 observer_.ice_gathering_state_);
1250 SetLocalDescriptionWithoutError(offer);
1251 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1252 observer_.ice_connection_state_);
1253 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001254 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1256 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001257 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258
1259 std::string sdp;
1260 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001261 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1262 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 ASSERT_TRUE(desc != NULL);
1264 SetRemoteDescriptionWithoutError(desc);
1265
1266 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001267 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001268
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001269 // The ice connection state is "Connected" too briefly to catch in a test.
1270 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001271 observer_.ice_connection_state_, kIceCandidatesTimeout);
1272 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273
stefanc1aeaf02015-10-15 07:26:07 -07001274 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1275 LoopbackNetworkManager loopback_network_manager(this, config);
1276 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001277 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 // Adding firewall rule to block ping requests, which should cause
1279 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001280
1281 loopback_network_manager.ApplyFirewallRules(fss_.get());
1282
1283 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1285 observer_.ice_connection_state_,
1286 kIceCandidatesTimeout);
1287
jbauchac8869e2015-07-03 01:36:14 -07001288 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001293 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001294 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 observer_.ice_connection_state_,
1296 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001297
1298 // Now we block ping requests and wait until the ICE connection transitions
1299 // to the Failed state. This will take at least 30 seconds because it must
1300 // wait for the Port to timeout.
1301 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001302
1303 loopback_network_manager.ApplyFirewallRules(fss_.get());
1304 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001305 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001306 observer_.ice_connection_state_,
1307 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 }
1309
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001310 void TestLoopbackCall() {
1311 LoopbackNetworkConfiguration config;
1312 TestLoopbackCall(config);
1313 }
1314
stefanc1aeaf02015-10-15 07:26:07 -07001315 void TestPacketOptions() {
1316 media_controller_.reset(
1317 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1318 LoopbackNetworkConfiguration config;
1319 LoopbackNetworkManager loopback_network_manager(this, config);
1320
1321 SetupLoopbackCall();
1322
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001323 // Wait for channel to be ready for sending.
1324 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001325 uint8_t test_packet[15] = {0};
1326 rtc::PacketOptions options;
1327 options.packet_id = 10;
1328 media_engine_->GetVideoChannel(0)
1329 ->SendRtp(test_packet, sizeof(test_packet), options);
1330
1331 const int kPacketTimeout = 2000;
1332 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1333 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1334 }
1335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1337 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001338 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1339 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001340
1341 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1343 codecs.push_back(kCNCodec1);
1344 codecs.push_back(kCNCodec2);
1345 media_engine_->SetAudioCodecs(codecs);
1346 desc_factory_->set_audio_codecs(codecs);
1347 }
1348
1349 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1350 const cricket::ContentDescription* description = content->description;
1351 ASSERT(description != NULL);
1352 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001353 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 ASSERT(audio_content_desc != NULL);
1355 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1356 if (audio_content_desc->codecs()[i].name == "CN")
1357 return false;
1358 }
1359 return true;
1360 }
1361
deadbeefab9b2d12015-10-14 11:33:11 -07001362 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001363 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001364 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001365 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1366 data_channel_ = DataChannel::Create(
1367 session_.get(), session_->data_channel_type(), "datachannel", dci);
1368 }
1369
1370 void SetLocalDescriptionWithDataChannel() {
1371 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001372 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 SetLocalDescriptionWithoutError(offer);
1374 }
1375
wu@webrtc.org91053e72013-08-10 07:18:04 +00001376 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001377 RTCCertificateGenerationMethod cert_gen_method,
1378 CreateSessionDescriptionRequest::Type type) {
1379 InitWithDtls(cert_gen_method);
1380 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1381 }
1382
1383 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1384 CreateSessionDescriptionRequest::Type type) {
1385 InitWithDtlsIdentityGenFail();
1386 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1387 }
1388
1389 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001391 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001392 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001393 if (type == CreateSessionDescriptionRequest::kAnswer) {
1394 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001395 std::unique_ptr<JsepSessionDescription> offer(
1396 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 ASSERT_TRUE(offer.get() != NULL);
1398 SetRemoteDescriptionWithoutError(offer.release());
1399 }
1400
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001401 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001402 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001403 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001404 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 observers[kNumber];
1406 for (int i = 0; i < kNumber; ++i) {
1407 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1408 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001409 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001410 } else {
htaa2a49d92016-03-04 02:51:39 -08001411 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001412 }
1413 }
1414
1415 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1416 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1417 WebRtcSessionCreateSDPObserverForTest::kFailed;
1418
1419 for (int i = 0; i < kNumber; ++i) {
1420 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1421 if (success) {
1422 EXPECT_TRUE(observers[i]->description() != NULL);
1423 } else {
1424 EXPECT_TRUE(observers[i]->description() == NULL);
1425 }
1426 }
1427 }
1428
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001429 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001430 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001431 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001432 turn_server.credentials = credentials;
1433 turn_server.ports.push_back(
1434 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1435 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001436 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001437 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001438 }
1439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 cricket::FakeMediaEngine* media_engine_;
1441 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001442 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001443 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001444 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1445 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1446 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1447 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1448 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1449 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 rtc::SocketServerScope ss_scope_;
1451 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001452 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001453 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001454 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001455 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001456 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001457 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001458 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 MockIceObserver observer_;
1460 cricket::FakeVideoMediaChannel* video_channel_;
1461 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001462 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001463 // The following flags affect options created for CreateOffer/CreateAnswer.
1464 bool send_stream_1_ = false;
1465 bool send_stream_2_ = false;
1466 bool send_audio_ = false;
1467 bool send_video_ = false;
1468 rtc::scoped_refptr<DataChannel> data_channel_;
1469 // Last values received from data channel creation signal.
1470 std::string last_data_channel_label_;
1471 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001472 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473};
1474
Henrik Boström87713d02015-08-25 09:53:21 +02001475TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1476 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 // SDES is disabled when DTLS is on.
1478 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479}
1480
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001481TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001483 // SDES is required if DTLS is off.
1484 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001485}
1486
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1488 TestSessionCandidatesWithBundleRtcpMux(false, false);
1489}
1490
1491// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1492// with rtcp-mux and/or bundle.
1493TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1494 TestSessionCandidatesWithBundleRtcpMux(false, true);
1495}
1496
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1498 TestSessionCandidatesWithBundleRtcpMux(true, true);
1499}
1500
1501TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001502 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1503 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001504 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001505 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 InitiateCall();
1507 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1508 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1509 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1510}
1511
minyuec8930ba2016-01-22 06:17:46 -08001512// Crashes on Win only. See webrtc:5411.
1513#if defined(WEBRTC_WIN)
1514#define MAYBE_TestStunError DISABLED_TestStunError
1515#else
1516#define MAYBE_TestStunError TestStunError
1517#endif
1518TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001519 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1520 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001521 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001522 rtc::FP_UDP,
1523 rtc::FD_ANY,
1524 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001525 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001526 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001528 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1530 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1531 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1532}
1533
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001534TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001535 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001536 SessionDescriptionInterface* offer = NULL;
1537 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1538 std::string unknown_action;
1539 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1540 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1541}
1542
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543// Test creating offers and receive answers and make sure the
1544// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001545TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001547 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001548 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 const std::string session_id_orig = offer->session_id();
1550 const std::string session_version_orig = offer->session_version();
1551 SetLocalDescriptionWithoutError(offer);
1552
deadbeefab9b2d12015-10-14 11:33:11 -07001553 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 SessionDescriptionInterface* answer =
1555 CreateRemoteAnswer(session_->local_description());
1556 SetRemoteDescriptionWithoutError(answer);
1557
1558 video_channel_ = media_engine_->GetVideoChannel(0);
1559 voice_channel_ = media_engine_->GetVoiceChannel(0);
1560
1561 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1562 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1563
1564 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1565 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1566
1567 ASSERT_EQ(1u, video_channel_->send_streams().size());
1568 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1569 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1570 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1571
1572 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001573 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001574 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575
1576 // Verify the session id is the same and the session version is
1577 // increased.
1578 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001579 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1580 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581
1582 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001583 EXPECT_EQ(0u, video_channel_->send_streams().size());
1584 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585
deadbeefab9b2d12015-10-14 11:33:11 -07001586 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 answer = CreateRemoteAnswer(session_->local_description());
1588 SetRemoteDescriptionWithoutError(answer);
1589
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 // Make sure the receive streams have not changed.
1591 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1592 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1593 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1594 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1595}
1596
1597// Test receiving offers and creating answers and make sure the
1598// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001600 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001601 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001602 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 SetRemoteDescriptionWithoutError(offer);
1605
deadbeefab9b2d12015-10-14 11:33:11 -07001606 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001607 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001608 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 SetLocalDescriptionWithoutError(answer);
1610
1611 const std::string session_id_orig = answer->session_id();
1612 const std::string session_version_orig = answer->session_version();
1613
1614 video_channel_ = media_engine_->GetVideoChannel(0);
1615 voice_channel_ = media_engine_->GetVoiceChannel(0);
1616
htaa2a49d92016-03-04 02:51:39 -08001617 ASSERT_TRUE(video_channel_);
1618 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1620 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1621
1622 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1623 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1624
1625 ASSERT_EQ(1u, video_channel_->send_streams().size());
1626 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1627 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1628 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1629
deadbeefab9b2d12015-10-14 11:33:11 -07001630 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001631 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 SetRemoteDescriptionWithoutError(offer);
1633
1634 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001635 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001636 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637
1638 // Verify the session id is the same and the session version is
1639 // increased.
1640 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001641 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1642 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 SetLocalDescriptionWithoutError(answer);
1644
1645 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1646 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1647 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1648 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1649 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1650 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1651
1652 // Make sure we have no send streams.
1653 EXPECT_EQ(0u, video_channel_->send_streams().size());
1654 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1655}
1656
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001658 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001659 media_engine_->set_fail_create_channel(true);
1660
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001662 ASSERT_TRUE(offer != NULL);
1663 // SetRemoteDescription and SetLocalDescription will take the ownership of
1664 // the offer.
1665 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001666 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001667 ASSERT_TRUE(offer != NULL);
1668 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1669}
1670
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671//
1672// Tests for creating/setting SDP under different SDES/DTLS polices:
1673//
1674// --DTLS off and SDES on
1675// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1676// set local/remote offer/answer with crypto --> success
1677// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1678// failure
1679// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1680// failure
1681// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1682// failure
1683//
1684// --DTLS on and SDES off
1685// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1686// set local/remote offer/answer with DTLS fingerprint --> success
1687// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1688// fingerprint --> failure
1689// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1690// --> failure
1691// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1692// --> failure
1693//
1694// --Encryption disabled: DTLS off and SDES off
1695// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1696// answer without SDES or DTLS --> success
1697// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1698// answer without SDES or DTLS --> success
1699//
1700
1701// Test that we return a failure when applying a remote/local offer that doesn't
1702// have cryptos enabled when DTLS is off.
1703TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001706 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 JsepSessionDescription* offer = CreateRemoteOffer(
1708 options, cricket::SEC_DISABLED);
1709 ASSERT_TRUE(offer != NULL);
1710 VerifyNoCryptoParams(offer->description(), false);
1711 // SetRemoteDescription and SetLocalDescription will take the ownership of
1712 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1715 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001716 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717}
1718
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001719// Test that we return a failure when applying a local answer that doesn't have
1720// cryptos enabled when DTLS is off.
1721TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001722 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 SessionDescriptionInterface* offer = NULL;
1724 SessionDescriptionInterface* answer = NULL;
1725 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1726 // SetRemoteDescription and SetLocalDescription will take the ownership of
1727 // the offer.
1728 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001729 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730}
1731
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001732// Test we will return fail when apply an remote answer that doesn't have
1733// crypto enabled when DTLS is off.
1734TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001735 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 SessionDescriptionInterface* offer = NULL;
1737 SessionDescriptionInterface* answer = NULL;
1738 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1739 // SetRemoteDescription and SetLocalDescription will take the ownership of
1740 // the offer.
1741 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743}
1744
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001745// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1746// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001747TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001748 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001749 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001750 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 SetFactoryDtlsSrtp();
1752 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001753 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 JsepSessionDescription* offer =
1755 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 ASSERT_TRUE(offer != NULL);
1757 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
1760 // SetRemoteDescription will take the ownership of the offer.
1761 SetRemoteDescriptionWithoutError(offer);
1762
1763 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001764 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 ASSERT_TRUE(answer != NULL);
1766 VerifyFingerprintStatus(answer->description(), true);
1767 // Check that we don't have an a=crypto line in the answer.
1768 VerifyNoCryptoParams(answer->description(), true);
1769
1770 // Now set the local description, which should work, even without a=crypto.
1771 SetLocalDescriptionWithoutError(answer);
1772}
1773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1775// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001776TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001777 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001778 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001779 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 SetFactoryDtlsSrtp();
1781
1782 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001783 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784 ASSERT_TRUE(offer != NULL);
1785 VerifyFingerprintStatus(offer->description(), true);
1786 // Check that we don't have an a=crypto line in the offer.
1787 VerifyNoCryptoParams(offer->description(), true);
1788
1789 // Now set the local description, which should work, even without a=crypto.
1790 SetLocalDescriptionWithoutError(offer);
1791
1792 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001793 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 JsepSessionDescription* answer =
1795 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1796 ASSERT_TRUE(answer != NULL);
1797 VerifyFingerprintStatus(answer->description(), true);
1798 VerifyNoCryptoParams(answer->description(), true);
1799
1800 // SetRemoteDescription will take the ownership of the answer.
1801 SetRemoteDescriptionWithoutError(answer);
1802}
1803
1804// Test that if we support DTLS and the other side didn't offer a fingerprint,
1805// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001806TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001807 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001808 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001810 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001811 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 JsepSessionDescription* offer = CreateRemoteOffer(
1813 options, cricket::SEC_REQUIRED);
1814 ASSERT_TRUE(offer != NULL);
1815 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818 // SetRemoteDescription will take the ownership of the offer.
1819 SetRemoteDescriptionOfferExpectError(
1820 kSdpWithoutDtlsFingerprint, offer);
1821
1822 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1823 // SetLocalDescription will take the ownership of the offer.
1824 SetLocalDescriptionOfferExpectError(
1825 kSdpWithoutDtlsFingerprint, offer);
1826}
1827
1828// Test that we return a failure when applying a local answer that doesn't have
1829// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001830TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001831 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001832 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 SessionDescriptionInterface* offer = NULL;
1834 SessionDescriptionInterface* answer = NULL;
1835 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1836
1837 // SetRemoteDescription and SetLocalDescription will take the ownership of
1838 // the offer and answer.
1839 SetRemoteDescriptionWithoutError(offer);
1840 SetLocalDescriptionAnswerExpectError(
1841 kSdpWithoutDtlsFingerprint, answer);
1842}
1843
1844// Test that we return a failure when applying a remote answer that doesn't have
1845// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001846TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001847 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001848 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001849 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001851 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001852 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001853 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001854 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001855 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856
1857 // SetRemoteDescription and SetLocalDescription will take the ownership of
1858 // the offer and answer.
1859 SetLocalDescriptionWithoutError(offer);
1860 SetRemoteDescriptionAnswerExpectError(
1861 kSdpWithoutDtlsFingerprint, answer);
1862}
1863
1864// Test that we create a local offer without SDES or DTLS and accept a remote
1865// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001866TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001867 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001869 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001870
1871 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001872 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001873 ASSERT_TRUE(offer != NULL);
1874 VerifyFingerprintStatus(offer->description(), false);
1875 // Check that we don't have an a=crypto line in the offer.
1876 VerifyNoCryptoParams(offer->description(), false);
1877
1878 // Now set the local description, which should work, even without a=crypto.
1879 SetLocalDescriptionWithoutError(offer);
1880
1881 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001882 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 JsepSessionDescription* answer =
1884 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1885 ASSERT_TRUE(answer != NULL);
1886 VerifyFingerprintStatus(answer->description(), false);
1887 VerifyNoCryptoParams(answer->description(), false);
1888
1889 // SetRemoteDescription will take the ownership of the answer.
1890 SetRemoteDescriptionWithoutError(answer);
1891}
1892
1893// Test that we create a local answer without SDES or DTLS and accept a remote
1894// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001895TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001897 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898
1899 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001900 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001901 JsepSessionDescription* offer =
1902 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1903 ASSERT_TRUE(offer != NULL);
1904 VerifyFingerprintStatus(offer->description(), false);
1905 VerifyNoCryptoParams(offer->description(), false);
1906
1907 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 SetRemoteDescriptionWithoutError(offer);
1909
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001911 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 ASSERT_TRUE(answer != NULL);
1913 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914 // Check that we don't have an a=crypto line in the answer.
1915 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 SetLocalDescriptionWithoutError(answer);
1919}
1920
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001921// Test that we can create and set an answer correctly when different
1922// SSL roles have been negotiated for different transports.
1923// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1924TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1925 SendAudioVideoStream1();
1926 InitWithDtls(GetParam());
1927 SetFactoryDtlsSrtp();
1928
1929 SessionDescriptionInterface* offer = CreateOffer();
1930 SetLocalDescriptionWithoutError(offer);
1931
1932 cricket::MediaSessionOptions options;
1933 options.recv_video = true;
1934
1935 // First, negotiate different SSL roles.
1936 SessionDescriptionInterface* answer =
1937 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1938 TransportInfo* audio_transport_info =
1939 answer->description()->GetTransportInfoByName("audio");
1940 audio_transport_info->description.connection_role =
1941 cricket::CONNECTIONROLE_ACTIVE;
1942 TransportInfo* video_transport_info =
1943 answer->description()->GetTransportInfoByName("video");
1944 video_transport_info->description.connection_role =
1945 cricket::CONNECTIONROLE_PASSIVE;
1946 SetRemoteDescriptionWithoutError(answer);
1947
1948 // Now create an offer in the reverse direction, and ensure the initial
1949 // offerer responds with an answer with correct SSL roles.
1950 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1951 kSessionVersion,
1952 session_->remote_description());
1953 SetRemoteDescriptionWithoutError(offer);
1954
htaa2a49d92016-03-04 02:51:39 -08001955 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001956 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1957 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1958 audio_transport_info->description.connection_role);
1959 video_transport_info = answer->description()->GetTransportInfoByName("video");
1960 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1961 video_transport_info->description.connection_role);
1962 SetLocalDescriptionWithoutError(answer);
1963
1964 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1965 // audio is transferred over to video in the answer that completes the BUNDLE
1966 // negotiation.
1967 options.bundle_enabled = true;
1968 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1969 kSessionVersion,
1970 session_->remote_description());
1971 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001972 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001973 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1974 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1975 audio_transport_info->description.connection_role);
1976 video_transport_info = answer->description()->GetTransportInfoByName("video");
1977 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1978 video_transport_info->description.connection_role);
1979 SetLocalDescriptionWithoutError(answer);
1980}
1981
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001983 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001984 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 SetLocalDescriptionWithoutError(offer);
1988
1989 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 SetLocalDescriptionWithoutError(offer2);
1992}
1993
1994TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 SetRemoteDescriptionWithoutError(offer);
2000
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002001 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 SetRemoteDescriptionWithoutError(offer2);
2003}
2004
2005TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002006 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002007 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002008 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002010 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002011 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2012 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013}
2014
2015TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002016 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002017 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002018 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002021 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002022 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023}
2024
2025TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002026 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002027 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002029 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
htaa2a49d92016-03-04 02:51:39 -08002031 JsepSessionDescription* pranswer =
2032 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002034 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002037 JsepSessionDescription* pranswer2 =
2038 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2040
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
deadbeefab9b2d12015-10-14 11:33:11 -07002043 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002044 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002045 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046}
2047
2048TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002049 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002052 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053
2054 JsepSessionDescription* pranswer =
2055 CreateRemoteAnswer(session_->local_description());
2056 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2057
2058 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002059 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 JsepSessionDescription* pranswer2 =
2063 CreateRemoteAnswer(session_->local_description());
2064 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2065
2066 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002067 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068
deadbeefab9b2d12015-10-14 11:33:11 -07002069 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SessionDescriptionInterface* answer =
2071 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002072 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
2075TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002078 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002079
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 SessionDescriptionInterface* answer =
2081 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002082 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2083 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002088 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002089 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 SessionDescriptionInterface* answer =
2092 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002093 SetRemoteDescriptionAnswerExpectError(
2094 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002097// Tests that the remote candidates are added and removed successfully.
2098TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002102 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2103 "", "", "host", 0, "");
2104 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2106
deadbeefd59daf82015-10-14 15:02:44 -07002107 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2109
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002110 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002112
2113 // Fail since we have not set a remote description.
2114 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2117 session_->local_description());
2118 SetRemoteDescriptionWithoutError(answer);
2119
deadbeefd59daf82015-10-14 15:02:44 -07002120 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2121 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002122 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002123 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2124 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 // Verifying the candidates are copied properly from internal vector.
2127 const SessionDescriptionInterface* remote_desc =
2128 session_->remote_description();
2129 ASSERT_TRUE(remote_desc != NULL);
2130 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2131 const IceCandidateCollection* candidates =
2132 remote_desc->candidates(kMediaContentIndex0);
2133 ASSERT_EQ(2u, candidates->count());
2134 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2135 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2136 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2137 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2138
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002139 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2140 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 candidate.set_component(2);
2142 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2143 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002144 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
2146 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2147 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002148
2149 // Remove candidate1 and candidate2
2150 std::vector<cricket::Candidate> remote_candidates;
2151 remote_candidates.push_back(ice_candidate1.candidate());
2152 remote_candidates.push_back(ice_candidate2.candidate());
2153 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2154 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155}
2156
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002157// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158// that it is retained if the remote session description is changed.
2159TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002160 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 cricket::Candidate candidate1;
2162 candidate1.set_component(1);
2163 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2164 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002165 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 CreateAndSetRemoteOfferAndLocalAnswer();
2167
2168 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2169 const SessionDescriptionInterface* remote_desc =
2170 session_->remote_description();
2171 ASSERT_TRUE(remote_desc != NULL);
2172 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2173 const IceCandidateCollection* candidates =
2174 remote_desc->candidates(kMediaContentIndex0);
2175 ASSERT_EQ(1u, candidates->count());
2176 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2177
2178 // Update the RemoteSessionDescription with a new session description and
2179 // a candidate and check that the new remote session description contains both
2180 // candidates.
2181 SessionDescriptionInterface* offer = CreateRemoteOffer();
2182 cricket::Candidate candidate2;
2183 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2184 candidate2);
2185 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2186 SetRemoteDescriptionWithoutError(offer);
2187
2188 remote_desc = session_->remote_description();
2189 ASSERT_TRUE(remote_desc != NULL);
2190 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2191 candidates = remote_desc->candidates(kMediaContentIndex0);
2192 ASSERT_EQ(2u, candidates->count());
2193 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2194 // Username and password have be updated with the TransportInfo of the
2195 // SessionDescription, won't be equal to the original one.
2196 candidate2.set_username(candidates->at(0)->candidate().username());
2197 candidate2.set_password(candidates->at(0)->candidate().password());
2198 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2199 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2200 // No need to verify the username and password.
2201 candidate1.set_username(candidates->at(1)->candidate().username());
2202 candidate1.set_password(candidates->at(1)->candidate().password());
2203 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2204
2205 // Test that the candidate is ignored if we can add the same candidate again.
2206 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2207}
2208
2209// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002210// that they are retained if the local session description is changed. And if
2211// continual gathering is enabled, they are removed from the local session
2212// description when the network is down.
2213TEST_F(WebRtcSessionTest,
2214 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002215 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002216 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002217 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 CreateAndSetRemoteOfferAndLocalAnswer();
2219
2220 const SessionDescriptionInterface* local_desc = session_->local_description();
2221 const IceCandidateCollection* candidates =
2222 local_desc->candidates(kMediaContentIndex0);
2223 ASSERT_TRUE(candidates != NULL);
2224 EXPECT_EQ(0u, candidates->count());
2225
2226 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2227
2228 local_desc = session_->local_description();
2229 candidates = local_desc->candidates(kMediaContentIndex0);
2230 ASSERT_TRUE(candidates != NULL);
2231 EXPECT_LT(0u, candidates->count());
2232 candidates = local_desc->candidates(1);
2233 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002234 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
2236 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002237 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 CreateAndSetRemoteOfferAndLocalAnswer();
2239
2240 local_desc = session_->local_description();
2241 candidates = local_desc->candidates(kMediaContentIndex0);
2242 ASSERT_TRUE(candidates != NULL);
2243 EXPECT_LT(0u, candidates->count());
2244 candidates = local_desc->candidates(1);
2245 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002246 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002247
2248 candidates = local_desc->candidates(kMediaContentIndex0);
2249 size_t num_local_candidates = candidates->count();
2250 // Enable Continual Gathering
2251 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2252 // Bring down the network interface to trigger candidate removals.
2253 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2254 // Verify that all local candidates are removed.
2255 EXPECT_EQ(0, observer_.num_candidates_removed_);
2256 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2257 kIceCandidatesTimeout);
2258 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2259}
2260
2261// Tests that if continual gathering is disabled, local candidates won't be
2262// removed when the interface is turned down.
2263TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2264 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2265 Init();
2266 SendAudioVideoStream1();
2267 CreateAndSetRemoteOfferAndLocalAnswer();
2268
2269 const SessionDescriptionInterface* local_desc = session_->local_description();
2270 const IceCandidateCollection* candidates =
2271 local_desc->candidates(kMediaContentIndex0);
2272 ASSERT_TRUE(candidates != NULL);
2273 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2274
2275 size_t num_local_candidates = candidates->count();
2276 EXPECT_LT(0u, num_local_candidates);
2277 // By default, Continual Gathering is disabled.
2278 // Bring down the network interface.
2279 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2280 // Verify that the local candidates are not removed.
2281 rtc::Thread::Current()->ProcessMessages(1000);
2282 EXPECT_EQ(0, observer_.num_candidates_removed_);
2283 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284}
2285
2286// Test that we can set a remote session description with remote candidates.
2287TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002288 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
2290 cricket::Candidate candidate1;
2291 candidate1.set_component(1);
2292 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2293 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002294 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002295 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296
2297 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2298 SetRemoteDescriptionWithoutError(offer);
2299
2300 const SessionDescriptionInterface* remote_desc =
2301 session_->remote_description();
2302 ASSERT_TRUE(remote_desc != NULL);
2303 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2304 const IceCandidateCollection* candidates =
2305 remote_desc->candidates(kMediaContentIndex0);
2306 ASSERT_EQ(1u, candidates->count());
2307 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2308
htaa2a49d92016-03-04 02:51:39 -08002309 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 SetLocalDescriptionWithoutError(answer);
2311}
2312
2313// Test that offers and answers contains ice candidates when Ice candidates have
2314// been gathered.
2315TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002316 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002317 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002318 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 // Ice is started but candidates are not provided until SetLocalDescription
2320 // is called.
2321 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2322 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2323 CreateAndSetRemoteOfferAndLocalAnswer();
2324 // Wait until at least one local candidate has been collected.
2325 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2326 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
kwibergd1fe2812016-04-27 06:47:29 -07002328 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2331 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332
2333 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2334 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002335 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2337 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 SetLocalDescriptionWithoutError(answer);
2339}
2340
2341// Verifies TransportProxy and media channels are created with content names
2342// present in the SessionDescription.
2343TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002344 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002345 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002346 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347
2348 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002349 // "video". Goal is to modify these content names and verify transport
2350 // channels
2351 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 // present in SDP.
2353 std::string sdp;
2354 EXPECT_TRUE(offer->ToString(&sdp));
2355 const std::string kAudioMid = "a=mid:audio";
2356 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2357 const std::string kVideoMid = "a=mid:video";
2358 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2359
2360 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002361 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 kAudioMidReplaceStr.c_str(),
2363 kAudioMidReplaceStr.length(),
2364 &sdp);
2365 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002366 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 kVideoMidReplaceStr.c_str(),
2368 kVideoMidReplaceStr.length(),
2369 &sdp);
2370
2371 SessionDescriptionInterface* modified_offer =
2372 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2373
2374 SetRemoteDescriptionWithoutError(modified_offer);
2375
htaa2a49d92016-03-04 02:51:39 -08002376 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 SetLocalDescriptionWithoutError(answer);
2378
deadbeefcbecd352015-09-23 11:50:27 -07002379 cricket::TransportChannel* voice_transport_channel =
2380 session_->voice_rtp_transport_channel();
2381 EXPECT_TRUE(voice_transport_channel != NULL);
2382 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2383 cricket::TransportChannel* video_transport_channel =
2384 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002385 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002386 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2388 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2389}
2390
2391// Test that an offer contains the correct media content descriptions based on
2392// the send streams when no constraints have been set.
2393TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002394 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002395 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 ASSERT_TRUE(offer != NULL);
2398 const cricket::ContentInfo* content =
2399 cricket::GetFirstAudioContent(offer->description());
2400 EXPECT_TRUE(content != NULL);
2401 content = cricket::GetFirstVideoContent(offer->description());
2402 EXPECT_TRUE(content == NULL);
2403}
2404
2405// Test that an offer contains the correct media content descriptions based on
2406// the send streams when no constraints have been set.
2407TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002408 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002410 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002411 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 const cricket::ContentInfo* content =
2414 cricket::GetFirstAudioContent(offer->description());
2415 EXPECT_TRUE(content != NULL);
2416 content = cricket::GetFirstVideoContent(offer->description());
2417 EXPECT_TRUE(content == NULL);
2418
2419 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002420 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002421 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422 content = cricket::GetFirstAudioContent(offer->description());
2423 EXPECT_TRUE(content != NULL);
2424 content = cricket::GetFirstVideoContent(offer->description());
2425 EXPECT_TRUE(content != NULL);
2426}
2427
2428// Test that an offer contains no media content descriptions if
2429// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2430TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002431 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002432 PeerConnectionInterface::RTCOfferAnswerOptions options;
2433 options.offer_to_receive_audio = 0;
2434 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435
kwibergd1fe2812016-04-27 06:47:29 -07002436 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 ASSERT_TRUE(offer != NULL);
2439 const cricket::ContentInfo* content =
2440 cricket::GetFirstAudioContent(offer->description());
2441 EXPECT_TRUE(content == NULL);
2442 content = cricket::GetFirstVideoContent(offer->description());
2443 EXPECT_TRUE(content == NULL);
2444}
2445
2446// Test that an offer contains only audio media content descriptions if
2447// kOfferToReceiveAudio constraints are set to true.
2448TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002449 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002450 PeerConnectionInterface::RTCOfferAnswerOptions options;
2451 options.offer_to_receive_audio =
2452 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2453
kwibergd1fe2812016-04-27 06:47:29 -07002454 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455
2456 const cricket::ContentInfo* content =
2457 cricket::GetFirstAudioContent(offer->description());
2458 EXPECT_TRUE(content != NULL);
2459 content = cricket::GetFirstVideoContent(offer->description());
2460 EXPECT_TRUE(content == NULL);
2461}
2462
2463// Test that an offer contains audio and video media content descriptions if
2464// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2465TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002466 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468 PeerConnectionInterface::RTCOfferAnswerOptions options;
2469 options.offer_to_receive_audio =
2470 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2471 options.offer_to_receive_video =
2472 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2473
kwibergd1fe2812016-04-27 06:47:29 -07002474 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 const cricket::ContentInfo* content =
2477 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002478 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 content = cricket::GetFirstVideoContent(offer->description());
2481 EXPECT_TRUE(content != NULL);
2482
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002483 // Sets constraints to false and verifies that audio/video contents are
2484 // removed.
2485 options.offer_to_receive_audio = 0;
2486 options.offer_to_receive_video = 0;
2487 offer.reset(CreateOffer(options));
2488
2489 content = cricket::GetFirstAudioContent(offer->description());
2490 EXPECT_TRUE(content == NULL);
2491 content = cricket::GetFirstVideoContent(offer->description());
2492 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493}
2494
2495// Test that an answer can not be created if the last remote description is not
2496// an offer.
2497TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002498 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002499 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 SetLocalDescriptionWithoutError(offer);
2501 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2502 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002503 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504}
2505
2506// Test that an answer contains the correct media content descriptions when no
2507// constraints have been set.
2508TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002509 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002511 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002513 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 const cricket::ContentInfo* content =
2515 cricket::GetFirstAudioContent(answer->description());
2516 ASSERT_TRUE(content != NULL);
2517 EXPECT_FALSE(content->rejected);
2518
2519 content = cricket::GetFirstVideoContent(answer->description());
2520 ASSERT_TRUE(content != NULL);
2521 EXPECT_FALSE(content->rejected);
2522}
2523
2524// Test that an answer contains the correct media content descriptions when no
2525// constraints have been set and the offer only contain audio.
2526TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002527 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 // Create a remote offer with audio only.
2529 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002530
kwibergd1fe2812016-04-27 06:47:29 -07002531 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2533 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2534
2535 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002536 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 const cricket::ContentInfo* content =
2538 cricket::GetFirstAudioContent(answer->description());
2539 ASSERT_TRUE(content != NULL);
2540 EXPECT_FALSE(content->rejected);
2541
2542 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2543}
2544
2545// Test that an answer contains the correct media content descriptions when no
2546// constraints have been set.
2547TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002548 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002550 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 SetRemoteDescriptionWithoutError(offer.release());
2552 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002553 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002554 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 const cricket::ContentInfo* content =
2556 cricket::GetFirstAudioContent(answer->description());
2557 ASSERT_TRUE(content != NULL);
2558 EXPECT_FALSE(content->rejected);
2559
2560 content = cricket::GetFirstVideoContent(answer->description());
2561 ASSERT_TRUE(content != NULL);
2562 EXPECT_FALSE(content->rejected);
2563}
2564
2565// Test that an answer contains the correct media content descriptions when
2566// constraints have been set but no stream is sent.
2567TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002568 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002570 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 SetRemoteDescriptionWithoutError(offer.release());
2572
htaa2a49d92016-03-04 02:51:39 -08002573 cricket::MediaSessionOptions session_options;
2574 session_options.recv_audio = false;
2575 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002576 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002577 CreateAnswer(session_options));
2578
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 const cricket::ContentInfo* content =
2580 cricket::GetFirstAudioContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_TRUE(content->rejected);
2583
2584 content = cricket::GetFirstVideoContent(answer->description());
2585 ASSERT_TRUE(content != NULL);
2586 EXPECT_TRUE(content->rejected);
2587}
2588
2589// Test that an answer contains the correct media content descriptions when
2590// constraints have been set and streams are sent.
2591TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002592 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002594 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595 SetRemoteDescriptionWithoutError(offer.release());
2596
htaa2a49d92016-03-04 02:51:39 -08002597 cricket::MediaSessionOptions options;
2598 options.recv_audio = false;
2599 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600
2601 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002602 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002603 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604
2605 // TODO(perkj): Should the direction be set to SEND_ONLY?
2606 const cricket::ContentInfo* content =
2607 cricket::GetFirstAudioContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_FALSE(content->rejected);
2610
2611 // TODO(perkj): Should the direction be set to SEND_ONLY?
2612 content = cricket::GetFirstVideoContent(answer->description());
2613 ASSERT_TRUE(content != NULL);
2614 EXPECT_FALSE(content->rejected);
2615}
2616
2617TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2618 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002619 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002620 PeerConnectionInterface::RTCOfferAnswerOptions options;
2621 options.offer_to_receive_audio =
2622 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2623 options.voice_activity_detection = false;
2624
kwibergd1fe2812016-04-27 06:47:29 -07002625 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002626
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 const cricket::ContentInfo* content =
2628 cricket::GetFirstAudioContent(offer->description());
2629 EXPECT_TRUE(content != NULL);
2630 EXPECT_TRUE(VerifyNoCNCodecs(content));
2631}
2632
2633TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2634 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002635 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002637 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 SetRemoteDescriptionWithoutError(offer.release());
2639
htaa2a49d92016-03-04 02:51:39 -08002640 cricket::MediaSessionOptions options;
2641 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002642 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 const cricket::ContentInfo* content =
2644 cricket::GetFirstAudioContent(answer->description());
2645 ASSERT_TRUE(content != NULL);
2646 EXPECT_TRUE(VerifyNoCNCodecs(content));
2647}
2648
2649// This test verifies the call setup when remote answer with audio only and
2650// later updates with video.
2651TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002652 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2654 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2655
deadbeefab9b2d12015-10-14 11:33:11 -07002656 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002657 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658
2659 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2661
2662 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2663 // and answer;
2664 SetLocalDescriptionWithoutError(offer);
2665 SetRemoteDescriptionWithoutError(answer);
2666
2667 video_channel_ = media_engine_->GetVideoChannel(0);
2668 voice_channel_ = media_engine_->GetVoiceChannel(0);
2669
2670 ASSERT_TRUE(video_channel_ == NULL);
2671
2672 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2673 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2674 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2675
2676 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002677 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678 CreateAndSetRemoteOfferAndLocalAnswer();
2679
2680 video_channel_ = media_engine_->GetVideoChannel(0);
2681 voice_channel_ = media_engine_->GetVoiceChannel(0);
2682
2683 ASSERT_TRUE(video_channel_ != NULL);
2684 ASSERT_TRUE(voice_channel_ != NULL);
2685
2686 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2687 ASSERT_EQ(1u, video_channel_->send_streams().size());
2688 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2689 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2690 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2691 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2692 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2694
2695 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002696 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697 CreateAndSetRemoteOfferAndLocalAnswer();
2698
2699 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2700 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2701 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2702 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2703 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2704}
2705
2706// This test verifies the call setup when remote answer with video only and
2707// later updates with audio.
2708TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002709 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2711 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002712 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002713 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714
2715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002716 options.recv_audio = false;
2717 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2719 offer, options, cricket::SEC_ENABLED);
2720
2721 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2722 // and answer.
2723 SetLocalDescriptionWithoutError(offer);
2724 SetRemoteDescriptionWithoutError(answer);
2725
2726 video_channel_ = media_engine_->GetVideoChannel(0);
2727 voice_channel_ = media_engine_->GetVoiceChannel(0);
2728
2729 ASSERT_TRUE(voice_channel_ == NULL);
2730 ASSERT_TRUE(video_channel_ != NULL);
2731
2732 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2733 ASSERT_EQ(1u, video_channel_->send_streams().size());
2734 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2735
2736 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002737 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 CreateAndSetRemoteOfferAndLocalAnswer();
2739
2740 voice_channel_ = media_engine_->GetVoiceChannel(0);
2741 ASSERT_TRUE(voice_channel_ != NULL);
2742
2743 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2744 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2745 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2746 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2747
2748 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 CreateAndSetRemoteOfferAndLocalAnswer();
2751
2752 video_channel_ = media_engine_->GetVideoChannel(0);
2753 voice_channel_ = media_engine_->GetVoiceChannel(0);
2754
2755 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2756 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2757 ASSERT_EQ(1u, video_channel_->send_streams().size());
2758 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2759}
2760
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002762 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002763 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002764 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 VerifyCryptoParams(offer->description());
2766 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002767 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 VerifyCryptoParams(answer->description());
2769}
2770
2771TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002772 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002773 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002774 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002775 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyNoCryptoParams(offer->description(), false);
2777}
2778
2779TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 VerifyAnswerFromNonCryptoOffer();
2782}
2783
2784TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 VerifyAnswerFromCryptoOffer();
2787}
2788
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002789// This test verifies that setLocalDescription fails if
2790// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2791TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002792 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002793 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002794 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002795
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002796 std::string sdp;
2797 RemoveIceUfragPwdLines(offer.get(), &sdp);
2798 SessionDescriptionInterface* modified_offer =
2799 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002800 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002801}
2802
2803// This test verifies that setRemoteDescription fails if
2804// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2805TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002806 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002807 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002808 std::string sdp;
2809 RemoveIceUfragPwdLines(offer.get(), &sdp);
2810 SessionDescriptionInterface* modified_offer =
2811 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002812 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002813}
2814
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002815// This test verifies that setLocalDescription fails if local offer has
2816// too short ice ufrag and pwd strings.
2817TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002818 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002819 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002820 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002821 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2822 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002823 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002824 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002825 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002826
2827 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002828 offer.reset(CreateOffer());
2829 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2830 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002831}
2832
2833// This test verifies that setRemoteDescription fails if remote offer has
2834// too short ice ufrag and pwd strings.
2835TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002836 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002837 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002838 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2839 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002840 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002841 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002842 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002843
deadbeef0ed85b22016-02-23 17:24:52 -08002844 offer.reset(CreateRemoteOffer());
2845 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2846 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002847}
2848
Honghai Zhang04e91462015-12-11 14:26:22 -08002849// Test that if the remote offer indicates the peer requested ICE restart (via
2850// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2851TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002852 Init();
honghaiz503726c2015-07-31 12:37:38 -07002853
2854 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002855 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002856 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002857 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2858 0, "", "", "relay", 0, "");
2859 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2860 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002861 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2862 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002863 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2864
2865 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002866 offer.reset(CreateRemoteOffer());
2867 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002868 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2869 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2870 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002871 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2872 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002873 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2874
2875 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002876 offer.reset(CreateRemoteOffer());
2877 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002878 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2879 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2880 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002881 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2882 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002883 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2884
2885 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002886 offer.reset(CreateRemoteOffer());
2887 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2888 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002889 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2890}
2891
Honghai Zhang04e91462015-12-11 14:26:22 -08002892// Test that if the remote answer indicates the peer requested ICE restart (via
2893// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2894TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2895 Init();
2896 SessionDescriptionInterface* offer = CreateOffer();
2897 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002898
2899 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002900 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002901 answer->set_type(JsepSessionDescription::kPrAnswer);
2902 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002903 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2904 0, "", "", "relay", 0, "");
2905 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2906 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002907 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2908 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002909 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2910
2911 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002912 answer.reset(CreateRemoteAnswer(offer));
2913 answer->set_type(JsepSessionDescription::kPrAnswer);
2914 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002915 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2916 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2917 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002918 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2919 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002920 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2921
2922 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002923 answer.reset(CreateRemoteAnswer(offer));
2924 answer->set_type(JsepSessionDescription::kPrAnswer);
2925 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002926 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2927 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2928 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002929 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2930 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002931 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2932
2933 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002934 answer.reset(CreateRemoteAnswer(offer));
2935 answer->set_type(JsepSessionDescription::kPrAnswer);
2936 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2937 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002938 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2939}
2940
Donald Curtisd4f769d2015-05-28 09:48:21 -07002941// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002942// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002943TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2944 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2945
2946 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002947 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002948
2949 PeerConnectionInterface::RTCOfferAnswerOptions options;
2950 options.use_rtp_mux = true;
2951
2952 SessionDescriptionInterface* offer = CreateRemoteOffer();
2953 SetRemoteDescriptionWithoutError(offer);
2954
htaa2a49d92016-03-04 02:51:39 -08002955 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002956 SetLocalDescriptionWithoutError(answer);
2957
deadbeefcbecd352015-09-23 11:50:27 -07002958 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2959 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002960
deadbeefcbecd352015-09-23 11:50:27 -07002961 cricket::BaseChannel* voice_channel = session_->voice_channel();
2962 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002963
2964 // Checks if one of the transport channels contains a connection using a given
2965 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002966 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002967 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002968 session_->GetChannelTransportStats(voice_channel, &stats);
2969 for (auto& kv : stats.transport_stats) {
2970 for (auto& chan_stat : kv.second.channel_stats) {
2971 for (auto& conn_info : chan_stat.connection_infos) {
2972 if (conn_info.remote_candidate.address().port() == port) {
2973 return true;
2974 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002975 }
2976 }
2977 }
2978 return false;
2979 };
2980
2981 EXPECT_FALSE(connection_with_remote_port(5000));
2982 EXPECT_FALSE(connection_with_remote_port(5001));
2983 EXPECT_FALSE(connection_with_remote_port(6000));
2984
2985 // The way the *_WAIT checks work is they only wait if the condition fails,
2986 // which does not help in the case where state is not changing. This is
2987 // problematic in this test since we want to verify that adding a video
2988 // candidate does _not_ change state. So we interleave candidates and assume
2989 // that messages are executed in the order they were posted.
2990
2991 // First audio candidate.
2992 cricket::Candidate candidate0;
2993 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2994 candidate0.set_component(1);
2995 candidate0.set_protocol("udp");
2996 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2997 candidate0);
2998 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2999
3000 // Video candidate.
3001 cricket::Candidate candidate1;
3002 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3003 candidate1.set_component(1);
3004 candidate1.set_protocol("udp");
3005 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3006 candidate1);
3007 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3008
3009 // Second audio candidate.
3010 cricket::Candidate candidate2;
3011 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3012 candidate2.set_component(1);
3013 candidate2.set_protocol("udp");
3014 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3015 candidate2);
3016 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3017
3018 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3019 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3020
3021 // No need here for a _WAIT check since we are checking that state hasn't
3022 // changed: if this is false we would be doing waits for nothing and if this
3023 // is true then there will be no messages processed anyways.
3024 EXPECT_FALSE(connection_with_remote_port(6000));
3025}
3026
deadbeefcbecd352015-09-23 11:50:27 -07003027// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003028TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3029 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003030 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003031
3032 PeerConnectionInterface::RTCOfferAnswerOptions options;
3033 options.use_rtp_mux = true;
3034
3035 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003036 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003037
deadbeefcbecd352015-09-23 11:50:27 -07003038 EXPECT_NE(session_->voice_rtp_transport_channel(),
3039 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003040
deadbeefab9b2d12015-10-14 11:33:11 -07003041 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003042 SessionDescriptionInterface* answer =
3043 CreateRemoteAnswer(session_->local_description());
3044 SetRemoteDescriptionWithoutError(answer);
3045
deadbeefcbecd352015-09-23 11:50:27 -07003046 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3047 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003048}
3049
deadbeefcbecd352015-09-23 11:50:27 -07003050// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003051TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3052 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003053 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003054
Donald Curtis0e209b02015-03-24 09:29:54 -07003055 PeerConnectionInterface::RTCOfferAnswerOptions options;
3056 options.use_rtp_mux = true;
3057
3058 SessionDescriptionInterface* offer = CreateOffer(options);
3059 SetLocalDescriptionWithoutError(offer);
3060
deadbeefcbecd352015-09-23 11:50:27 -07003061 EXPECT_NE(session_->voice_rtp_transport_channel(),
3062 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003063
deadbeefab9b2d12015-10-14 11:33:11 -07003064 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003065
3066 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003067 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003068 CreateRemoteAnswer(session_->local_description()));
3069 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3070 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3071 JsepSessionDescription* modified_answer =
3072 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3073 modified_answer->Initialize(answer_copy, "1", "1");
3074 SetRemoteDescriptionWithoutError(modified_answer); //
3075
deadbeefcbecd352015-09-23 11:50:27 -07003076 EXPECT_NE(session_->voice_rtp_transport_channel(),
3077 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003078}
3079
3080// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3081TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3082 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003083 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003084
3085 PeerConnectionInterface::RTCOfferAnswerOptions options;
3086 options.use_rtp_mux = true;
3087
3088 SessionDescriptionInterface* offer = CreateOffer(options);
3089 SetLocalDescriptionWithoutError(offer);
3090
deadbeefcbecd352015-09-23 11:50:27 -07003091 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3092 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003093
deadbeefab9b2d12015-10-14 11:33:11 -07003094 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003095 SessionDescriptionInterface* answer =
3096 CreateRemoteAnswer(session_->local_description());
3097 SetRemoteDescriptionWithoutError(answer);
3098
deadbeefcbecd352015-09-23 11:50:27 -07003099 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3100 session_->video_rtp_transport_channel());
3101}
3102
3103// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3104// audio content in the answer.
3105TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3106 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003107 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003108
3109 PeerConnectionInterface::RTCOfferAnswerOptions options;
3110 options.use_rtp_mux = true;
3111
3112 SessionDescriptionInterface* offer = CreateOffer(options);
3113 SetLocalDescriptionWithoutError(offer);
3114
3115 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3116 session_->video_rtp_transport_channel());
3117
deadbeefab9b2d12015-10-14 11:33:11 -07003118 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003119 cricket::MediaSessionOptions recv_options;
3120 recv_options.recv_audio = false;
3121 recv_options.recv_video = true;
3122 SessionDescriptionInterface* answer =
3123 CreateRemoteAnswer(session_->local_description(), recv_options);
3124 SetRemoteDescriptionWithoutError(answer);
3125
deadbeefd59daf82015-10-14 15:02:44 -07003126 EXPECT_TRUE(nullptr == session_->voice_channel());
3127 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003128
deadbeefd59daf82015-10-14 15:02:44 -07003129 session_->Close();
3130 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3131 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3132 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3133 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003134}
3135
3136// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3137TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3138 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003139 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003140
Donald Curtis0e209b02015-03-24 09:29:54 -07003141 PeerConnectionInterface::RTCOfferAnswerOptions options;
3142 options.use_rtp_mux = true;
3143
3144 SessionDescriptionInterface* offer = CreateOffer(options);
3145 SetLocalDescriptionWithoutError(offer);
3146
deadbeefcbecd352015-09-23 11:50:27 -07003147 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3148 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003149
deadbeefab9b2d12015-10-14 11:33:11 -07003150 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003151
3152 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003153 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003154 CreateRemoteAnswer(session_->local_description()));
3155 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3156 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3157 JsepSessionDescription* modified_answer =
3158 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3159 modified_answer->Initialize(answer_copy, "1", "1");
3160 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161
deadbeefcbecd352015-09-23 11:50:27 -07003162 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3163 session_->video_rtp_transport_channel());
3164}
3165
3166// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3167TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3168 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003169 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003170
3171 SessionDescriptionInterface* offer = CreateRemoteOffer();
3172 SetRemoteDescriptionWithoutError(offer);
3173
3174 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3175 session_->video_rtp_transport_channel());
3176
deadbeefab9b2d12015-10-14 11:33:11 -07003177 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003178 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003179 SetLocalDescriptionWithoutError(answer);
3180
3181 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3182 session_->video_rtp_transport_channel());
3183}
3184
3185// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3186TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3187 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003189
3190 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003191 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003192 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3193 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3194 JsepSessionDescription* modified_offer =
3195 new JsepSessionDescription(JsepSessionDescription::kOffer);
3196 modified_offer->Initialize(offer_copy, "1", "1");
3197
3198 // Expect an error when applying the remote description
3199 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3200 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003201}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
Peter Thatcher4eddf182015-04-30 10:55:59 -07003203// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003204TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3205 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003206 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207
Donald Curtis0e209b02015-03-24 09:29:54 -07003208 PeerConnectionInterface::RTCOfferAnswerOptions options;
3209 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210
Donald Curtis0e209b02015-03-24 09:29:54 -07003211 SessionDescriptionInterface* offer = CreateOffer(options);
3212 SetLocalDescriptionWithoutError(offer);
3213
deadbeefcbecd352015-09-23 11:50:27 -07003214 EXPECT_NE(session_->voice_rtp_transport_channel(),
3215 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003216
deadbeefab9b2d12015-10-14 11:33:11 -07003217 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003218 SessionDescriptionInterface* answer =
3219 CreateRemoteAnswer(session_->local_description());
3220 SetRemoteDescriptionWithoutError(answer);
3221
3222 // This should lead to an audio-only call but isn't implemented
3223 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003224 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3225 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003226}
3227
deadbeefcbecd352015-09-23 11:50:27 -07003228// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003229TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3230 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003231 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003232 PeerConnectionInterface::RTCOfferAnswerOptions options;
3233 options.use_rtp_mux = true;
3234
3235 SessionDescriptionInterface* offer = CreateOffer(options);
3236 SetLocalDescriptionWithoutError(offer);
3237
deadbeefcbecd352015-09-23 11:50:27 -07003238 EXPECT_NE(session_->voice_rtp_transport_channel(),
3239 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003240
deadbeefab9b2d12015-10-14 11:33:11 -07003241 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003242
3243 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003244 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003245 CreateRemoteAnswer(session_->local_description()));
3246 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3247 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3248 JsepSessionDescription* modified_answer =
3249 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3250 modified_answer->Initialize(answer_copy, "1", "1");
3251 SetRemoteDescriptionWithoutError(modified_answer); //
3252
deadbeefcbecd352015-09-23 11:50:27 -07003253 EXPECT_NE(session_->voice_rtp_transport_channel(),
3254 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255}
3256
Peter Thatcher4eddf182015-04-30 10:55:59 -07003257// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3258TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3259 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003260 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003261
3262 PeerConnectionInterface::RTCOfferAnswerOptions options;
3263 options.use_rtp_mux = true;
3264
3265 SessionDescriptionInterface* offer = CreateOffer(options);
3266 SetRemoteDescriptionWithoutError(offer);
3267
deadbeefcbecd352015-09-23 11:50:27 -07003268 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3269 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003270}
3271
skvlad6c87a672016-05-17 17:49:52 -07003272// Adding a new channel to a BUNDLE which is already connected should directly
3273// assign the bundle transport to the channel, without first setting a
3274// disconnected non-bundle transport and then replacing it. The application
3275// should not receive any changes in the ICE state.
3276TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3277 LoopbackNetworkConfiguration config;
3278 LoopbackNetworkManager loopback_network_manager(this, config);
3279 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3280 // connected. Disabling either of these two means that we need to wait for the
3281 // answer to find out if more transports are needed.
3282 configuration_.bundle_policy =
3283 PeerConnectionInterface::kBundlePolicyMaxBundle;
3284 configuration_.rtcp_mux_policy =
3285 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3286 options_.disable_encryption = true;
3287 Init();
3288
3289 // Negotiate an audio channel with MAX_BUNDLE enabled.
3290 SendAudioOnlyStream2();
3291 SessionDescriptionInterface* offer = CreateOffer();
3292 SetLocalDescriptionWithoutError(offer);
3293 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3294 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3295 std::string sdp;
3296 offer->ToString(&sdp);
3297 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3298 JsepSessionDescription::kAnswer, sdp, nullptr);
3299 ASSERT_TRUE(answer != NULL);
3300 SetRemoteDescriptionWithoutError(answer);
3301
3302 // Wait for the ICE state to stabilize.
3303 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3304 observer_.ice_connection_state_, kIceCandidatesTimeout);
3305 observer_.ice_connection_state_history_.clear();
3306
3307 // Now add a video channel which should be using the same bundle transport.
3308 SendAudioVideoStream2();
3309 offer = CreateOffer();
3310 offer->ToString(&sdp);
3311 SetLocalDescriptionWithoutError(offer);
3312 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3313 sdp, nullptr);
3314 ASSERT_TRUE(answer != NULL);
3315 SetRemoteDescriptionWithoutError(answer);
3316
3317 // Wait for ICE state to stabilize
3318 rtc::Thread::Current()->ProcessMessages(0);
3319 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3320 observer_.ice_connection_state_, kIceCandidatesTimeout);
3321
3322 // No ICE state changes are expected to happen.
3323 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3324}
3325
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003326TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3327 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003328 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003329
3330 PeerConnectionInterface::RTCOfferAnswerOptions options;
3331 SessionDescriptionInterface* offer = CreateOffer(options);
3332 SetLocalDescriptionWithoutError(offer);
3333
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3335 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003336
deadbeefab9b2d12015-10-14 11:33:11 -07003337 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003338 SessionDescriptionInterface* answer =
3339 CreateRemoteAnswer(session_->local_description());
3340 SetRemoteDescriptionWithoutError(answer);
3341
deadbeefcbecd352015-09-23 11:50:27 -07003342 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3343 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003344}
3345
3346TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3347 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003348 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003349
3350 PeerConnectionInterface::RTCOfferAnswerOptions options;
3351 SessionDescriptionInterface* offer = CreateOffer(options);
3352 SetLocalDescriptionWithoutError(offer);
3353
deadbeefcbecd352015-09-23 11:50:27 -07003354 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3355 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003356
deadbeefab9b2d12015-10-14 11:33:11 -07003357 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003358 SessionDescriptionInterface* answer =
3359 CreateRemoteAnswer(session_->local_description());
3360 SetRemoteDescriptionWithoutError(answer);
3361
deadbeefcbecd352015-09-23 11:50:27 -07003362 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3363 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003364}
3365
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003366// This test verifies that SetLocalDescription and SetRemoteDescription fails
3367// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3368TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003369 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003370 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003371
3372 PeerConnectionInterface::RTCOfferAnswerOptions options;
3373 options.use_rtp_mux = true;
3374
3375 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003376 std::string offer_str;
3377 offer->ToString(&offer_str);
3378 // Disable rtcp-mux
3379 const std::string rtcp_mux = "rtcp-mux";
3380 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003381 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003382 xrtcp_mux.c_str(), xrtcp_mux.length(),
3383 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003384 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003385 new JsepSessionDescription(JsepSessionDescription::kOffer);
3386 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003387 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003388 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003389 new JsepSessionDescription(JsepSessionDescription::kOffer);
3390 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003391 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003392 // Trying unmodified SDP.
3393 SetLocalDescriptionWithoutError(offer);
3394}
3395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003397 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003398 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 CreateAndSetRemoteOfferAndLocalAnswer();
3400 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3401 ASSERT_TRUE(channel != NULL);
3402 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003403 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003404 double volume;
3405 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3406 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003407 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003408 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3409 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003410 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003411 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3412 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413}
3414
skvlade0d46372016-04-07 22:59:22 -07003415TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003416 Init();
3417 SendAudioVideoStream1();
3418 CreateAndSetRemoteOfferAndLocalAnswer();
3419 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3420 ASSERT_TRUE(channel != NULL);
3421 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003422 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003423 webrtc::RtpParameters params = session_->GetAudioRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003424 EXPECT_EQ(1, params.encodings.size());
3425 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3426 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003427 EXPECT_TRUE(session_->SetAudioRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003428
skvlade0d46372016-04-07 22:59:22 -07003429 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003430 params = session_->GetAudioRtpSendParameters(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 audio channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003435 params = channel->GetRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003436 EXPECT_EQ(1, params.encodings.size());
3437 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3438
3439 // Verify that the global bitrate limit has not been changed.
3440 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003441}
3442
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003444 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003445 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 CreateAndSetRemoteOfferAndLocalAnswer();
3447 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3448 ASSERT_TRUE(channel != NULL);
3449 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003450 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3452
3453 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003454 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455
kwibergd1fe2812016-04-27 06:47:29 -07003456 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003457 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003459 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003460 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003462 // This will trigger SetSink(nullptr) to the |source|.
3463 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003465 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003466 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003467}
3468
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003469TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003470 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003471 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003472 CreateAndSetRemoteOfferAndLocalAnswer();
3473 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3474 ASSERT_TRUE(channel != NULL);
3475 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003476 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003477
kwibergd1fe2812016-04-27 06:47:29 -07003478 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003479 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003480 session_->SetAudioSend(send_ssrc, true, options, source.get());
3481 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003482
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003483 // Delete the |source| and it will trigger OnClose() to the sink, and this
3484 // will invalidate the |source_| pointer in the sink and prevent getting a
3485 // SetSink(nullptr) callback afterwards.
3486 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003487
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003488 // This will trigger SetSink(nullptr) if no OnClose() callback.
3489 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490}
3491
3492TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003493 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003494 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 CreateAndSetRemoteOfferAndLocalAnswer();
3496 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3497 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003498 ASSERT_LT(0u, channel->sinks().size());
3499 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003501 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502 cricket::FakeVideoRenderer renderer;
3503 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003504 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003506 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507}
3508
skvladdc1c62c2016-03-16 19:07:43 -07003509TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3510 Init();
3511 SendAudioVideoStream1();
3512 CreateAndSetRemoteOfferAndLocalAnswer();
3513 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3514 ASSERT_TRUE(channel != NULL);
3515 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3516 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003517 webrtc::RtpParameters params = session_->GetVideoRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003518 EXPECT_EQ(1, params.encodings.size());
3519 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3520 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003521 EXPECT_TRUE(session_->SetVideoRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003522
3523 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003524 params = session_->GetVideoRtpSendParameters(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 video channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003529 params = channel->GetRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003530 EXPECT_EQ(1, params.encodings.size());
3531 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3532
3533 // Verify that the global bitrate limit has not been changed.
3534 EXPECT_EQ(-1, channel->max_bps());
3535}
3536
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003538 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003539 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 CreateAndSetRemoteOfferAndLocalAnswer();
3541 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3542 ASSERT_TRUE(channel != NULL);
3543 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003544 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3546 cricket::VideoOptions* options = NULL;
3547 session_->SetVideoSend(send_ssrc, false, options);
3548 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3549 session_->SetVideoSend(send_ssrc, true, options);
3550 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3551}
3552
3553TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3554 TestCanInsertDtmf(false);
3555}
3556
3557TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3558 TestCanInsertDtmf(true);
3559}
3560
3561TEST_F(WebRtcSessionTest, InsertDtmf) {
3562 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003563 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003564 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565 CreateAndSetRemoteOfferAndLocalAnswer();
3566 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3567 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3568
3569 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 const int expected_duration = 90;
3571 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3572 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3573 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3574
3575 // Verify
3576 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003577 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003579 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003581 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003583 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584}
3585
deadbeefd59daf82015-10-14 15:02:44 -07003586// This test verifies the |initial_offerer| flag when session initiates the
3587// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003590 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003591 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3593 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003594 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003596 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597}
3598
deadbeefd59daf82015-10-14 15:02:44 -07003599// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003601 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003602 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 SessionDescriptionInterface* offer = CreateRemoteOffer();
3604 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003605 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606
deadbeefd59daf82015-10-14 15:02:44 -07003607 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003609 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610}
3611
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3613TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003614 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003615 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003616 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003618 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619 CreateRemoteAnswer(session_->local_description()));
3620
3621 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3622 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003623 JsepSessionDescription* modified_answer =
3624 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625
3626 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3627 answer->session_id(),
3628 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003629 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630
wu@webrtc.org4e393072014-04-07 17:04:35 +00003631 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 std::string sdp;
3633 EXPECT_TRUE(answer->ToString(&sdp));
3634 const std::string kAudioMid = "a=mid:audio";
3635 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003636 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637 kAudioMidReplaceStr.c_str(),
3638 kAudioMidReplaceStr.length(),
3639 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003640 SessionDescriptionInterface* modified_answer1 =
3641 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003642 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643
wu@webrtc.org4e393072014-04-07 17:04:35 +00003644 // Different media types.
3645 EXPECT_TRUE(answer->ToString(&sdp));
3646 const std::string kAudioMline = "m=audio";
3647 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003648 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003649 kAudioMlineReplaceStr.c_str(),
3650 kAudioMlineReplaceStr.length(),
3651 &sdp);
3652 SessionDescriptionInterface* modified_answer2 =
3653 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3654 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3655
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003656 SetRemoteDescriptionWithoutError(answer.release());
3657}
3658
3659// Verifying remote offer and local answer have matching m-lines as per
3660// RFC 3264.
3661TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003662 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003663 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003664 SessionDescriptionInterface* offer = CreateRemoteOffer();
3665 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003666 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
3668 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3669 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003670 JsepSessionDescription* modified_answer =
3671 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672
3673 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3674 answer->session_id(),
3675 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003676 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677 SetLocalDescriptionWithoutError(answer);
3678}
3679
3680// This test verifies that WebRtcSession does not start candidate allocation
3681// before SetLocalDescription is called.
3682TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003683 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003684 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003685 SessionDescriptionInterface* offer = CreateRemoteOffer();
3686 cricket::Candidate candidate;
3687 candidate.set_component(1);
3688 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3689 candidate);
3690 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3691 cricket::Candidate candidate1;
3692 candidate1.set_component(1);
3693 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3694 candidate1);
3695 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3696 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003697 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3698 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003699
3700 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003701 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003702 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3703 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3704
htaa2a49d92016-03-04 02:51:39 -08003705 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003707 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3708}
3709
3710// This test verifies that crypto parameter is updated in local session
3711// description as per security policy set in MediaSessionDescriptionFactory.
3712TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003713 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003714 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003715 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716
3717 // Making sure SetLocalDescription correctly sets crypto value in
3718 // SessionDescription object after de-serialization of sdp string. The value
3719 // will be set as per MediaSessionDescriptionFactory.
3720 std::string offer_str;
3721 offer->ToString(&offer_str);
3722 SessionDescriptionInterface* jsep_offer_str =
3723 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3724 SetLocalDescriptionWithoutError(jsep_offer_str);
3725 EXPECT_TRUE(session_->voice_channel()->secure_required());
3726 EXPECT_TRUE(session_->video_channel()->secure_required());
3727}
3728
3729// This test verifies the crypto parameter when security is disabled.
3730TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003731 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003732 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003733 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003735
3736 // Making sure SetLocalDescription correctly sets crypto value in
3737 // SessionDescription object after de-serialization of sdp string. The value
3738 // will be set as per MediaSessionDescriptionFactory.
3739 std::string offer_str;
3740 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003741 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3743 SetLocalDescriptionWithoutError(jsep_offer_str);
3744 EXPECT_FALSE(session_->voice_channel()->secure_required());
3745 EXPECT_FALSE(session_->video_channel()->secure_required());
3746}
3747
3748// This test verifies that an answer contains new ufrag and password if an offer
3749// with new ufrag and password is received.
3750TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003751 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003752 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003753 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003754 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003755 SetRemoteDescriptionWithoutError(offer.release());
3756
deadbeefab9b2d12015-10-14 11:33:11 -07003757 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003758 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759 SetLocalDescriptionWithoutError(answer.release());
3760
3761 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003762 for (const cricket::ContentInfo& content :
3763 session_->local_description()->description()->contents()) {
3764 options.transport_options[content.name].ice_restart = true;
3765 }
kwibergd1fe2812016-04-27 06:47:29 -07003766 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003767 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003768 SetRemoteDescriptionWithoutError(updated_offer1.release());
3769
kwibergd1fe2812016-04-27 06:47:29 -07003770 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003771
deadbeef0ed85b22016-02-23 17:24:52 -08003772 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3773 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003774
deadbeef0ed85b22016-02-23 17:24:52 -08003775 // Even a second answer (created before the description is set) should have
3776 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003777 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003778
3779 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3780 session_->local_description()->description()));
3781
3782 SetLocalDescriptionWithoutError(updated_answer2.release());
3783}
3784
3785// This test verifies that an answer contains new ufrag and password if an offer
3786// that changes either the ufrag or password (but not both) is received.
3787// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3788// a=ice-pwd attributes compared to the previous SDP from the peer, it
3789// indicates that ICE is restarting for this media stream."
3790TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3791 Init();
3792 cricket::MediaSessionOptions options;
3793 options.recv_audio = true;
3794 options.recv_video = true;
3795 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003796 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003797 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3798 SetRemoteDescriptionWithoutError(offer.release());
3799
3800 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003801 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003802 SetLocalDescriptionWithoutError(answer.release());
3803
3804 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003805 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003806 CreateRemoteOffer(options, session_->remote_description()));
3807 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3808 "original_password12345");
3809 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3810
kwibergd1fe2812016-04-27 06:47:29 -07003811 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003812 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3813 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003815
3816 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003817 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003818 CreateRemoteOffer(options, session_->remote_description()));
3819 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3820 "modified_password12345");
3821 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3822
kwibergd1fe2812016-04-27 06:47:29 -07003823 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003824 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3825 session_->local_description()->description()));
3826 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003827}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003828
wu@webrtc.org91053e72013-08-10 07:18:04 +00003829// This test verifies that an answer contains old ufrag and password if an offer
3830// with old ufrag and password is received.
3831TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003832 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003833 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003834 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003835 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003836 SetRemoteDescriptionWithoutError(offer.release());
3837
deadbeefab9b2d12015-10-14 11:33:11 -07003838 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003839 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003840 SetLocalDescriptionWithoutError(answer.release());
3841
3842 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003843 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003844 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003845 SetRemoteDescriptionWithoutError(updated_offer2.release());
3846
kwibergd1fe2812016-04-27 06:47:29 -07003847 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003848
deadbeef0ed85b22016-02-23 17:24:52 -08003849 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3850 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003851
3852 SetLocalDescriptionWithoutError(updated_answer2.release());
3853}
3854
deadbeef0ed85b22016-02-23 17:24:52 -08003855// This test verifies that if an offer does an ICE restart on some, but not all
3856// media sections, the answer will change the ufrag/password in the correct
3857// media sections.
3858TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3859 Init();
3860 cricket::MediaSessionOptions options;
3861 options.recv_video = true;
3862 options.recv_audio = true;
3863 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003864 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003865
3866 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3867 "aaaaaaaaaaaaaaaaaaaaaa");
3868 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3869 "bbbbbbbbbbbbbbbbbbbbbb");
3870 SetRemoteDescriptionWithoutError(offer.release());
3871
3872 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003873 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003874 SetLocalDescriptionWithoutError(answer.release());
3875
3876 // Receive an offer with new ufrag and password, but only for the video media
3877 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003878 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003879 CreateRemoteOffer(options, session_->remote_description()));
3880 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3881 "cccccccccccccccccccccc");
3882 SetRemoteDescriptionWithoutError(updated_offer.release());
3883
kwibergd1fe2812016-04-27 06:47:29 -07003884 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003885
3886 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3887 session_->local_description()->description(),
3888 cricket::MEDIA_TYPE_AUDIO));
3889
3890 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3891 session_->local_description()->description(),
3892 cricket::MEDIA_TYPE_VIDEO));
3893
3894 SetLocalDescriptionWithoutError(updated_answer.release());
3895}
3896
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003897TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003898 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003899 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003900 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003901 const std::string session_id_orig = offer->session_id();
3902 const std::string session_version_orig = offer->session_version();
3903 SetLocalDescriptionWithoutError(offer);
3904
3905 video_channel_ = media_engine_->GetVideoChannel(0);
3906 video_channel_->set_fail_set_send_codecs(true);
3907
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003908 SessionDescriptionInterface* answer =
3909 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003910 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003911
3912 // Test that after a content error, setting any description will
3913 // result in an error.
3914 video_channel_->set_fail_set_send_codecs(false);
3915 answer = CreateRemoteAnswer(session_->local_description());
3916 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3917 offer = CreateRemoteOffer();
3918 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003919}
3920
3921// Runs the loopback call test with BUNDLE and STUN disabled.
3922TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3923 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003924 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003925 cricket::PORTALLOCATOR_DISABLE_STUN |
3926 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003927 TestLoopbackCall();
3928}
3929
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003930TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003931 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003932 cricket::PORTALLOCATOR_DISABLE_STUN |
3933 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3934 cricket::PORTALLOCATOR_DISABLE_RELAY);
3935
3936 // best connection is IPv6 since it has higher network preference.
3937 LoopbackNetworkConfiguration config;
3938 config.test_ipv6_network_ = true;
3939 config.best_connection_after_initial_ice_converged_ =
3940 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3941
3942 TestLoopbackCall(config);
3943}
3944
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003945// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003946TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003947 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3948 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003949 TestLoopbackCall();
3950}
3951
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003952TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003953 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003954 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003955 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003956 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003957 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3958}
3959
Henrik Boström87713d02015-08-25 09:53:21 +02003960TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003961 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003962
htaa2a49d92016-03-04 02:51:39 -08003963 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003964 options_.disable_sctp_data_channels = false;
3965
Henrik Boström87713d02015-08-25 09:53:21 +02003966 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003967
3968 SetLocalDescriptionWithDataChannel();
3969 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3970}
3971
Henrik Boström87713d02015-08-25 09:53:21 +02003972TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003973 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003974
Henrik Boström87713d02015-08-25 09:53:21 +02003975 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003976
kwibergd1fe2812016-04-27 06:47:29 -07003977 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003978 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003979 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3980}
3981
Henrik Boström87713d02015-08-25 09:53:21 +02003982TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003983 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003984 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003985 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003986
3987 // Create remote offer with SCTP.
3988 cricket::MediaSessionOptions options;
3989 options.data_channel_type = cricket::DCT_SCTP;
3990 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003991 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003992 SetRemoteDescriptionWithoutError(offer);
3993
3994 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003995 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003996 EXPECT_TRUE(answer != NULL);
3997 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3998 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003999}
4000
Henrik Boström87713d02015-08-25 09:53:21 +02004001TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004002 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004003 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004004
4005 SetLocalDescriptionWithDataChannel();
4006 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4007}
4008
Henrik Boström87713d02015-08-25 09:53:21 +02004009TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004010 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004011
Henrik Boström87713d02015-08-25 09:53:21 +02004012 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004013
4014 SetLocalDescriptionWithDataChannel();
4015 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4016}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004017
Henrik Boström87713d02015-08-25 09:53:21 +02004018TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004019 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004020 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004021 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004022
4023 SetLocalDescriptionWithDataChannel();
4024 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4025}
4026
Henrik Boström87713d02015-08-25 09:53:21 +02004027TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004028 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004029 const int new_send_port = 9998;
4030 const int new_recv_port = 7775;
4031
Henrik Boström87713d02015-08-25 09:53:21 +02004032 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004033 SetFactoryDtlsSrtp();
4034
4035 // By default, don't actually add the codecs to desc_factory_; they don't
4036 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4037 // let the session description get parsed. That'll get the proper codecs
4038 // into the stream.
4039 cricket::MediaSessionOptions options;
4040 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4041 "stream1", new_send_port, options);
4042
4043 // SetRemoteDescription will take the ownership of the offer.
4044 SetRemoteDescriptionWithoutError(offer);
4045
htaa2a49d92016-03-04 02:51:39 -08004046 SessionDescriptionInterface* answer =
4047 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004048 ASSERT_TRUE(answer != NULL);
4049
4050 // Now set the local description, which'll take ownership of the answer.
4051 SetLocalDescriptionWithoutError(answer);
4052
4053 // TEST PLAN: Set the port number to something new, set it in the SDP,
4054 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004055 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004056 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004057
4058 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4059 int portnum = -1;
4060 ASSERT_TRUE(ch != NULL);
4061 ASSERT_EQ(1UL, ch->send_codecs().size());
4062 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004063 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004064 ch->send_codecs()[0].name.c_str()));
4065 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4066 &portnum));
4067 EXPECT_EQ(new_send_port, portnum);
4068
4069 ASSERT_EQ(1UL, ch->recv_codecs().size());
4070 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004071 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004072 ch->recv_codecs()[0].name.c_str()));
4073 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4074 &portnum));
4075 EXPECT_EQ(new_recv_port, portnum);
4076}
4077
deadbeefab9b2d12015-10-14 11:33:11 -07004078// Verifies that when a session's DataChannel receives an OPEN message,
4079// WebRtcSession signals the DataChannel creation request with the expected
4080// config.
4081TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4082 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4083
4084 InitWithDtls(GetParam());
4085
4086 SetLocalDescriptionWithDataChannel();
4087 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4088
4089 webrtc::DataChannelInit config;
4090 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004091 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004092 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4093 cricket::ReceiveDataParams params;
4094 params.ssrc = config.id;
4095 params.type = cricket::DMT_CONTROL;
4096
4097 cricket::DataChannel* data_channel = session_->data_channel();
4098 data_channel->SignalDataReceived(data_channel, params, payload);
4099
4100 EXPECT_EQ("a", last_data_channel_label_);
4101 EXPECT_EQ(config.id, last_data_channel_config_.id);
4102 EXPECT_FALSE(last_data_channel_config_.negotiated);
4103 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4104 last_data_channel_config_.open_handshake_role);
4105}
4106
4107TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004108 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4109 FakeDtlsIdentityStore::GenerateCertificate();
4110
htaa2a49d92016-03-04 02:51:39 -08004111 configuration_.certificates.push_back(certificate);
4112 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004113 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4114
4115 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4116}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004117
Henrik Boström87713d02015-08-25 09:53:21 +02004118// Verifies that CreateOffer succeeds when CreateOffer is called before async
4119// identity generation is finished (even if a certificate is provided this is
4120// an async op).
4121TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4122 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4123 InitWithDtls(GetParam());
4124
Henrik Boströmd8281982015-08-27 10:12:24 +02004125 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004126 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004127 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004128
wu@webrtc.org91053e72013-08-10 07:18:04 +00004129 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004130 VerifyNoCryptoParams(offer->description(), true);
4131 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004132}
4133
4134// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004135// identity generation is finished (even if a certificate is provided this is
4136// an async op).
4137TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004138 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004139 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004140 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141
4142 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004143 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004144 std::unique_ptr<JsepSessionDescription> offer(
4145 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004146 ASSERT_TRUE(offer.get() != NULL);
4147 SetRemoteDescriptionWithoutError(offer.release());
4148
kwibergd1fe2812016-04-27 06:47:29 -07004149 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004150 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004151 VerifyNoCryptoParams(answer->description(), true);
4152 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004153}
4154
4155// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004156// identity generation is finished (even if a certificate is provided this is
4157// an async op).
4158TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004159 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004160 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004161
Henrik Boströmd8281982015-08-27 10:12:24 +02004162 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004163
kwibergd1fe2812016-04-27 06:47:29 -07004164 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004165 EXPECT_TRUE(offer != NULL);
4166}
4167
4168// Verifies that CreateOffer fails when CreateOffer is called after async
4169// identity generation fails.
4170TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004171 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004172 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004173
Henrik Boströmd8281982015-08-27 10:12:24 +02004174 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004175
kwibergd1fe2812016-04-27 06:47:29 -07004176 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004177 EXPECT_TRUE(offer == NULL);
4178}
4179
4180// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4181// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004182TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004183 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004184 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004185 VerifyMultipleAsyncCreateDescription(GetParam(),
4186 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004187}
4188
4189// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4190// before async identity generation fails.
4191TEST_F(WebRtcSessionTest,
4192 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004193 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004194 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4195 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004196}
4197
4198// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4199// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004200TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004201 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004202 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004203 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004204 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004205}
4206
4207// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4208// before async identity generation fails.
4209TEST_F(WebRtcSessionTest,
4210 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004211 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004212 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4213 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004214}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004215
4216// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4217// offer has no SDES crypto but only DTLS fingerprint.
4218TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4219 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004220 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004221 // Create a remote offer with secured transport disabled.
4222 cricket::MediaSessionOptions options;
4223 JsepSessionDescription* offer(CreateRemoteOffer(
4224 options, cricket::SEC_DISABLED));
4225 // Adds a DTLS fingerprint to the remote offer.
4226 cricket::SessionDescription* sdp = offer->description();
4227 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4228 ASSERT_TRUE(audio != NULL);
4229 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4230 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004231 rtc::SSLFingerprint::CreateFromRfc4572(
4232 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004233 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004234 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004235}
4236
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004237TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004238 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004239 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004240 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004241 SessionDescriptionInterface* offer = CreateOffer();
4242
4243 SetLocalDescriptionWithoutError(offer);
4244
4245 voice_channel_ = media_engine_->GetVoiceChannel(0);
4246
4247 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004248 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004249 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004250}
4251
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004252// Tests that we can renegotiate new media content with ICE candidates in the
4253// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004254TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004255 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004256 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004257 SetFactoryDtlsSrtp();
4258
deadbeefab9b2d12015-10-14 11:33:11 -07004259 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004260 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004261 SetLocalDescriptionWithoutError(offer);
4262
4263 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4264 SetRemoteDescriptionWithoutError(answer);
4265
4266 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004267 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004268 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4269
4270 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004271 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004272 candidate1.set_component(1);
4273 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4274 candidate1);
4275 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4276 SetRemoteDescriptionWithoutError(offer);
4277
htaa2a49d92016-03-04 02:51:39 -08004278 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004279 SetLocalDescriptionWithoutError(answer);
4280}
4281
4282// Tests that we can renegotiate new media content with ICE candidates separated
4283// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004284TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004285 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004286 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004287 SetFactoryDtlsSrtp();
4288
deadbeefab9b2d12015-10-14 11:33:11 -07004289 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004290 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004291 SetLocalDescriptionWithoutError(offer);
4292
4293 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4294 SetRemoteDescriptionWithoutError(answer);
4295
4296 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004297 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004298 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4299 SetRemoteDescriptionWithoutError(offer);
4300
4301 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004302 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004303 candidate1.set_component(1);
4304 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4305 candidate1);
4306 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4307
htaa2a49d92016-03-04 02:51:39 -08004308 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004309 SetLocalDescriptionWithoutError(answer);
4310}
honghaiz7f777492016-02-02 21:54:01 -08004311
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004312// Tests that RTX codec is removed from the answer when it isn't supported
4313// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004314TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004315 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004316 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004317 std::string offer_sdp(kSdpWithRtx);
4318
4319 SessionDescriptionInterface* offer =
4320 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4321 EXPECT_TRUE(offer->ToString(&offer_sdp));
4322
4323 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004324 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004325 SetRemoteDescriptionWithoutError(offer);
4326
htaa2a49d92016-03-04 02:51:39 -08004327 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004328 // Answer SDP does not contain the RTX codec.
4329 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004330 SetLocalDescriptionWithoutError(answer);
4331}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004332
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004333// This verifies that the voice channel after bundle has both options from video
4334// and voice channels.
4335TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4336 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004337 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004338
4339 PeerConnectionInterface::RTCOfferAnswerOptions options;
4340 options.use_rtp_mux = true;
4341
4342 SessionDescriptionInterface* offer = CreateOffer(options);
4343 SetLocalDescriptionWithoutError(offer);
4344
4345 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4346 rtc::Socket::Option::OPT_SNDBUF, 4000);
4347
4348 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4349 rtc::Socket::Option::OPT_RCVBUF, 8000);
4350
4351 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004352 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004353 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4354 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004355 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004356 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4357
deadbeefcbecd352015-09-23 11:50:27 -07004358 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004359 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4360 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004361 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004362 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4363
deadbeefcbecd352015-09-23 11:50:27 -07004364 EXPECT_NE(session_->voice_rtp_transport_channel(),
4365 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004366
deadbeefab9b2d12015-10-14 11:33:11 -07004367 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004368 SessionDescriptionInterface* answer =
4369 CreateRemoteAnswer(session_->local_description());
4370 SetRemoteDescriptionWithoutError(answer);
4371
deadbeefcbecd352015-09-23 11:50:27 -07004372 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004373 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4374 EXPECT_EQ(4000, option_val);
4375
deadbeefcbecd352015-09-23 11:50:27 -07004376 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004377 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4378 EXPECT_EQ(8000, option_val);
4379}
4380
tommi0f620f42015-07-09 03:25:02 -07004381// Test creating a session, request multiple offers, destroy the session
4382// and make sure we got success/failure callbacks for all of the requests.
4383// Background: crbug.com/507307
4384TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4385 Init();
4386
4387 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4388 PeerConnectionInterface::RTCOfferAnswerOptions options;
4389 options.offer_to_receive_audio =
4390 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004391 cricket::MediaSessionOptions session_options;
4392 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004393
4394 for (auto& o : observers) {
4395 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004396 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004397 }
4398
4399 session_.reset();
4400
tommi0f620f42015-07-09 03:25:02 -07004401 for (auto& o : observers) {
4402 // We expect to have received a notification now even if the session was
4403 // terminated. The offer creation may or may not have succeeded, but we
4404 // must have received a notification which, so the only invalid state
4405 // is kInit.
4406 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4407 }
4408}
4409
stefanc1aeaf02015-10-15 07:26:07 -07004410TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4411 TestPacketOptions();
4412}
4413
deadbeef057ecf02016-01-20 14:30:43 -08004414// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4415// is destroyed.
4416TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4417 Init();
4418 session_.reset();
4419 EXPECT_TRUE(session_destroyed_);
4420}
4421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004422// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4423// currently fails because upon disconnection and reconnection OnIceComplete is
4424// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004425
deadbeefcbecd352015-09-23 11:50:27 -07004426INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4427 WebRtcSessionTest,
4428 testing::Values(ALREADY_GENERATED,
4429 DTLS_IDENTITY_STORE));