blob: 52a3f0af70f095617deecc5162e954af84035a30 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
kwiberg0eb15ed2015-12-17 03:04:15 -080028#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070029#include <vector>
30
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/app/webrtc/audiotrack.h"
stefanc1aeaf02015-10-15 07:26:07 -070032#include "talk/app/webrtc/fakemediacontroller.h"
jbauchac8869e2015-07-03 01:36:14 -070033#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/jsepicecandidate.h"
35#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070036#include "talk/app/webrtc/peerconnection.h"
deadbeefab9b2d12015-10-14 11:33:11 -070037#include "talk/app/webrtc/sctputils.h"
38#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020041#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000044#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/media/base/fakemediaengine.h"
46#include "talk/media/base/fakevideorenderer.h"
47#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070048#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000049#include "webrtc/p2p/base/stunserver.h"
50#include "webrtc/p2p/base/teststunserver.h"
51#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000052#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000054#include "talk/session/media/channelmanager.h"
55#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056#include "webrtc/base/fakenetwork.h"
57#include "webrtc/base/firewallsocketserver.h"
58#include "webrtc/base/gunit.h"
59#include "webrtc/base/logging.h"
60#include "webrtc/base/network.h"
61#include "webrtc/base/physicalsocketserver.h"
62#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020063#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064#include "webrtc/base/sslstreamadapter.h"
65#include "webrtc/base/stringutils.h"
66#include "webrtc/base/thread.h"
67#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
69#define MAYBE_SKIP_TEST(feature) \
70 if (!(feature())) { \
71 LOG(LS_INFO) << "Feature disabled... skipping"; \
72 return; \
73 }
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070083using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020084using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070086using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070088using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::JsepIceCandidate;
90using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000091using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::PeerConnectionInterface;
93using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070094using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000096using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000097using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kCreateChannelFailed;
99using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000103using webrtc::kSdpWithoutDtlsFingerprint;
104using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000106using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000107using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000109typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
110
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111static const int kClientAddrPort = 0;
112static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000113static const char kClientIPv6AddrHost1[] =
114 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000115static const char kClientAddrHost2[] = "22.22.22.22";
116static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000117static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
118static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000119static const char kTurnUsername[] = "test";
120static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122static const char kSessionVersion[] = "1";
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Media index of candidates belonging to the first media content.
125static const int kMediaContentIndex0 = 0;
126static const char kMediaContentName0[] = "audio";
127
128// Media index of candidates belonging to the second media content.
129static const int kMediaContentIndex1 = 1;
130static const char kMediaContentName1[] = "video";
131
132static const int kIceCandidatesTimeout = 10000;
133
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000134static const char kFakeDtlsFingerprint[] =
135 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
136 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
137
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000138static const char kTooLongIceUfragPwd[] =
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
143
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000144static const char kSdpWithRtx[] =
145 "v=0\r\n"
146 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
149 "a=msid-semantic: WMS stream1\r\n"
150 "m=video 9 RTP/SAVPF 0 96\r\n"
151 "c=IN IP4 0.0.0.0\r\n"
152 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
153 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
154 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
155 "a=mid:video\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
159 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
160 "a=rtpmap:0 fake_video_codec/90000\r\n"
161 "a=rtpmap:96 rtx/90000\r\n"
162 "a=fmtp:96 apt=0\r\n";
163
deadbeefab9b2d12015-10-14 11:33:11 -0700164static const char kStream1[] = "stream1";
165static const char kVideoTrack1[] = "video1";
166static const char kAudioTrack1[] = "audio1";
167
168static const char kStream2[] = "stream2";
169static const char kVideoTrack2[] = "video2";
170static const char kAudioTrack2[] = "audio2";
171
Henrik Boström87713d02015-08-25 09:53:21 +0200172enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174class MockIceObserver : public webrtc::IceObserver {
175 public:
176 MockIceObserver()
177 : oncandidatesready_(false),
178 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
179 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
180 }
181
182 virtual void OnIceConnectionChange(
183 PeerConnectionInterface::IceConnectionState new_state) {
184 ice_connection_state_ = new_state;
185 }
186 virtual void OnIceGatheringChange(
187 PeerConnectionInterface::IceGatheringState new_state) {
188 // We can never transition back to "new".
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
190 ice_gathering_state_ = new_state;
191
192 // oncandidatesready_ really means "ICE gathering is complete".
193 // This if statement ensures that this value remains correct when we
194 // transition from kIceGatheringComplete to kIceGatheringGathering.
195 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
196 oncandidatesready_ = false;
197 }
198 }
199
200 // Found a new candidate.
201 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000202 switch (candidate->sdp_mline_index()) {
203 case kMediaContentIndex0:
204 mline_0_candidates_.push_back(candidate->candidate());
205 break;
206 case kMediaContentIndex1:
207 mline_1_candidates_.push_back(candidate->candidate());
208 break;
209 default:
210 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000212
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 // The ICE gathering state should always be Gathering when a candidate is
214 // received (or possibly Completed in the case of the final candidate).
215 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
216 }
217
218 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
219 virtual void OnIceComplete() {
220 EXPECT_FALSE(oncandidatesready_);
221 oncandidatesready_ = true;
222
223 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
224 // be called approximately simultaneously. For ease of testing, this
225 // check additionally requires that they be called in the above order.
226 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
227 ice_gathering_state_);
228 }
229
230 bool oncandidatesready_;
231 std::vector<cricket::Candidate> mline_0_candidates_;
232 std::vector<cricket::Candidate> mline_1_candidates_;
233 PeerConnectionInterface::IceConnectionState ice_connection_state_;
234 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
235};
236
237class WebRtcSessionForTest : public webrtc::WebRtcSession {
238 public:
stefanc1aeaf02015-10-15 07:26:07 -0700239 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000240 rtc::Thread* signaling_thread,
241 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700243 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700244 : WebRtcSession(media_controller,
245 signaling_thread,
246 worker_thread,
247 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 RegisterIceObserver(ice_observer);
249 }
250 virtual ~WebRtcSessionForTest() {}
251
deadbeefcbecd352015-09-23 11:50:27 -0700252 // Note that these methods are only safe to use if the signaling thread
253 // is the same as the worker thread
254 cricket::TransportChannel* voice_rtp_transport_channel() {
255 return rtp_transport_channel(voice_channel());
256 }
257
258 cricket::TransportChannel* voice_rtcp_transport_channel() {
259 return rtcp_transport_channel(voice_channel());
260 }
261
262 cricket::TransportChannel* video_rtp_transport_channel() {
263 return rtp_transport_channel(video_channel());
264 }
265
266 cricket::TransportChannel* video_rtcp_transport_channel() {
267 return rtcp_transport_channel(video_channel());
268 }
269
270 cricket::TransportChannel* data_rtp_transport_channel() {
271 return rtp_transport_channel(data_channel());
272 }
273
274 cricket::TransportChannel* data_rtcp_transport_channel() {
275 return rtcp_transport_channel(data_channel());
276 }
277
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 using webrtc::WebRtcSession::SetAudioPlayout;
279 using webrtc::WebRtcSession::SetAudioSend;
280 using webrtc::WebRtcSession::SetCaptureDevice;
281 using webrtc::WebRtcSession::SetVideoPlayout;
282 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700283
284 private:
285 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
286 if (!ch) {
287 return nullptr;
288 }
289 return ch->transport_channel();
290 }
291
292 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
293 if (!ch) {
294 return nullptr;
295 }
296 return ch->rtcp_transport_channel();
297 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298};
299
wu@webrtc.org91053e72013-08-10 07:18:04 +0000300class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000301 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 enum State {
304 kInit,
305 kFailed,
306 kSucceeded,
307 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000308 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309
310 // CreateSessionDescriptionObserver implementation.
311 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000312 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000313 state_ = kSucceeded;
314 }
315 virtual void OnFailure(const std::string& error) {
316 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
318
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000319 SessionDescriptionInterface* description() { return description_.get(); }
320
321 SessionDescriptionInterface* ReleaseDescription() {
322 return description_.release();
323 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324
wu@webrtc.org91053e72013-08-10 07:18:04 +0000325 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326
wu@webrtc.org91053e72013-08-10 07:18:04 +0000327 protected:
328 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329
330 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000332 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333};
334
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000335class FakeAudioRenderer : public cricket::AudioRenderer {
336 public:
solenberg98c68862015-10-09 03:27:14 -0700337 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000338 virtual ~FakeAudioRenderer() {
339 if (sink_)
340 sink_->OnClose();
341 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000342
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000343 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000344
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000345 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000346 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000347 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000348};
349
Henrik Boström87713d02015-08-25 09:53:21 +0200350class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700351 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
352 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 protected:
354 // TODO Investigate why ChannelManager crashes, if it's created
355 // after stun_server.
356 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700357 : media_engine_(new cricket::FakeMediaEngine()),
358 data_engine_(new cricket::FakeDataEngine()),
359 channel_manager_(
360 new cricket::ChannelManager(media_engine_,
361 data_engine_,
362 new cricket::CaptureManager(),
363 rtc::Thread::Current())),
364 fake_call_(webrtc::Call::Config()),
365 media_controller_(
366 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
367 channel_manager_.get())),
368 tdesc_factory_(new cricket::TransportDescriptionFactory()),
369 desc_factory_(
370 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
371 tdesc_factory_.get())),
372 pss_(new rtc::PhysicalSocketServer),
373 vss_(new rtc::VirtualSocketServer(pss_.get())),
374 fss_(new rtc::FirewallSocketServer(vss_.get())),
375 ss_scope_(fss_.get()),
376 stun_socket_addr_(
377 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
378 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
379 stun_socket_addr_)),
380 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
381 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000382 cricket::ServerAddresses stun_servers;
383 stun_servers.insert(stun_socket_addr_);
384 allocator_.reset(new cricket::BasicPortAllocator(
385 &network_manager_,
386 stun_servers,
387 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000388 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700389 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 EXPECT_TRUE(channel_manager_->Init());
391 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000392 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 }
394
395 void AddInterface(const SocketAddress& addr) {
396 network_manager_.AddInterface(addr);
397 }
398
Henrik Boström87713d02015-08-25 09:53:21 +0200399 // If |dtls_identity_store| != null or |rtc_configuration| contains
400 // |certificates| then DTLS will be enabled unless explicitly disabled by
401 // |rtc_configuration| options. When DTLS is enabled a certificate will be
402 // used if provided, otherwise one will be generated using the
403 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000404 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200405 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200406 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 ASSERT_TRUE(session_.get() == NULL);
408 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700409 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700410 allocator_.get(), &observer_));
411 session_->SignalDataChannelOpenMessage.connect(
412 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800413 session_->GetOnDestroyedSignal()->connect(
414 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415
416 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
417 observer_.ice_connection_state_);
418 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
419 observer_.ice_gathering_state_);
420
deadbeefcbecd352015-09-23 11:50:27 -0700421 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800422 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700423 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700424 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 }
426
deadbeefab9b2d12015-10-14 11:33:11 -0700427 void OnDataChannelOpenMessage(const std::string& label,
428 const InternalDataChannelInit& config) {
429 last_data_channel_label_ = label;
430 last_data_channel_config_ = config;
431 }
432
deadbeef057ecf02016-01-20 14:30:43 -0800433 void OnSessionDestroyed() { session_destroyed_ = true; }
434
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000435 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200436 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200437 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000438 }
439
440 void InitWithIceTransport(
441 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200442 PeerConnectionInterface::RTCConfiguration configuration;
443 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200444 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000445 }
446
447 void InitWithBundlePolicy(
448 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200449 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200450 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200451 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700452 }
453
454 void InitWithRtcpMuxPolicy(
455 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
456 PeerConnectionInterface::RTCConfiguration configuration;
457 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200458 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000459 }
460
Henrik Boström87713d02015-08-25 09:53:21 +0200461 // Successfully init with DTLS; with a certificate generated and supplied or
462 // with a store that generates it for us.
463 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
464 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
465 PeerConnectionInterface::RTCConfiguration configuration;
466 if (cert_gen_method == ALREADY_GENERATED) {
467 configuration.certificates.push_back(
468 FakeDtlsIdentityStore::GenerateCertificate());
469 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
470 dtls_identity_store.reset(new FakeDtlsIdentityStore());
471 dtls_identity_store->set_should_fail(false);
472 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700473 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200474 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800475 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200476 }
477
478 // Init with DTLS with a store that will fail to generate a certificate.
479 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200480 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
481 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200482 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200483 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800484 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000485 }
486
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 void InitWithDtmfCodec() {
488 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000489 const cricket::AudioCodec kTelephoneEventCodec(
490 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 std::vector<cricket::AudioCodec> codecs;
492 codecs.push_back(kTelephoneEventCodec);
493 media_engine_->SetAudioCodecs(codecs);
494 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 }
497
deadbeefab9b2d12015-10-14 11:33:11 -0700498 void SendAudioVideoStream1() {
499 send_stream_1_ = true;
500 send_stream_2_ = false;
501 send_audio_ = true;
502 send_video_ = true;
503 }
504
505 void SendAudioVideoStream2() {
506 send_stream_1_ = false;
507 send_stream_2_ = true;
508 send_audio_ = true;
509 send_video_ = true;
510 }
511
512 void SendAudioVideoStream1And2() {
513 send_stream_1_ = true;
514 send_stream_2_ = true;
515 send_audio_ = true;
516 send_video_ = true;
517 }
518
519 void SendNothing() {
520 send_stream_1_ = false;
521 send_stream_2_ = false;
522 send_audio_ = false;
523 send_video_ = false;
524 }
525
526 void SendAudioOnlyStream2() {
527 send_stream_1_ = false;
528 send_stream_2_ = true;
529 send_audio_ = true;
530 send_video_ = false;
531 }
532
533 void SendVideoOnlyStream2() {
534 send_stream_1_ = false;
535 send_stream_2_ = true;
536 send_audio_ = false;
537 send_video_ = true;
538 }
539
540 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
541 if (send_stream_1_ && send_audio_) {
542 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
543 kStream1);
544 }
545 if (send_stream_1_ && send_video_) {
546 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
547 kStream1);
548 }
549 if (send_stream_2_ && send_audio_) {
550 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
551 kStream2);
552 }
553 if (send_stream_2_ && send_video_) {
554 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
555 kStream2);
556 }
557 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
558 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
559 data_channel_->label(),
560 data_channel_->label());
561 }
562 }
563
564 void GetOptionsForOffer(
565 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
566 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700567 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
568
deadbeefc80741f2015-10-22 13:14:45 -0700569 AddStreamsToOptions(session_options);
570 if (rtc_options.offer_to_receive_audio ==
571 RTCOfferAnswerOptions::kUndefined) {
572 session_options->recv_audio =
573 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
574 }
575 if (rtc_options.offer_to_receive_video ==
576 RTCOfferAnswerOptions::kUndefined) {
577 session_options->recv_video =
578 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
579 }
580 session_options->bundle_enabled =
581 session_options->bundle_enabled &&
582 (session_options->has_audio() || session_options->has_video() ||
583 session_options->has_data());
584
deadbeefab9b2d12015-10-14 11:33:11 -0700585 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
586 session_options->data_channel_type = cricket::DCT_SCTP;
587 }
588 }
589
590 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
591 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700592 session_options->recv_audio = false;
593 session_options->recv_video = false;
594 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
595
deadbeefc80741f2015-10-22 13:14:45 -0700596 AddStreamsToOptions(session_options);
597 session_options->bundle_enabled =
598 session_options->bundle_enabled &&
599 (session_options->has_audio() || session_options->has_video() ||
600 session_options->has_data());
601
deadbeefab9b2d12015-10-14 11:33:11 -0700602 if (session_->data_channel_type() == cricket::DCT_SCTP) {
603 session_options->data_channel_type = cricket::DCT_SCTP;
604 }
605 }
606
607 // Creates a local offer and applies it. Starts ICE.
608 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 // to decide which streams to create.
610 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000611 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 SetLocalDescriptionWithoutError(offer);
613 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
614 observer_.ice_gathering_state_,
615 kIceCandidatesTimeout);
616 }
617
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000618 SessionDescriptionInterface* CreateOffer() {
619 PeerConnectionInterface::RTCOfferAnswerOptions options;
620 options.offer_to_receive_audio =
621 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
622
623 return CreateOffer(options);
624 }
625
wu@webrtc.org91053e72013-08-10 07:18:04 +0000626 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000627 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000628 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000629 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700630 cricket::MediaSessionOptions session_options;
631 GetOptionsForOffer(options, &session_options);
632 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 EXPECT_TRUE_WAIT(
634 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000635 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000636 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000637 }
638
639 SessionDescriptionInterface* CreateAnswer(
640 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000641 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000642 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700643 cricket::MediaSessionOptions session_options;
644 GetOptionsForAnswer(constraints, &session_options);
645 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000646 EXPECT_TRUE_WAIT(
647 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000648 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000649 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000650 }
651
wu@webrtc.org364f2042013-11-20 21:49:41 +0000652 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 return (session_->voice_channel() != NULL &&
654 session_->video_channel() != NULL);
655 }
656
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
658 ASSERT_TRUE(session_.get() != NULL);
659 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::AudioContentDescription* audio_content =
662 static_cast<const cricket::AudioContentDescription*>(
663 content->description);
664 ASSERT_TRUE(audio_content != NULL);
665 ASSERT_EQ(1U, audio_content->cryptos().size());
666 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
667 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
668 audio_content->cryptos()[0].cipher_suite);
669 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
670 audio_content->protocol());
671
672 content = cricket::GetFirstVideoContent(sdp);
673 ASSERT_TRUE(content != NULL);
674 const cricket::VideoContentDescription* video_content =
675 static_cast<const cricket::VideoContentDescription*>(
676 content->description);
677 ASSERT_TRUE(video_content != NULL);
678 ASSERT_EQ(1U, video_content->cryptos().size());
679 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
680 video_content->cryptos()[0].cipher_suite);
681 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
682 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
683 video_content->protocol());
684 }
685
686 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
687 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
688 ASSERT_TRUE(content != NULL);
689 const cricket::AudioContentDescription* audio_content =
690 static_cast<const cricket::AudioContentDescription*>(
691 content->description);
692 ASSERT_TRUE(audio_content != NULL);
693 ASSERT_EQ(0U, audio_content->cryptos().size());
694
695 content = cricket::GetFirstVideoContent(sdp);
696 ASSERT_TRUE(content != NULL);
697 const cricket::VideoContentDescription* video_content =
698 static_cast<const cricket::VideoContentDescription*>(
699 content->description);
700 ASSERT_TRUE(video_content != NULL);
701 ASSERT_EQ(0U, video_content->cryptos().size());
702
703 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700704 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700706 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 video_content->protocol());
708 } else {
709 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
710 audio_content->protocol());
711 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
712 video_content->protocol());
713 }
714 }
715
716 // Set the internal fake description factories to do DTLS-SRTP.
717 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000718 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000720 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200721 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800722 tdesc_factory_->set_certificate(
723 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
724 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
726 }
727
728 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
729 bool expected) {
730 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
731 ASSERT_TRUE(audio != NULL);
732 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 const TransportInfo* video = sdp->GetTransportInfoByName("video");
734 ASSERT_TRUE(video != NULL);
735 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 }
737
738 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000739 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000741 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000742 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000744 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000746 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
747 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000748 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 // Answer should be NULL as no crypto params in offer.
750 ASSERT_TRUE(answer == NULL);
751 }
752
753 void VerifyAnswerFromCryptoOffer() {
754 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000755 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 options.bundle_enabled = true;
757 scoped_ptr<JsepSessionDescription> offer(
758 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
759 ASSERT_TRUE(offer.get() != NULL);
760 VerifyCryptoParams(offer->description());
761 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000762 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 ASSERT_TRUE(answer.get() != NULL);
764 VerifyCryptoParams(answer->description());
765 }
766
767 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
768 const cricket::SessionDescription* desc2,
769 bool expect_equal) {
770 if (desc1->contents().size() != desc2->contents().size()) {
771 EXPECT_FALSE(expect_equal);
772 return;
773 }
774
775 const cricket::ContentInfos& contents = desc1->contents();
776 cricket::ContentInfos::const_iterator it = contents.begin();
777
778 for (; it != contents.end(); ++it) {
779 const cricket::TransportDescription* transport_desc1 =
780 desc1->GetTransportDescriptionByName(it->name);
781 const cricket::TransportDescription* transport_desc2 =
782 desc2->GetTransportDescriptionByName(it->name);
783 if (!transport_desc1 || !transport_desc2) {
784 EXPECT_FALSE(expect_equal);
785 return;
786 }
787 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
788 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
789 EXPECT_FALSE(expect_equal);
790 return;
791 }
792 }
793 EXPECT_TRUE(expect_equal);
794 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000795
796 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
797 std::string *sdp) {
798 const cricket::SessionDescription* desc = current_desc->description();
799 EXPECT_TRUE(current_desc->ToString(sdp));
800
801 const cricket::ContentInfos& contents = desc->contents();
802 cricket::ContentInfos::const_iterator it = contents.begin();
803 // Replace ufrag and pwd lines with empty strings.
804 for (; it != contents.end(); ++it) {
805 const cricket::TransportDescription* transport_desc =
806 desc->GetTransportDescriptionByName(it->name);
807 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
808 + "\r\n";
809 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
810 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000811 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000812 "", 0,
813 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000814 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000815 "", 0,
816 sdp);
817 }
818 }
819
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000820 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
821 const std::string& modified_ice_ufrag,
822 const std::string& modified_ice_pwd,
823 std::string* sdp) {
824 const cricket::SessionDescription* desc = current_desc->description();
825 EXPECT_TRUE(current_desc->ToString(sdp));
826
827 const cricket::ContentInfos& contents = desc->contents();
828 cricket::ContentInfos::const_iterator it = contents.begin();
829 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
830 // |modified_ice_pwd| strings.
831 for (; it != contents.end(); ++it) {
832 const cricket::TransportDescription* transport_desc =
833 desc->GetTransportDescriptionByName(it->name);
834 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
835 + "\r\n";
836 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
837 + "\r\n";
838 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
839 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000840 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000841 mod_ufrag.c_str(), mod_ufrag.length(),
842 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000843 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000844 mod_pwd.c_str(), mod_pwd.length(),
845 sdp);
846 }
847 }
848
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 // Creates a remote offer and and applies it as a remote description,
850 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700851 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 // to decide which local and remote streams to create.
853 void CreateAndSetRemoteOfferAndLocalAnswer() {
854 SessionDescriptionInterface* offer = CreateRemoteOffer();
855 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000856 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 SetLocalDescriptionWithoutError(answer);
858 }
859 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
860 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700861 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 }
863 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700864 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 SetLocalDescriptionWithoutError(desc);
866 EXPECT_EQ(expected_state, session_->state());
867 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 void SetLocalDescriptionExpectError(const std::string& action,
869 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 SessionDescriptionInterface* desc) {
871 std::string error;
872 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 std::string sdp_type = "local ";
874 sdp_type.append(action);
875 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 EXPECT_NE(std::string::npos, error.find(expected_error));
877 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000878 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
879 SessionDescriptionInterface* desc) {
880 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
881 expected_error, desc);
882 }
883 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
884 SessionDescriptionInterface* desc) {
885 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
886 expected_error, desc);
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
889 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
890 }
891 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700892 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 SetRemoteDescriptionWithoutError(desc);
894 EXPECT_EQ(expected_state, session_->state());
895 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000896 void SetRemoteDescriptionExpectError(const std::string& action,
897 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 SessionDescriptionInterface* desc) {
899 std::string error;
900 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000901 std::string sdp_type = "remote ";
902 sdp_type.append(action);
903 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_NE(std::string::npos, error.find(expected_error));
905 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 void SetRemoteDescriptionOfferExpectError(
907 const std::string& expected_error, SessionDescriptionInterface* desc) {
908 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
909 expected_error, desc);
910 }
911 void SetRemoteDescriptionPranswerExpectError(
912 const std::string& expected_error, SessionDescriptionInterface* desc) {
913 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
914 expected_error, desc);
915 }
916 void SetRemoteDescriptionAnswerExpectError(
917 const std::string& expected_error, SessionDescriptionInterface* desc) {
918 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
919 expected_error, desc);
920 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921
922 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
923 SessionDescriptionInterface** nocrypto_answer) {
924 // Create a SDP without Crypto.
925 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000926 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 options.bundle_enabled = true;
928 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
929 ASSERT_TRUE(*offer != NULL);
930 VerifyCryptoParams((*offer)->description());
931
932 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
933 cricket::SEC_DISABLED);
934 EXPECT_TRUE(*nocrypto_answer != NULL);
935 }
936
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000937 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
938 SessionDescriptionInterface** nodtls_answer) {
939 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000940 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000941 options.bundle_enabled = true;
942
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000944 CreateRemoteOffer(options, cricket::SEC_ENABLED));
945
946 *nodtls_answer =
947 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
948 EXPECT_TRUE(*nodtls_answer != NULL);
949 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
950 VerifyCryptoParams((*nodtls_answer)->description());
951
952 SetFactoryDtlsSrtp();
953 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
954 ASSERT_TRUE(*offer != NULL);
955 VerifyFingerprintStatus((*offer)->description(), true);
956 VerifyCryptoParams((*offer)->description());
957 }
958
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 JsepSessionDescription* CreateRemoteOfferWithVersion(
960 cricket::MediaSessionOptions options,
961 cricket::SecurePolicy secure_policy,
962 const std::string& session_version,
963 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 const cricket::SessionDescription* cricket_desc = NULL;
966 if (current_desc) {
967 cricket_desc = current_desc->description();
968 session_id = current_desc->session_id();
969 }
970
971 desc_factory_->set_secure(secure_policy);
972 JsepSessionDescription* offer(
973 new JsepSessionDescription(JsepSessionDescription::kOffer));
974 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
975 session_id, session_version)) {
976 delete offer;
977 offer = NULL;
978 }
979 return offer;
980 }
981 JsepSessionDescription* CreateRemoteOffer(
982 cricket::MediaSessionOptions options) {
983 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
984 kSessionVersion, NULL);
985 }
986 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000987 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
988 return CreateRemoteOfferWithVersion(
989 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 }
991 JsepSessionDescription* CreateRemoteOffer(
992 cricket::MediaSessionOptions options,
993 const SessionDescriptionInterface* current_desc) {
994 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
995 kSessionVersion, current_desc);
996 }
997
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000998 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
999 const char* sctp_stream_name, int new_port,
1000 cricket::MediaSessionOptions options) {
1001 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001002 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1003 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001004 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1005 }
1006
1007 // Takes ownership of offer_basis (and deletes it).
1008 JsepSessionDescription* ChangeSDPSctpPort(
1009 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1010 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1011 // SessionDescription from the mutated string.
1012 const char* default_port_str = "5000";
1013 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001014 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001015 std::string offer_str;
1016 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001017 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001018 new_port_str, strlen(new_port_str),
1019 &offer_str);
1020 JsepSessionDescription* offer = new JsepSessionDescription(
1021 offer_basis->type());
1022 delete offer_basis;
1023 offer->Initialize(offer_str, NULL);
1024 return offer;
1025 }
1026
deadbeefab9b2d12015-10-14 11:33:11 -07001027 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // before this function to decide which streams to create.
1029 JsepSessionDescription* CreateRemoteOffer() {
1030 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001031 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 return CreateRemoteOffer(options, session_->remote_description());
1033 }
1034
1035 JsepSessionDescription* CreateRemoteAnswer(
1036 const SessionDescriptionInterface* offer,
1037 cricket::MediaSessionOptions options,
1038 cricket::SecurePolicy policy) {
1039 desc_factory_->set_secure(policy);
1040 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001041 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 JsepSessionDescription* answer(
1043 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1044 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1045 options, NULL),
1046 session_id, kSessionVersion)) {
1047 delete answer;
1048 answer = NULL;
1049 }
1050 return answer;
1051 }
1052
1053 JsepSessionDescription* CreateRemoteAnswer(
1054 const SessionDescriptionInterface* offer,
1055 cricket::MediaSessionOptions options) {
1056 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1057 }
1058
deadbeefab9b2d12015-10-14 11:33:11 -07001059 // Creates an answer session description.
1060 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 // to decide which streams to create.
1062 JsepSessionDescription* CreateRemoteAnswer(
1063 const SessionDescriptionInterface* offer) {
1064 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001065 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1067 }
1068
1069 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001070 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001072 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001073
1074 PeerConnectionInterface::RTCOfferAnswerOptions options;
1075 options.use_rtp_mux = bundle;
1076
1077 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1079 // and answer.
1080 SetLocalDescriptionWithoutError(offer);
1081
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001082 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001083 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 std::string sdp;
1085 EXPECT_TRUE(answer->ToString(&sdp));
1086
1087 size_t expected_candidate_num = 2;
1088 if (!rtcp_mux) {
1089 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1090 // for rtp and rtcp.
1091 expected_candidate_num = 4;
1092 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 const std::string kRtcpMux = "a=rtcp-mux";
1094 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001095 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 kXRtcpMux.c_str(), kXRtcpMux.length(),
1097 &sdp);
1098 }
1099
1100 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1101 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102
1103 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001104 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1106 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001107 if (bundle) {
1108 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1109 } else {
1110 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 }
1112 }
1113 // Tests that we can only send DTMF when the dtmf codec is supported.
1114 void TestCanInsertDtmf(bool can) {
1115 if (can) {
1116 InitWithDtmfCodec();
1117 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001118 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 }
deadbeefab9b2d12015-10-14 11:33:11 -07001120 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 CreateAndSetRemoteOfferAndLocalAnswer();
1122 EXPECT_FALSE(session_->CanInsertDtmf(""));
1123 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1124 }
1125
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001126 // Helper class to configure loopback network and verify Best
1127 // Connection using right IP protocol for TestLoopbackCall
1128 // method. LoopbackNetworkManager applies firewall rules to block
1129 // all ping traffic once ICE completed, and remove them to observe
1130 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1131 // verifies the best connection is using the right IP protocol after
1132 // initial ICE convergences.
1133
1134 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001135 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136 LoopbackNetworkConfiguration()
1137 : test_ipv6_network_(false),
1138 test_extra_ipv4_network_(false),
1139 best_connection_after_initial_ice_converged_(1, 0) {}
1140
1141 // Used to track the expected best connection count in each IP protocol.
1142 struct ExpectedBestConnection {
1143 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1144 : ipv4_count_(ipv4_count),
1145 ipv6_count_(ipv6_count) {}
1146
1147 int ipv4_count_;
1148 int ipv6_count_;
1149 };
1150
1151 bool test_ipv6_network_;
1152 bool test_extra_ipv4_network_;
1153 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1154
1155 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001156 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1158 }
1159
1160 private:
jbauchac8869e2015-07-03 01:36:14 -07001161 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001162 const ExpectedBestConnection& expected) const {
1163 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001164 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1165 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001166 expected.ipv4_count_);
1167 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001168 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1169 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001171 // This is used in the loopback call so there is only single host to host
1172 // candidate pair.
1173 EXPECT_EQ(metrics_observer->GetEnumCounter(
1174 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1175 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001176 0);
1177 EXPECT_EQ(metrics_observer->GetEnumCounter(
1178 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1179 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001180 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001181 }
1182 };
1183
1184 class LoopbackNetworkManager {
1185 public:
1186 LoopbackNetworkManager(WebRtcSessionTest* session,
1187 const LoopbackNetworkConfiguration& config)
1188 : config_(config) {
1189 session->AddInterface(
1190 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1191 if (config_.test_extra_ipv4_network_) {
1192 session->AddInterface(
1193 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1194 }
1195 if (config_.test_ipv6_network_) {
1196 session->AddInterface(
1197 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1198 }
1199 }
1200
1201 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1202 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1203 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1204 if (config_.test_extra_ipv4_network_) {
1205 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1206 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1207 }
1208 if (config_.test_ipv6_network_) {
1209 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1210 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1211 }
1212 }
1213
1214 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1215
1216 private:
1217 LoopbackNetworkConfiguration config_;
1218 };
1219
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 // The method sets up a call from the session to itself, in a loopback
1221 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001222 // disconnection, and then a permanent disconnection.
1223 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1225 // While running the call, this method also checks if the session goes through
1226 // the correct sequence of ICE states when a connection is established,
1227 // broken, and re-established.
1228 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001229 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1230 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001232
stefanc1aeaf02015-10-15 07:26:07 -07001233 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001234 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001235 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001236 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237
1238 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1239 observer_.ice_gathering_state_);
1240 SetLocalDescriptionWithoutError(offer);
1241 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1242 observer_.ice_connection_state_);
1243 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001244 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1246 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001247 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248
1249 std::string sdp;
1250 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001251 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1252 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 ASSERT_TRUE(desc != NULL);
1254 SetRemoteDescriptionWithoutError(desc);
1255
1256 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001257 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001258
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001259 // The ice connection state is "Connected" too briefly to catch in a test.
1260 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001261 observer_.ice_connection_state_, kIceCandidatesTimeout);
1262 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263
stefanc1aeaf02015-10-15 07:26:07 -07001264 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1265 LoopbackNetworkManager loopback_network_manager(this, config);
1266 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001267 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268 // Adding firewall rule to block ping requests, which should cause
1269 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001270
1271 loopback_network_manager.ApplyFirewallRules(fss_.get());
1272
1273 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1275 observer_.ice_connection_state_,
1276 kIceCandidatesTimeout);
1277
jbauchac8869e2015-07-03 01:36:14 -07001278 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001279
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001281 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001283 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001284 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 observer_.ice_connection_state_,
1286 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001287
1288 // Now we block ping requests and wait until the ICE connection transitions
1289 // to the Failed state. This will take at least 30 seconds because it must
1290 // wait for the Port to timeout.
1291 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001292
1293 loopback_network_manager.ApplyFirewallRules(fss_.get());
1294 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001295 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001296 observer_.ice_connection_state_,
1297 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 }
1299
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300 void TestLoopbackCall() {
1301 LoopbackNetworkConfiguration config;
1302 TestLoopbackCall(config);
1303 }
1304
stefanc1aeaf02015-10-15 07:26:07 -07001305 void TestPacketOptions() {
1306 media_controller_.reset(
1307 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1308 LoopbackNetworkConfiguration config;
1309 LoopbackNetworkManager loopback_network_manager(this, config);
1310
1311 SetupLoopbackCall();
1312
1313 uint8_t test_packet[15] = {0};
1314 rtc::PacketOptions options;
1315 options.packet_id = 10;
1316 media_engine_->GetVideoChannel(0)
1317 ->SendRtp(test_packet, sizeof(test_packet), options);
1318
1319 const int kPacketTimeout = 2000;
1320 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1321 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1322 }
1323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1325 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001326 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1327 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1328
1329 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1331 codecs.push_back(kCNCodec1);
1332 codecs.push_back(kCNCodec2);
1333 media_engine_->SetAudioCodecs(codecs);
1334 desc_factory_->set_audio_codecs(codecs);
1335 }
1336
1337 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1338 const cricket::ContentDescription* description = content->description;
1339 ASSERT(description != NULL);
1340 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001341 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 ASSERT(audio_content_desc != NULL);
1343 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1344 if (audio_content_desc->codecs()[i].name == "CN")
1345 return false;
1346 }
1347 return true;
1348 }
1349
deadbeefab9b2d12015-10-14 11:33:11 -07001350 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001351 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001352 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1353 data_channel_ = DataChannel::Create(
1354 session_.get(), session_->data_channel_type(), "datachannel", dci);
1355 }
1356
1357 void SetLocalDescriptionWithDataChannel() {
1358 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001359 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 SetLocalDescriptionWithoutError(offer);
1361 }
1362
wu@webrtc.org91053e72013-08-10 07:18:04 +00001363 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001364 RTCCertificateGenerationMethod cert_gen_method,
1365 CreateSessionDescriptionRequest::Type type) {
1366 InitWithDtls(cert_gen_method);
1367 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1368 }
1369
1370 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1371 CreateSessionDescriptionRequest::Type type) {
1372 InitWithDtlsIdentityGenFail();
1373 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1374 }
1375
1376 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001377 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001378 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001379 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001380 if (type == CreateSessionDescriptionRequest::kAnswer) {
1381 cricket::MediaSessionOptions options;
1382 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001383 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 ASSERT_TRUE(offer.get() != NULL);
1385 SetRemoteDescriptionWithoutError(offer.release());
1386 }
1387
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001388 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001389 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001391 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001392 observers[kNumber];
1393 for (int i = 0; i < kNumber; ++i) {
1394 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1395 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001396 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001398 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001399 }
1400 }
1401
1402 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1403 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1404 WebRtcSessionCreateSDPObserverForTest::kFailed;
1405
1406 for (int i = 0; i < kNumber; ++i) {
1407 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1408 if (success) {
1409 EXPECT_TRUE(observers[i]->description() != NULL);
1410 } else {
1411 EXPECT_TRUE(observers[i]->description() == NULL);
1412 }
1413 }
1414 }
1415
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001416 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001417 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001418 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001419 turn_server.credentials = credentials;
1420 turn_server.ports.push_back(
1421 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1422 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001423 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001424 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001425 }
1426
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 cricket::FakeMediaEngine* media_engine_;
1428 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001429 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001430 cricket::FakeCall fake_call_;
1431 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001432 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001433 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1434 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1435 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1436 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1437 rtc::SocketServerScope ss_scope_;
1438 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001439 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001440 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001441 rtc::FakeNetworkManager network_manager_;
1442 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001443 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001444 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001445 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 MockIceObserver observer_;
1447 cricket::FakeVideoMediaChannel* video_channel_;
1448 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001449 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001450 // The following flags affect options created for CreateOffer/CreateAnswer.
1451 bool send_stream_1_ = false;
1452 bool send_stream_2_ = false;
1453 bool send_audio_ = false;
1454 bool send_video_ = false;
1455 rtc::scoped_refptr<DataChannel> data_channel_;
1456 // Last values received from data channel creation signal.
1457 std::string last_data_channel_label_;
1458 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001459 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460};
1461
Henrik Boström87713d02015-08-25 09:53:21 +02001462TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1463 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001464 // SDES is disabled when DTLS is on.
1465 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466}
1467
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001468TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001469 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001470 // SDES is required if DTLS is off.
1471 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001472}
1473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1475 TestSessionCandidatesWithBundleRtcpMux(false, false);
1476}
1477
1478// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1479// with rtcp-mux and/or bundle.
1480TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1481 TestSessionCandidatesWithBundleRtcpMux(false, true);
1482}
1483
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1485 TestSessionCandidatesWithBundleRtcpMux(true, true);
1486}
1487
1488TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001489 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1490 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001491 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001492 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 InitiateCall();
1494 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1495 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1496 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1497}
1498
minyuec8930ba2016-01-22 06:17:46 -08001499// Crashes on Win only. See webrtc:5411.
1500#if defined(WEBRTC_WIN)
1501#define MAYBE_TestStunError DISABLED_TestStunError
1502#else
1503#define MAYBE_TestStunError TestStunError
1504#endif
1505TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001506 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1507 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001508 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001509 rtc::FP_UDP,
1510 rtc::FD_ANY,
1511 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001512 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001513 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001515 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1517 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1518 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1519}
1520
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001521// Test session delivers no candidates gathered when constraint set to "none".
1522TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1523 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001524 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001525 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001526 InitiateCall();
1527 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1528 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1529 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1530}
1531
1532// Test session delivers only relay candidates gathered when constaint set to
1533// "relay".
1534TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1535 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1536 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001537 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001538 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001539 InitiateCall();
1540 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1541 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1542 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1543 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1544 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1545 observer_.mline_0_candidates_[i].type());
1546 }
1547 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1548 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1549 observer_.mline_1_candidates_[i].type());
1550 }
1551}
1552
1553// Test session delivers all candidates gathered when constaint set to "all".
1554TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1555 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001556 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001557 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001558 InitiateCall();
1559 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1560 // Host + STUN. By default allocator is disabled to gather relay candidates.
1561 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1562 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1563}
1564
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001565TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001566 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001567 SessionDescriptionInterface* offer = NULL;
1568 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1569 std::string unknown_action;
1570 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1571 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1572}
1573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574// Test creating offers and receive answers and make sure the
1575// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001576TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001577 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001578 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001579 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 const std::string session_id_orig = offer->session_id();
1581 const std::string session_version_orig = offer->session_version();
1582 SetLocalDescriptionWithoutError(offer);
1583
deadbeefab9b2d12015-10-14 11:33:11 -07001584 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 SessionDescriptionInterface* answer =
1586 CreateRemoteAnswer(session_->local_description());
1587 SetRemoteDescriptionWithoutError(answer);
1588
1589 video_channel_ = media_engine_->GetVideoChannel(0);
1590 voice_channel_ = media_engine_->GetVoiceChannel(0);
1591
1592 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1593 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1594
1595 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1596 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1597
1598 ASSERT_EQ(1u, video_channel_->send_streams().size());
1599 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1600 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1601 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1602
1603 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001604 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001605 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606
1607 // Verify the session id is the same and the session version is
1608 // increased.
1609 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001610 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1611 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612
1613 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001614 EXPECT_EQ(0u, video_channel_->send_streams().size());
1615 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 answer = CreateRemoteAnswer(session_->local_description());
1619 SetRemoteDescriptionWithoutError(answer);
1620
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 // Make sure the receive streams have not changed.
1622 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1623 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1624 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1625 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1626}
1627
1628// Test receiving offers and creating answers and make sure the
1629// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001630TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001631 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001632 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001633 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001634 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 SetRemoteDescriptionWithoutError(offer);
1636
deadbeefab9b2d12015-10-14 11:33:11 -07001637 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001638 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001639 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 SetLocalDescriptionWithoutError(answer);
1641
1642 const std::string session_id_orig = answer->session_id();
1643 const std::string session_version_orig = answer->session_version();
1644
1645 video_channel_ = media_engine_->GetVideoChannel(0);
1646 voice_channel_ = media_engine_->GetVoiceChannel(0);
1647
1648 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1649 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1650
1651 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1652 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1653
1654 ASSERT_EQ(1u, video_channel_->send_streams().size());
1655 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1656 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1657 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1658
deadbeefab9b2d12015-10-14 11:33:11 -07001659 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 SetRemoteDescriptionWithoutError(offer);
1662
1663 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001664 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001665 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666
1667 // Verify the session id is the same and the session version is
1668 // increased.
1669 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001670 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1671 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 SetLocalDescriptionWithoutError(answer);
1673
1674 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1675 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1676 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1677 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1678 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1679 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1680
1681 // Make sure we have no send streams.
1682 EXPECT_EQ(0u, video_channel_->send_streams().size());
1683 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1684}
1685
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001686TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001687 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001688 media_engine_->set_fail_create_channel(true);
1689
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001690 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001691 ASSERT_TRUE(offer != NULL);
1692 // SetRemoteDescription and SetLocalDescription will take the ownership of
1693 // the offer.
1694 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001695 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001696 ASSERT_TRUE(offer != NULL);
1697 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1698}
1699
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001700//
1701// Tests for creating/setting SDP under different SDES/DTLS polices:
1702//
1703// --DTLS off and SDES on
1704// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1705// set local/remote offer/answer with crypto --> success
1706// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1707// failure
1708// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1709// failure
1710// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1711// failure
1712//
1713// --DTLS on and SDES off
1714// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1715// set local/remote offer/answer with DTLS fingerprint --> success
1716// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1717// fingerprint --> failure
1718// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1719// --> failure
1720// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1721// --> failure
1722//
1723// --Encryption disabled: DTLS off and SDES off
1724// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1725// answer without SDES or DTLS --> success
1726// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1727// answer without SDES or DTLS --> success
1728//
1729
1730// Test that we return a failure when applying a remote/local offer that doesn't
1731// have cryptos enabled when DTLS is off.
1732TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001733 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001735 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 JsepSessionDescription* offer = CreateRemoteOffer(
1737 options, cricket::SEC_DISABLED);
1738 ASSERT_TRUE(offer != NULL);
1739 VerifyNoCryptoParams(offer->description(), false);
1740 // SetRemoteDescription and SetLocalDescription will take the ownership of
1741 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1744 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001745 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746}
1747
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001748// Test that we return a failure when applying a local answer that doesn't have
1749// cryptos enabled when DTLS is off.
1750TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001751 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 SessionDescriptionInterface* offer = NULL;
1753 SessionDescriptionInterface* answer = NULL;
1754 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1755 // SetRemoteDescription and SetLocalDescription will take the ownership of
1756 // the offer.
1757 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759}
1760
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001761// Test we will return fail when apply an remote answer that doesn't have
1762// crypto enabled when DTLS is off.
1763TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 SessionDescriptionInterface* offer = NULL;
1766 SessionDescriptionInterface* answer = NULL;
1767 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1768 // SetRemoteDescription and SetLocalDescription will take the ownership of
1769 // the offer.
1770 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001771 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772}
1773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1775// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001776TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
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.org28e20752013-07-10 00:45:36 +00001780 SetFactoryDtlsSrtp();
1781 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001782 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 JsepSessionDescription* offer =
1784 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 ASSERT_TRUE(offer != NULL);
1786 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788
1789 // SetRemoteDescription will take the ownership of the offer.
1790 SetRemoteDescriptionWithoutError(offer);
1791
1792 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001793 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 ASSERT_TRUE(answer != NULL);
1795 VerifyFingerprintStatus(answer->description(), true);
1796 // Check that we don't have an a=crypto line in the answer.
1797 VerifyNoCryptoParams(answer->description(), true);
1798
1799 // Now set the local description, which should work, even without a=crypto.
1800 SetLocalDescriptionWithoutError(answer);
1801}
1802
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1804// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001805TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001806 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001807 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001808 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001809 SetFactoryDtlsSrtp();
1810
1811 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001812 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001813 ASSERT_TRUE(offer != NULL);
1814 VerifyFingerprintStatus(offer->description(), true);
1815 // Check that we don't have an a=crypto line in the offer.
1816 VerifyNoCryptoParams(offer->description(), true);
1817
1818 // Now set the local description, which should work, even without a=crypto.
1819 SetLocalDescriptionWithoutError(offer);
1820
1821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001822 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 JsepSessionDescription* answer =
1824 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1825 ASSERT_TRUE(answer != NULL);
1826 VerifyFingerprintStatus(answer->description(), true);
1827 VerifyNoCryptoParams(answer->description(), true);
1828
1829 // SetRemoteDescription will take the ownership of the answer.
1830 SetRemoteDescriptionWithoutError(answer);
1831}
1832
1833// Test that if we support DTLS and the other side didn't offer a fingerprint,
1834// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001835TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001836 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001837 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001839 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 JsepSessionDescription* offer = CreateRemoteOffer(
1842 options, cricket::SEC_REQUIRED);
1843 ASSERT_TRUE(offer != NULL);
1844 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001847 // SetRemoteDescription will take the ownership of the offer.
1848 SetRemoteDescriptionOfferExpectError(
1849 kSdpWithoutDtlsFingerprint, offer);
1850
1851 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1852 // SetLocalDescription will take the ownership of the offer.
1853 SetLocalDescriptionOfferExpectError(
1854 kSdpWithoutDtlsFingerprint, offer);
1855}
1856
1857// Test that we return a failure when applying a local answer that doesn't have
1858// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001859TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001860 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001861 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 SessionDescriptionInterface* offer = NULL;
1863 SessionDescriptionInterface* answer = NULL;
1864 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1865
1866 // SetRemoteDescription and SetLocalDescription will take the ownership of
1867 // the offer and answer.
1868 SetRemoteDescriptionWithoutError(offer);
1869 SetLocalDescriptionAnswerExpectError(
1870 kSdpWithoutDtlsFingerprint, answer);
1871}
1872
1873// Test that we return a failure when applying a remote answer that doesn't have
1874// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001875TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001876 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001877 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001878 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001880 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001881 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1882 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001884 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885
1886 // SetRemoteDescription and SetLocalDescription will take the ownership of
1887 // the offer and answer.
1888 SetLocalDescriptionWithoutError(offer);
1889 SetRemoteDescriptionAnswerExpectError(
1890 kSdpWithoutDtlsFingerprint, answer);
1891}
1892
1893// Test that we create a local offer without SDES or DTLS and accept a remote
1894// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001895TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001896 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001897 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001898 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899
1900 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001901 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001902 ASSERT_TRUE(offer != NULL);
1903 VerifyFingerprintStatus(offer->description(), false);
1904 // Check that we don't have an a=crypto line in the offer.
1905 VerifyNoCryptoParams(offer->description(), false);
1906
1907 // Now set the local description, which should work, even without a=crypto.
1908 SetLocalDescriptionWithoutError(offer);
1909
1910 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001911 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 JsepSessionDescription* answer =
1913 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1914 ASSERT_TRUE(answer != NULL);
1915 VerifyFingerprintStatus(answer->description(), false);
1916 VerifyNoCryptoParams(answer->description(), false);
1917
1918 // SetRemoteDescription will take the ownership of the answer.
1919 SetRemoteDescriptionWithoutError(answer);
1920}
1921
1922// Test that we create a local answer without SDES or DTLS and accept a remote
1923// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001924TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001925 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001926 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001927
1928 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001929 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001930 JsepSessionDescription* offer =
1931 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1932 ASSERT_TRUE(offer != NULL);
1933 VerifyFingerprintStatus(offer->description(), false);
1934 VerifyNoCryptoParams(offer->description(), false);
1935
1936 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 SetRemoteDescriptionWithoutError(offer);
1938
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001940 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 ASSERT_TRUE(answer != NULL);
1942 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001943 // Check that we don't have an a=crypto line in the answer.
1944 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001946 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 SetLocalDescriptionWithoutError(answer);
1948}
1949
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001950// Test that we can create and set an answer correctly when different
1951// SSL roles have been negotiated for different transports.
1952// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1953TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1954 SendAudioVideoStream1();
1955 InitWithDtls(GetParam());
1956 SetFactoryDtlsSrtp();
1957
1958 SessionDescriptionInterface* offer = CreateOffer();
1959 SetLocalDescriptionWithoutError(offer);
1960
1961 cricket::MediaSessionOptions options;
1962 options.recv_video = true;
1963
1964 // First, negotiate different SSL roles.
1965 SessionDescriptionInterface* answer =
1966 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1967 TransportInfo* audio_transport_info =
1968 answer->description()->GetTransportInfoByName("audio");
1969 audio_transport_info->description.connection_role =
1970 cricket::CONNECTIONROLE_ACTIVE;
1971 TransportInfo* video_transport_info =
1972 answer->description()->GetTransportInfoByName("video");
1973 video_transport_info->description.connection_role =
1974 cricket::CONNECTIONROLE_PASSIVE;
1975 SetRemoteDescriptionWithoutError(answer);
1976
1977 // Now create an offer in the reverse direction, and ensure the initial
1978 // offerer responds with an answer with correct SSL roles.
1979 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1980 kSessionVersion,
1981 session_->remote_description());
1982 SetRemoteDescriptionWithoutError(offer);
1983
1984 answer = CreateAnswer(nullptr);
1985 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1986 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1987 audio_transport_info->description.connection_role);
1988 video_transport_info = answer->description()->GetTransportInfoByName("video");
1989 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1990 video_transport_info->description.connection_role);
1991 SetLocalDescriptionWithoutError(answer);
1992
1993 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1994 // audio is transferred over to video in the answer that completes the BUNDLE
1995 // negotiation.
1996 options.bundle_enabled = true;
1997 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1998 kSessionVersion,
1999 session_->remote_description());
2000 SetRemoteDescriptionWithoutError(offer);
2001 answer = CreateAnswer(nullptr);
2002 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2003 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2004 audio_transport_info->description.connection_role);
2005 video_transport_info = answer->description()->GetTransportInfoByName("video");
2006 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2007 video_transport_info->description.connection_role);
2008 SetLocalDescriptionWithoutError(answer);
2009}
2010
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002012 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002013 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SetLocalDescriptionWithoutError(offer);
2017
2018 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002019 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 SetLocalDescriptionWithoutError(offer2);
2021}
2022
2023TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002024 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002025 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002027 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 SetRemoteDescriptionWithoutError(offer);
2029
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetRemoteDescriptionWithoutError(offer2);
2032}
2033
2034TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002035 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002037 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002039 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2041 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042}
2043
2044TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002049 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002050 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002051 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052}
2053
2054TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002055 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002058 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059
2060 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002061 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002063 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002067 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2069
deadbeefd59daf82015-10-14 15:02:44 -07002070 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002073 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002074 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075}
2076
2077TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002078 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002079 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002080 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002081 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
2083 JsepSessionDescription* pranswer =
2084 CreateRemoteAnswer(session_->local_description());
2085 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2086
2087 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002088 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089
deadbeefab9b2d12015-10-14 11:33:11 -07002090 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 JsepSessionDescription* pranswer2 =
2092 CreateRemoteAnswer(session_->local_description());
2093 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2094
2095 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002096 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
deadbeefab9b2d12015-10-14 11:33:11 -07002098 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 SessionDescriptionInterface* answer =
2100 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002101 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102}
2103
2104TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002105 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002106 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002107 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2108
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 SessionDescriptionInterface* answer =
2110 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002111 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2112 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113}
2114
2115TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002116 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002117 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002118 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 SessionDescriptionInterface* answer =
2121 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002122 SetRemoteDescriptionAnswerExpectError(
2123 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124}
2125
2126TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002127 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002128 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129
2130 cricket::Candidate candidate;
2131 candidate.set_component(1);
2132 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2133
deadbeefd59daf82015-10-14 15:02:44 -07002134 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2136
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002137 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002139
2140 // Fail since we have not set a remote description.
2141 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142
2143 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2144 session_->local_description());
2145 SetRemoteDescriptionWithoutError(answer);
2146
deadbeefd59daf82015-10-14 15:02:44 -07002147 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2148 candidate.set_component(2);
2149 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2150 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 // Verifying the candidates are copied properly from internal vector.
2153 const SessionDescriptionInterface* remote_desc =
2154 session_->remote_description();
2155 ASSERT_TRUE(remote_desc != NULL);
2156 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2157 const IceCandidateCollection* candidates =
2158 remote_desc->candidates(kMediaContentIndex0);
2159 ASSERT_EQ(2u, candidates->count());
2160 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2161 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2162 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2163 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2164
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002165 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2166 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 candidate.set_component(2);
2168 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2169 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002170 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171
2172 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2173 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2174}
2175
2176// Test that a remote candidate is added to the remote session description and
2177// that it is retained if the remote session description is changed.
2178TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002179 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 cricket::Candidate candidate1;
2181 candidate1.set_component(1);
2182 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2183 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002184 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 CreateAndSetRemoteOfferAndLocalAnswer();
2186
2187 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2188 const SessionDescriptionInterface* remote_desc =
2189 session_->remote_description();
2190 ASSERT_TRUE(remote_desc != NULL);
2191 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2192 const IceCandidateCollection* candidates =
2193 remote_desc->candidates(kMediaContentIndex0);
2194 ASSERT_EQ(1u, candidates->count());
2195 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2196
2197 // Update the RemoteSessionDescription with a new session description and
2198 // a candidate and check that the new remote session description contains both
2199 // candidates.
2200 SessionDescriptionInterface* offer = CreateRemoteOffer();
2201 cricket::Candidate candidate2;
2202 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2203 candidate2);
2204 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2205 SetRemoteDescriptionWithoutError(offer);
2206
2207 remote_desc = session_->remote_description();
2208 ASSERT_TRUE(remote_desc != NULL);
2209 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2210 candidates = remote_desc->candidates(kMediaContentIndex0);
2211 ASSERT_EQ(2u, candidates->count());
2212 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2213 // Username and password have be updated with the TransportInfo of the
2214 // SessionDescription, won't be equal to the original one.
2215 candidate2.set_username(candidates->at(0)->candidate().username());
2216 candidate2.set_password(candidates->at(0)->candidate().password());
2217 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2218 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2219 // No need to verify the username and password.
2220 candidate1.set_username(candidates->at(1)->candidate().username());
2221 candidate1.set_password(candidates->at(1)->candidate().password());
2222 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2223
2224 // Test that the candidate is ignored if we can add the same candidate again.
2225 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2226}
2227
2228// Test that local candidates are added to the local session description and
2229// that they are retained if the local session description is changed.
2230TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002231 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002232 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002233 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 CreateAndSetRemoteOfferAndLocalAnswer();
2235
2236 const SessionDescriptionInterface* local_desc = session_->local_description();
2237 const IceCandidateCollection* candidates =
2238 local_desc->candidates(kMediaContentIndex0);
2239 ASSERT_TRUE(candidates != NULL);
2240 EXPECT_EQ(0u, candidates->count());
2241
2242 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2243
2244 local_desc = session_->local_description();
2245 candidates = local_desc->candidates(kMediaContentIndex0);
2246 ASSERT_TRUE(candidates != NULL);
2247 EXPECT_LT(0u, candidates->count());
2248 candidates = local_desc->candidates(1);
2249 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002250 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251
2252 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002253 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 CreateAndSetRemoteOfferAndLocalAnswer();
2255
2256 local_desc = session_->local_description();
2257 candidates = local_desc->candidates(kMediaContentIndex0);
2258 ASSERT_TRUE(candidates != NULL);
2259 EXPECT_LT(0u, candidates->count());
2260 candidates = local_desc->candidates(1);
2261 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002262 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263}
2264
2265// Test that we can set a remote session description with remote candidates.
2266TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002267 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268
2269 cricket::Candidate candidate1;
2270 candidate1.set_component(1);
2271 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2272 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002273 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002274 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275
2276 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2277 SetRemoteDescriptionWithoutError(offer);
2278
2279 const SessionDescriptionInterface* remote_desc =
2280 session_->remote_description();
2281 ASSERT_TRUE(remote_desc != NULL);
2282 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2283 const IceCandidateCollection* candidates =
2284 remote_desc->candidates(kMediaContentIndex0);
2285 ASSERT_EQ(1u, candidates->count());
2286 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2287
wu@webrtc.org91053e72013-08-10 07:18:04 +00002288 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 SetLocalDescriptionWithoutError(answer);
2290}
2291
2292// Test that offers and answers contains ice candidates when Ice candidates have
2293// been gathered.
2294TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002295 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002296 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002297 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 // Ice is started but candidates are not provided until SetLocalDescription
2299 // is called.
2300 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2301 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2302 CreateAndSetRemoteOfferAndLocalAnswer();
2303 // Wait until at least one local candidate has been collected.
2304 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2305 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002307 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2308
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2310 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311
2312 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2313 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002314 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2316 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 SetLocalDescriptionWithoutError(answer);
2318}
2319
2320// Verifies TransportProxy and media channels are created with content names
2321// present in the SessionDescription.
2322TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002323 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002324 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002325 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326
2327 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002328 // "video". Goal is to modify these content names and verify transport
2329 // channels
2330 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 // present in SDP.
2332 std::string sdp;
2333 EXPECT_TRUE(offer->ToString(&sdp));
2334 const std::string kAudioMid = "a=mid:audio";
2335 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2336 const std::string kVideoMid = "a=mid:video";
2337 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2338
2339 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002340 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 kAudioMidReplaceStr.c_str(),
2342 kAudioMidReplaceStr.length(),
2343 &sdp);
2344 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002345 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 kVideoMidReplaceStr.c_str(),
2347 kVideoMidReplaceStr.length(),
2348 &sdp);
2349
2350 SessionDescriptionInterface* modified_offer =
2351 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2352
2353 SetRemoteDescriptionWithoutError(modified_offer);
2354
2355 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002356 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 SetLocalDescriptionWithoutError(answer);
2358
deadbeefcbecd352015-09-23 11:50:27 -07002359 cricket::TransportChannel* voice_transport_channel =
2360 session_->voice_rtp_transport_channel();
2361 EXPECT_TRUE(voice_transport_channel != NULL);
2362 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2363 cricket::TransportChannel* video_transport_channel =
2364 session_->video_rtp_transport_channel();
2365 EXPECT_TRUE(video_transport_channel != NULL);
2366 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2368 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2369}
2370
2371// Test that an offer contains the correct media content descriptions based on
2372// the send streams when no constraints have been set.
2373TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002374 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002375 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 ASSERT_TRUE(offer != NULL);
2378 const cricket::ContentInfo* content =
2379 cricket::GetFirstAudioContent(offer->description());
2380 EXPECT_TRUE(content != NULL);
2381 content = cricket::GetFirstVideoContent(offer->description());
2382 EXPECT_TRUE(content == NULL);
2383}
2384
2385// Test that an offer contains the correct media content descriptions based on
2386// the send streams when no constraints have been set.
2387TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002388 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002390 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2392
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 const cricket::ContentInfo* content =
2394 cricket::GetFirstAudioContent(offer->description());
2395 EXPECT_TRUE(content != NULL);
2396 content = cricket::GetFirstVideoContent(offer->description());
2397 EXPECT_TRUE(content == NULL);
2398
2399 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002400 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002401 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 content = cricket::GetFirstAudioContent(offer->description());
2403 EXPECT_TRUE(content != NULL);
2404 content = cricket::GetFirstVideoContent(offer->description());
2405 EXPECT_TRUE(content != NULL);
2406}
2407
2408// Test that an offer contains no media content descriptions if
2409// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2410TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002411 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002412 PeerConnectionInterface::RTCOfferAnswerOptions options;
2413 options.offer_to_receive_audio = 0;
2414 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002416 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 CreateOffer(options));
2418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 ASSERT_TRUE(offer != NULL);
2420 const cricket::ContentInfo* content =
2421 cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content == NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content == NULL);
2425}
2426
2427// Test that an offer contains only audio media content descriptions if
2428// kOfferToReceiveAudio constraints are set to true.
2429TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002431 PeerConnectionInterface::RTCOfferAnswerOptions options;
2432 options.offer_to_receive_audio =
2433 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2434
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002435 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002436 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437
2438 const cricket::ContentInfo* content =
2439 cricket::GetFirstAudioContent(offer->description());
2440 EXPECT_TRUE(content != NULL);
2441 content = cricket::GetFirstVideoContent(offer->description());
2442 EXPECT_TRUE(content == NULL);
2443}
2444
2445// Test that an offer contains audio and video media content descriptions if
2446// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2447TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002448 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002450 PeerConnectionInterface::RTCOfferAnswerOptions options;
2451 options.offer_to_receive_audio =
2452 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2453 options.offer_to_receive_video =
2454 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2455
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002456 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002457 CreateOffer(options));
2458
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 const cricket::ContentInfo* content =
2460 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002461 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002462
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 content = cricket::GetFirstVideoContent(offer->description());
2464 EXPECT_TRUE(content != NULL);
2465
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002466 // Sets constraints to false and verifies that audio/video contents are
2467 // removed.
2468 options.offer_to_receive_audio = 0;
2469 options.offer_to_receive_video = 0;
2470 offer.reset(CreateOffer(options));
2471
2472 content = cricket::GetFirstAudioContent(offer->description());
2473 EXPECT_TRUE(content == NULL);
2474 content = cricket::GetFirstVideoContent(offer->description());
2475 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476}
2477
2478// Test that an answer can not be created if the last remote description is not
2479// an offer.
2480TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002481 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002482 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 SetLocalDescriptionWithoutError(offer);
2484 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2485 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002486 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487}
2488
2489// Test that an answer contains the correct media content descriptions when no
2490// constraints have been set.
2491TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002494 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002496 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002497 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 const cricket::ContentInfo* content =
2499 cricket::GetFirstAudioContent(answer->description());
2500 ASSERT_TRUE(content != NULL);
2501 EXPECT_FALSE(content->rejected);
2502
2503 content = cricket::GetFirstVideoContent(answer->description());
2504 ASSERT_TRUE(content != NULL);
2505 EXPECT_FALSE(content->rejected);
2506}
2507
2508// Test that an answer contains the correct media content descriptions when no
2509// constraints have been set and the offer only contain audio.
2510TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002511 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 // Create a remote offer with audio only.
2513 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002514
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002515 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 CreateRemoteOffer(options));
2517 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2518 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2519
2520 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002521 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002522 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 const cricket::ContentInfo* content =
2524 cricket::GetFirstAudioContent(answer->description());
2525 ASSERT_TRUE(content != NULL);
2526 EXPECT_FALSE(content->rejected);
2527
2528 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2529}
2530
2531// Test that an answer contains the correct media content descriptions when no
2532// constraints have been set.
2533TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002534 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002536 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 SetRemoteDescriptionWithoutError(offer.release());
2538 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002539 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002540 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002541 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 const cricket::ContentInfo* content =
2543 cricket::GetFirstAudioContent(answer->description());
2544 ASSERT_TRUE(content != NULL);
2545 EXPECT_FALSE(content->rejected);
2546
2547 content = cricket::GetFirstVideoContent(answer->description());
2548 ASSERT_TRUE(content != NULL);
2549 EXPECT_FALSE(content->rejected);
2550}
2551
2552// Test that an answer contains the correct media content descriptions when
2553// constraints have been set but no stream is sent.
2554TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002555 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002557 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 SetRemoteDescriptionWithoutError(offer.release());
2559
2560 webrtc::FakeConstraints constraints_no_receive;
2561 constraints_no_receive.SetMandatoryReceiveAudio(false);
2562 constraints_no_receive.SetMandatoryReceiveVideo(false);
2563
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002564 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002565 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 const cricket::ContentInfo* content =
2567 cricket::GetFirstAudioContent(answer->description());
2568 ASSERT_TRUE(content != NULL);
2569 EXPECT_TRUE(content->rejected);
2570
2571 content = cricket::GetFirstVideoContent(answer->description());
2572 ASSERT_TRUE(content != NULL);
2573 EXPECT_TRUE(content->rejected);
2574}
2575
2576// Test that an answer contains the correct media content descriptions when
2577// constraints have been set and streams are sent.
2578TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002579 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002581 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 SetRemoteDescriptionWithoutError(offer.release());
2583
2584 webrtc::FakeConstraints constraints_no_receive;
2585 constraints_no_receive.SetMandatoryReceiveAudio(false);
2586 constraints_no_receive.SetMandatoryReceiveVideo(false);
2587
2588 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002589 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002590 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002591 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592
2593 // TODO(perkj): Should the direction be set to SEND_ONLY?
2594 const cricket::ContentInfo* content =
2595 cricket::GetFirstAudioContent(answer->description());
2596 ASSERT_TRUE(content != NULL);
2597 EXPECT_FALSE(content->rejected);
2598
2599 // TODO(perkj): Should the direction be set to SEND_ONLY?
2600 content = cricket::GetFirstVideoContent(answer->description());
2601 ASSERT_TRUE(content != NULL);
2602 EXPECT_FALSE(content->rejected);
2603}
2604
2605TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2606 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002607 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002608 PeerConnectionInterface::RTCOfferAnswerOptions options;
2609 options.offer_to_receive_audio =
2610 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2611 options.voice_activity_detection = false;
2612
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002613 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002614 CreateOffer(options));
2615
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 const cricket::ContentInfo* content =
2617 cricket::GetFirstAudioContent(offer->description());
2618 EXPECT_TRUE(content != NULL);
2619 EXPECT_TRUE(VerifyNoCNCodecs(content));
2620}
2621
2622TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2623 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002624 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002626 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 SetRemoteDescriptionWithoutError(offer.release());
2628
2629 webrtc::FakeConstraints constraints;
2630 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002631 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002632 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 const cricket::ContentInfo* content =
2634 cricket::GetFirstAudioContent(answer->description());
2635 ASSERT_TRUE(content != NULL);
2636 EXPECT_TRUE(VerifyNoCNCodecs(content));
2637}
2638
2639// This test verifies the call setup when remote answer with audio only and
2640// later updates with video.
2641TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002642 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2644 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2645
deadbeefab9b2d12015-10-14 11:33:11 -07002646 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002647 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648
2649 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2651
2652 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2653 // and answer;
2654 SetLocalDescriptionWithoutError(offer);
2655 SetRemoteDescriptionWithoutError(answer);
2656
2657 video_channel_ = media_engine_->GetVideoChannel(0);
2658 voice_channel_ = media_engine_->GetVoiceChannel(0);
2659
2660 ASSERT_TRUE(video_channel_ == NULL);
2661
2662 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2663 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2664 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2665
2666 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002667 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 CreateAndSetRemoteOfferAndLocalAnswer();
2669
2670 video_channel_ = media_engine_->GetVideoChannel(0);
2671 voice_channel_ = media_engine_->GetVoiceChannel(0);
2672
2673 ASSERT_TRUE(video_channel_ != NULL);
2674 ASSERT_TRUE(voice_channel_ != NULL);
2675
2676 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2677 ASSERT_EQ(1u, video_channel_->send_streams().size());
2678 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2679 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2680 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2681 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2682 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2683 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2684
2685 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002686 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 CreateAndSetRemoteOfferAndLocalAnswer();
2688
2689 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2690 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2691 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2692 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2694}
2695
2696// This test verifies the call setup when remote answer with video only and
2697// later updates with audio.
2698TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002699 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2701 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002702 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002703 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704
2705 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002706 options.recv_audio = false;
2707 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2709 offer, options, cricket::SEC_ENABLED);
2710
2711 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2712 // and answer.
2713 SetLocalDescriptionWithoutError(offer);
2714 SetRemoteDescriptionWithoutError(answer);
2715
2716 video_channel_ = media_engine_->GetVideoChannel(0);
2717 voice_channel_ = media_engine_->GetVoiceChannel(0);
2718
2719 ASSERT_TRUE(voice_channel_ == NULL);
2720 ASSERT_TRUE(video_channel_ != NULL);
2721
2722 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2723 ASSERT_EQ(1u, video_channel_->send_streams().size());
2724 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2725
2726 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002727 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 CreateAndSetRemoteOfferAndLocalAnswer();
2729
2730 voice_channel_ = media_engine_->GetVoiceChannel(0);
2731 ASSERT_TRUE(voice_channel_ != NULL);
2732
2733 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2734 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2735 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2736 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2737
2738 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002739 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 CreateAndSetRemoteOfferAndLocalAnswer();
2741
2742 video_channel_ = media_engine_->GetVideoChannel(0);
2743 voice_channel_ = media_engine_->GetVoiceChannel(0);
2744
2745 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2746 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2747 ASSERT_EQ(1u, video_channel_->send_streams().size());
2748 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2749}
2750
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002752 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002753 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002754 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 VerifyCryptoParams(offer->description());
2756 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002757 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002758 VerifyCryptoParams(answer->description());
2759}
2760
2761TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002762 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002763 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002764 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002765 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 VerifyNoCryptoParams(offer->description(), false);
2767}
2768
2769TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002770 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 VerifyAnswerFromNonCryptoOffer();
2772}
2773
2774TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyAnswerFromCryptoOffer();
2777}
2778
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002779// This test verifies that setLocalDescription fails if
2780// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2781TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002782 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002783 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002784 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2785
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002786 std::string sdp;
2787 RemoveIceUfragPwdLines(offer.get(), &sdp);
2788 SessionDescriptionInterface* modified_offer =
2789 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002790 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002791}
2792
2793// This test verifies that setRemoteDescription fails if
2794// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2795TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002796 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002797 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002798 std::string sdp;
2799 RemoveIceUfragPwdLines(offer.get(), &sdp);
2800 SessionDescriptionInterface* modified_offer =
2801 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002802 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002803}
2804
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002805// This test verifies that setLocalDescription fails if local offer has
2806// too short ice ufrag and pwd strings.
2807TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002808 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002809 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002810 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2811
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002812 std::string sdp;
2813 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2814 // recommended values of 4 and 22 bytes respectively.
2815 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2816 SessionDescriptionInterface* modified_offer =
2817 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2818 std::string error;
2819 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2820
2821 // Test with string greater than 256.
2822 sdp.clear();
2823 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2824 &sdp);
2825 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2826 NULL);
2827 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2828}
2829
2830// This test verifies that setRemoteDescription fails if remote offer has
2831// too short ice ufrag and pwd strings.
2832TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002833 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002834 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002835 std::string sdp;
2836 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2837 // recommended values of 4 and 22 bytes respectively.
2838 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2839 SessionDescriptionInterface* modified_offer =
2840 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2841 std::string error;
2842 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2843
2844 sdp.clear();
2845 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2846 &sdp);
2847 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2848 NULL);
2849 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2850}
2851
Honghai Zhang04e91462015-12-11 14:26:22 -08002852// Test that if the remote offer indicates the peer requested ICE restart (via
2853// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2854TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002855 Init();
2856 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2857
2858 // Create the first offer.
2859 std::string sdp;
2860 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2861 "abcdefghijklmnopqrstuvwx", &sdp);
2862 SessionDescriptionInterface* offer1 =
2863 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2864 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2865 0, "", "", "relay", 0, "");
2866 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2867 candidate1);
2868 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2869 SetRemoteDescriptionWithoutError(offer1);
2870 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2871
2872 // The second offer has the same ufrag and pwd but different address.
2873 sdp.clear();
2874 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2875 "abcdefghijklmnopqrstuvwx", &sdp);
2876 SessionDescriptionInterface* offer2 =
2877 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2878 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2879 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2880 candidate1);
2881 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2882 SetRemoteDescriptionWithoutError(offer2);
2883 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2884
2885 // The third offer has a different ufrag and different address.
2886 sdp.clear();
2887 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2888 "abcdefghijklmnopqrstuvwx", &sdp);
2889 SessionDescriptionInterface* offer3 =
2890 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2891 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2892 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2893 candidate1);
2894 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2895 SetRemoteDescriptionWithoutError(offer3);
2896 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2897
2898 // The fourth offer has no candidate but a different ufrag/pwd.
2899 sdp.clear();
2900 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2901 "abcdefghijklmnopqrstuvyz", &sdp);
2902 SessionDescriptionInterface* offer4 =
2903 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2904 SetRemoteDescriptionWithoutError(offer4);
2905 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2906}
2907
Honghai Zhang04e91462015-12-11 14:26:22 -08002908// Test that if the remote answer indicates the peer requested ICE restart (via
2909// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2910TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2911 Init();
2912 SessionDescriptionInterface* offer = CreateOffer();
2913 SetLocalDescriptionWithoutError(offer);
2914 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2915
2916 // Create the first answer.
2917 std::string sdp;
2918 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2919 "abcdefghijklmnopqrstuvwx", &sdp);
2920 SessionDescriptionInterface* answer1 =
2921 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2922 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2923 0, "", "", "relay", 0, "");
2924 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2925 candidate1);
2926 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2927 SetRemoteDescriptionWithoutError(answer1);
2928 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2929
2930 // The second answer has the same ufrag and pwd but different address.
2931 sdp.clear();
2932 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2933 "abcdefghijklmnopqrstuvwx", &sdp);
2934 SessionDescriptionInterface* answer2 =
2935 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2936 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2937 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2938 candidate1);
2939 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2940 SetRemoteDescriptionWithoutError(answer2);
2941 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2942
2943 // The third answer has a different ufrag and different address.
2944 sdp.clear();
2945 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2946 "abcdefghijklmnopqrstuvwx", &sdp);
2947 SessionDescriptionInterface* answer3 =
2948 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2949 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2950 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2951 candidate1);
2952 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2953 SetRemoteDescriptionWithoutError(answer3);
2954 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2955
2956 // The fourth answer has no candidate but a different ufrag/pwd.
2957 sdp.clear();
2958 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2959 "abcdefghijklmnopqrstuvyz", &sdp);
2960 SessionDescriptionInterface* offer4 =
2961 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2962 SetRemoteDescriptionWithoutError(offer4);
2963 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2964}
2965
Donald Curtisd4f769d2015-05-28 09:48:21 -07002966// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002967// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002968TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2969 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2970
2971 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002972 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002973
2974 PeerConnectionInterface::RTCOfferAnswerOptions options;
2975 options.use_rtp_mux = true;
2976
2977 SessionDescriptionInterface* offer = CreateRemoteOffer();
2978 SetRemoteDescriptionWithoutError(offer);
2979
2980 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2981 SetLocalDescriptionWithoutError(answer);
2982
deadbeefcbecd352015-09-23 11:50:27 -07002983 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2984 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002985
deadbeefcbecd352015-09-23 11:50:27 -07002986 cricket::BaseChannel* voice_channel = session_->voice_channel();
2987 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002988
2989 // Checks if one of the transport channels contains a connection using a given
2990 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002991 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002992 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002993 session_->GetChannelTransportStats(voice_channel, &stats);
2994 for (auto& kv : stats.transport_stats) {
2995 for (auto& chan_stat : kv.second.channel_stats) {
2996 for (auto& conn_info : chan_stat.connection_infos) {
2997 if (conn_info.remote_candidate.address().port() == port) {
2998 return true;
2999 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003000 }
3001 }
3002 }
3003 return false;
3004 };
3005
3006 EXPECT_FALSE(connection_with_remote_port(5000));
3007 EXPECT_FALSE(connection_with_remote_port(5001));
3008 EXPECT_FALSE(connection_with_remote_port(6000));
3009
3010 // The way the *_WAIT checks work is they only wait if the condition fails,
3011 // which does not help in the case where state is not changing. This is
3012 // problematic in this test since we want to verify that adding a video
3013 // candidate does _not_ change state. So we interleave candidates and assume
3014 // that messages are executed in the order they were posted.
3015
3016 // First audio candidate.
3017 cricket::Candidate candidate0;
3018 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3019 candidate0.set_component(1);
3020 candidate0.set_protocol("udp");
3021 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3022 candidate0);
3023 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3024
3025 // Video candidate.
3026 cricket::Candidate candidate1;
3027 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3028 candidate1.set_component(1);
3029 candidate1.set_protocol("udp");
3030 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3031 candidate1);
3032 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3033
3034 // Second audio candidate.
3035 cricket::Candidate candidate2;
3036 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3037 candidate2.set_component(1);
3038 candidate2.set_protocol("udp");
3039 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3040 candidate2);
3041 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3042
3043 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3044 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3045
3046 // No need here for a _WAIT check since we are checking that state hasn't
3047 // changed: if this is false we would be doing waits for nothing and if this
3048 // is true then there will be no messages processed anyways.
3049 EXPECT_FALSE(connection_with_remote_port(6000));
3050}
3051
deadbeefcbecd352015-09-23 11:50:27 -07003052// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003053TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3054 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003055 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003056
3057 PeerConnectionInterface::RTCOfferAnswerOptions options;
3058 options.use_rtp_mux = true;
3059
3060 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003062
deadbeefcbecd352015-09-23 11:50:27 -07003063 EXPECT_NE(session_->voice_rtp_transport_channel(),
3064 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003065
deadbeefab9b2d12015-10-14 11:33:11 -07003066 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003067 SessionDescriptionInterface* answer =
3068 CreateRemoteAnswer(session_->local_description());
3069 SetRemoteDescriptionWithoutError(answer);
3070
deadbeefcbecd352015-09-23 11:50:27 -07003071 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3072 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003073}
3074
deadbeefcbecd352015-09-23 11:50:27 -07003075// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003076TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3077 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003078 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003079
Donald Curtis0e209b02015-03-24 09:29:54 -07003080 PeerConnectionInterface::RTCOfferAnswerOptions options;
3081 options.use_rtp_mux = true;
3082
3083 SessionDescriptionInterface* offer = CreateOffer(options);
3084 SetLocalDescriptionWithoutError(offer);
3085
deadbeefcbecd352015-09-23 11:50:27 -07003086 EXPECT_NE(session_->voice_rtp_transport_channel(),
3087 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003088
deadbeefab9b2d12015-10-14 11:33:11 -07003089 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003090
3091 // Remove BUNDLE from the answer.
3092 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3093 CreateRemoteAnswer(session_->local_description()));
3094 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3095 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3096 JsepSessionDescription* modified_answer =
3097 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3098 modified_answer->Initialize(answer_copy, "1", "1");
3099 SetRemoteDescriptionWithoutError(modified_answer); //
3100
deadbeefcbecd352015-09-23 11:50:27 -07003101 EXPECT_NE(session_->voice_rtp_transport_channel(),
3102 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003103}
3104
3105// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3106TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3107 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003108 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003109
3110 PeerConnectionInterface::RTCOfferAnswerOptions options;
3111 options.use_rtp_mux = true;
3112
3113 SessionDescriptionInterface* offer = CreateOffer(options);
3114 SetLocalDescriptionWithoutError(offer);
3115
deadbeefcbecd352015-09-23 11:50:27 -07003116 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3117 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003118
deadbeefab9b2d12015-10-14 11:33:11 -07003119 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003120 SessionDescriptionInterface* answer =
3121 CreateRemoteAnswer(session_->local_description());
3122 SetRemoteDescriptionWithoutError(answer);
3123
deadbeefcbecd352015-09-23 11:50:27 -07003124 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3125 session_->video_rtp_transport_channel());
3126}
3127
3128// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3129// audio content in the answer.
3130TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3131 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003132 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003133
3134 PeerConnectionInterface::RTCOfferAnswerOptions options;
3135 options.use_rtp_mux = true;
3136
3137 SessionDescriptionInterface* offer = CreateOffer(options);
3138 SetLocalDescriptionWithoutError(offer);
3139
3140 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3141 session_->video_rtp_transport_channel());
3142
deadbeefab9b2d12015-10-14 11:33:11 -07003143 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003144 cricket::MediaSessionOptions recv_options;
3145 recv_options.recv_audio = false;
3146 recv_options.recv_video = true;
3147 SessionDescriptionInterface* answer =
3148 CreateRemoteAnswer(session_->local_description(), recv_options);
3149 SetRemoteDescriptionWithoutError(answer);
3150
deadbeefd59daf82015-10-14 15:02:44 -07003151 EXPECT_TRUE(nullptr == session_->voice_channel());
3152 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003153
deadbeefd59daf82015-10-14 15:02:44 -07003154 session_->Close();
3155 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3156 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3157 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3158 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003159}
3160
3161// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003165
Donald Curtis0e209b02015-03-24 09:29:54 -07003166 PeerConnectionInterface::RTCOfferAnswerOptions options;
3167 options.use_rtp_mux = true;
3168
3169 SessionDescriptionInterface* offer = CreateOffer(options);
3170 SetLocalDescriptionWithoutError(offer);
3171
deadbeefcbecd352015-09-23 11:50:27 -07003172 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3173 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003174
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003176
3177 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003178 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179 CreateRemoteAnswer(session_->local_description()));
3180 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3181 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3182 JsepSessionDescription* modified_answer =
3183 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3184 modified_answer->Initialize(answer_copy, "1", "1");
3185 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186
deadbeefcbecd352015-09-23 11:50:27 -07003187 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3188 session_->video_rtp_transport_channel());
3189}
3190
3191// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3192TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3193 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003194 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003195
3196 SessionDescriptionInterface* offer = CreateRemoteOffer();
3197 SetRemoteDescriptionWithoutError(offer);
3198
3199 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3200 session_->video_rtp_transport_channel());
3201
deadbeefab9b2d12015-10-14 11:33:11 -07003202 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003203 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3204 SetLocalDescriptionWithoutError(answer);
3205
3206 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3207 session_->video_rtp_transport_channel());
3208}
3209
3210// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3211TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3212 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003213 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003214
3215 // Remove BUNDLE from the offer.
3216 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3217 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3218 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3219 JsepSessionDescription* modified_offer =
3220 new JsepSessionDescription(JsepSessionDescription::kOffer);
3221 modified_offer->Initialize(offer_copy, "1", "1");
3222
3223 // Expect an error when applying the remote description
3224 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3225 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003226}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227
Peter Thatcher4eddf182015-04-30 10:55:59 -07003228// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003229TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3230 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003231 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232
Donald Curtis0e209b02015-03-24 09:29:54 -07003233 PeerConnectionInterface::RTCOfferAnswerOptions options;
3234 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235
Donald Curtis0e209b02015-03-24 09:29:54 -07003236 SessionDescriptionInterface* offer = CreateOffer(options);
3237 SetLocalDescriptionWithoutError(offer);
3238
deadbeefcbecd352015-09-23 11:50:27 -07003239 EXPECT_NE(session_->voice_rtp_transport_channel(),
3240 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003241
deadbeefab9b2d12015-10-14 11:33:11 -07003242 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003243 SessionDescriptionInterface* answer =
3244 CreateRemoteAnswer(session_->local_description());
3245 SetRemoteDescriptionWithoutError(answer);
3246
3247 // This should lead to an audio-only call but isn't implemented
3248 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003249 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3250 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003251}
3252
deadbeefcbecd352015-09-23 11:50:27 -07003253// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003254TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3255 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003256 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003257 PeerConnectionInterface::RTCOfferAnswerOptions options;
3258 options.use_rtp_mux = true;
3259
3260 SessionDescriptionInterface* offer = CreateOffer(options);
3261 SetLocalDescriptionWithoutError(offer);
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263 EXPECT_NE(session_->voice_rtp_transport_channel(),
3264 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003265
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003267
3268 // Remove BUNDLE from the answer.
3269 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3270 CreateRemoteAnswer(session_->local_description()));
3271 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3272 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3273 JsepSessionDescription* modified_answer =
3274 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3275 modified_answer->Initialize(answer_copy, "1", "1");
3276 SetRemoteDescriptionWithoutError(modified_answer); //
3277
deadbeefcbecd352015-09-23 11:50:27 -07003278 EXPECT_NE(session_->voice_rtp_transport_channel(),
3279 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280}
3281
Peter Thatcher4eddf182015-04-30 10:55:59 -07003282// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3283TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3284 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003285 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003286
3287 PeerConnectionInterface::RTCOfferAnswerOptions options;
3288 options.use_rtp_mux = true;
3289
3290 SessionDescriptionInterface* offer = CreateOffer(options);
3291 SetRemoteDescriptionWithoutError(offer);
3292
deadbeefcbecd352015-09-23 11:50:27 -07003293 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3294 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003295}
3296
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003297TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3298 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003299 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003300
3301 PeerConnectionInterface::RTCOfferAnswerOptions options;
3302 SessionDescriptionInterface* offer = CreateOffer(options);
3303 SetLocalDescriptionWithoutError(offer);
3304
deadbeefcbecd352015-09-23 11:50:27 -07003305 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3306 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003307
deadbeefab9b2d12015-10-14 11:33:11 -07003308 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003309 SessionDescriptionInterface* answer =
3310 CreateRemoteAnswer(session_->local_description());
3311 SetRemoteDescriptionWithoutError(answer);
3312
deadbeefcbecd352015-09-23 11:50:27 -07003313 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3314 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003315}
3316
3317TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3318 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003319 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003320
3321 PeerConnectionInterface::RTCOfferAnswerOptions options;
3322 SessionDescriptionInterface* offer = CreateOffer(options);
3323 SetLocalDescriptionWithoutError(offer);
3324
deadbeefcbecd352015-09-23 11:50:27 -07003325 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3326 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003327
deadbeefab9b2d12015-10-14 11:33:11 -07003328 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003329 SessionDescriptionInterface* answer =
3330 CreateRemoteAnswer(session_->local_description());
3331 SetRemoteDescriptionWithoutError(answer);
3332
deadbeefcbecd352015-09-23 11:50:27 -07003333 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3334 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003335}
3336
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003337// This test verifies that SetLocalDescription and SetRemoteDescription fails
3338// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3339TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003340 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003341 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003342
3343 PeerConnectionInterface::RTCOfferAnswerOptions options;
3344 options.use_rtp_mux = true;
3345
3346 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003347 std::string offer_str;
3348 offer->ToString(&offer_str);
3349 // Disable rtcp-mux
3350 const std::string rtcp_mux = "rtcp-mux";
3351 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003352 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003353 xrtcp_mux.c_str(), xrtcp_mux.length(),
3354 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003355 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003356 new JsepSessionDescription(JsepSessionDescription::kOffer);
3357 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003358 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003359 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003360 new JsepSessionDescription(JsepSessionDescription::kOffer);
3361 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003362 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003363 // Trying unmodified SDP.
3364 SetLocalDescriptionWithoutError(offer);
3365}
3366
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003368 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003369 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370 CreateAndSetRemoteOfferAndLocalAnswer();
3371 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3372 ASSERT_TRUE(channel != NULL);
3373 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003374 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003375 double volume;
3376 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3377 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003378 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003379 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3380 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003381 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003382 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3383 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384}
3385
3386TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003387 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003388 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389 CreateAndSetRemoteOfferAndLocalAnswer();
3390 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3391 ASSERT_TRUE(channel != NULL);
3392 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003393 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3395
3396 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003397 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003399 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003400 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003401 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003402 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003403 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003405 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003406 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003408 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003409 EXPECT_TRUE(renderer->sink() == NULL);
3410}
3411
3412TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003413 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003414 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003415 CreateAndSetRemoteOfferAndLocalAnswer();
3416 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3417 ASSERT_TRUE(channel != NULL);
3418 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003419 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003420
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003421 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003422 cricket::AudioOptions options;
3423 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3424 EXPECT_TRUE(renderer->sink() != NULL);
3425
3426 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3427 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3428 // SetSink(NULL) callback afterwards.
3429 renderer.reset();
3430
3431 // This will trigger SetSink(NULL) if no OnClose() callback.
3432 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433}
3434
3435TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003436 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003437 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 CreateAndSetRemoteOfferAndLocalAnswer();
3439 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3440 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003441 ASSERT_LT(0u, channel->sinks().size());
3442 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003444 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 cricket::FakeVideoRenderer renderer;
3446 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003447 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003449 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450}
3451
3452TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003453 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003454 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 CreateAndSetRemoteOfferAndLocalAnswer();
3456 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3457 ASSERT_TRUE(channel != NULL);
3458 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003459 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3461 cricket::VideoOptions* options = NULL;
3462 session_->SetVideoSend(send_ssrc, false, options);
3463 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3464 session_->SetVideoSend(send_ssrc, true, options);
3465 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3466}
3467
3468TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3469 TestCanInsertDtmf(false);
3470}
3471
3472TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3473 TestCanInsertDtmf(true);
3474}
3475
3476TEST_F(WebRtcSessionTest, InsertDtmf) {
3477 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003478 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003479 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 CreateAndSetRemoteOfferAndLocalAnswer();
3481 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3482 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3483
3484 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 const int expected_duration = 90;
3486 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3487 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3488 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3489
3490 // Verify
3491 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003492 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003494 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003496 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003498 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499}
3500
deadbeefd59daf82015-10-14 15:02:44 -07003501// This test verifies the |initial_offerer| flag when session initiates the
3502// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003504 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003506 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3508 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003509 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003511 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512}
3513
deadbeefd59daf82015-10-14 15:02:44 -07003514// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003516 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003517 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 SessionDescriptionInterface* offer = CreateRemoteOffer();
3519 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003520 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521
deadbeefd59daf82015-10-14 15:02:44 -07003522 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003524 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525}
3526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3528TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003529 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003530 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003531 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003533 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 CreateRemoteAnswer(session_->local_description()));
3535
3536 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3537 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003538 JsepSessionDescription* modified_answer =
3539 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540
3541 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3542 answer->session_id(),
3543 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003544 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545
wu@webrtc.org4e393072014-04-07 17:04:35 +00003546 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547 std::string sdp;
3548 EXPECT_TRUE(answer->ToString(&sdp));
3549 const std::string kAudioMid = "a=mid:audio";
3550 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003551 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 kAudioMidReplaceStr.c_str(),
3553 kAudioMidReplaceStr.length(),
3554 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003555 SessionDescriptionInterface* modified_answer1 =
3556 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003557 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558
wu@webrtc.org4e393072014-04-07 17:04:35 +00003559 // Different media types.
3560 EXPECT_TRUE(answer->ToString(&sdp));
3561 const std::string kAudioMline = "m=audio";
3562 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003563 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003564 kAudioMlineReplaceStr.c_str(),
3565 kAudioMlineReplaceStr.length(),
3566 &sdp);
3567 SessionDescriptionInterface* modified_answer2 =
3568 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3569 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3570
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 SetRemoteDescriptionWithoutError(answer.release());
3572}
3573
3574// Verifying remote offer and local answer have matching m-lines as per
3575// RFC 3264.
3576TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003577 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003578 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 SessionDescriptionInterface* offer = CreateRemoteOffer();
3580 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003581 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582
3583 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3584 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003585 JsepSessionDescription* modified_answer =
3586 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587
3588 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3589 answer->session_id(),
3590 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003591 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592 SetLocalDescriptionWithoutError(answer);
3593}
3594
3595// This test verifies that WebRtcSession does not start candidate allocation
3596// before SetLocalDescription is called.
3597TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003599 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 SessionDescriptionInterface* offer = CreateRemoteOffer();
3601 cricket::Candidate candidate;
3602 candidate.set_component(1);
3603 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3604 candidate);
3605 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3606 cricket::Candidate candidate1;
3607 candidate1.set_component(1);
3608 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3609 candidate1);
3610 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3611 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003612 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3613 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
3615 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003616 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3618 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3619
wu@webrtc.org91053e72013-08-10 07:18:04 +00003620 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003622 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3623}
3624
3625// This test verifies that crypto parameter is updated in local session
3626// description as per security policy set in MediaSessionDescriptionFactory.
3627TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003628 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003629 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003630 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
3632 // Making sure SetLocalDescription correctly sets crypto value in
3633 // SessionDescription object after de-serialization of sdp string. The value
3634 // will be set as per MediaSessionDescriptionFactory.
3635 std::string offer_str;
3636 offer->ToString(&offer_str);
3637 SessionDescriptionInterface* jsep_offer_str =
3638 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3639 SetLocalDescriptionWithoutError(jsep_offer_str);
3640 EXPECT_TRUE(session_->voice_channel()->secure_required());
3641 EXPECT_TRUE(session_->video_channel()->secure_required());
3642}
3643
3644// This test verifies the crypto parameter when security is disabled.
3645TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003646 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003647 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003648 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003649 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650
3651 // Making sure SetLocalDescription correctly sets crypto value in
3652 // SessionDescription object after de-serialization of sdp string. The value
3653 // will be set as per MediaSessionDescriptionFactory.
3654 std::string offer_str;
3655 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003656 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003657 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3658 SetLocalDescriptionWithoutError(jsep_offer_str);
3659 EXPECT_FALSE(session_->voice_channel()->secure_required());
3660 EXPECT_FALSE(session_->video_channel()->secure_required());
3661}
3662
3663// This test verifies that an answer contains new ufrag and password if an offer
3664// with new ufrag and password is received.
3665TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003666 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003668 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 CreateRemoteOffer(options));
3671 SetRemoteDescriptionWithoutError(offer.release());
3672
deadbeefab9b2d12015-10-14 11:33:11 -07003673 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003674 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003675 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 SetLocalDescriptionWithoutError(answer.release());
3677
3678 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003679 options.audio_transport_options.ice_restart = true;
3680 options.video_transport_options.ice_restart = true;
3681 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003682 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003683 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 SetRemoteDescriptionWithoutError(updated_offer1.release());
3685
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003686 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003687 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688
3689 CompareIceUfragAndPassword(updated_answer1->description(),
3690 session_->local_description()->description(),
3691 false);
3692
3693 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003694}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003695
wu@webrtc.org91053e72013-08-10 07:18:04 +00003696// This test verifies that an answer contains old ufrag and password if an offer
3697// with old ufrag and password is received.
3698TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003699 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003700 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003701 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003702 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003703 CreateRemoteOffer(options));
3704 SetRemoteDescriptionWithoutError(offer.release());
3705
deadbeefab9b2d12015-10-14 11:33:11 -07003706 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003707 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003708 CreateAnswer(NULL));
3709 SetLocalDescriptionWithoutError(answer.release());
3710
3711 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003712 options.audio_transport_options.ice_restart = false;
3713 options.video_transport_options.ice_restart = false;
3714 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003715 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003716 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003717 SetRemoteDescriptionWithoutError(updated_offer2.release());
3718
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003719 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003720 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003721
3722 CompareIceUfragAndPassword(updated_answer2->description(),
3723 session_->local_description()->description(),
3724 true);
3725
3726 SetLocalDescriptionWithoutError(updated_answer2.release());
3727}
3728
3729TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003730 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003731 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003732 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003733 const std::string session_id_orig = offer->session_id();
3734 const std::string session_version_orig = offer->session_version();
3735 SetLocalDescriptionWithoutError(offer);
3736
3737 video_channel_ = media_engine_->GetVideoChannel(0);
3738 video_channel_->set_fail_set_send_codecs(true);
3739
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003740 SessionDescriptionInterface* answer =
3741 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003742 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003743
3744 // Test that after a content error, setting any description will
3745 // result in an error.
3746 video_channel_->set_fail_set_send_codecs(false);
3747 answer = CreateRemoteAnswer(session_->local_description());
3748 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3749 offer = CreateRemoteOffer();
3750 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751}
3752
3753// Runs the loopback call test with BUNDLE and STUN disabled.
3754TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3755 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003756 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003757 cricket::PORTALLOCATOR_DISABLE_STUN |
3758 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759 TestLoopbackCall();
3760}
3761
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003762TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003763 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003764 cricket::PORTALLOCATOR_DISABLE_STUN |
3765 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3766 cricket::PORTALLOCATOR_DISABLE_RELAY);
3767
3768 // best connection is IPv6 since it has higher network preference.
3769 LoopbackNetworkConfiguration config;
3770 config.test_ipv6_network_ = true;
3771 config.best_connection_after_initial_ice_converged_ =
3772 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3773
3774 TestLoopbackCall(config);
3775}
3776
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003777// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003778TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003779 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3780 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003781 TestLoopbackCall();
3782}
3783
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003784TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3785 constraints_.reset(new FakeConstraints());
3786 constraints_->AddOptional(
3787 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003788 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003789
3790 SetLocalDescriptionWithDataChannel();
3791 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3792}
3793
Henrik Boström87713d02015-08-25 09:53:21 +02003794TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003795 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
3797 constraints_.reset(new FakeConstraints());
3798 constraints_->AddOptional(
3799 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003800 options_.disable_sctp_data_channels = false;
3801
Henrik Boström87713d02015-08-25 09:53:21 +02003802 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003803
3804 SetLocalDescriptionWithDataChannel();
3805 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3806}
3807
Henrik Boström87713d02015-08-25 09:53:21 +02003808TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003809 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003810
Henrik Boström87713d02015-08-25 09:53:21 +02003811 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003812
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003813 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003814 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003815 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3816}
3817
Henrik Boström87713d02015-08-25 09:53:21 +02003818TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003820 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003821 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003822
3823 // Create remote offer with SCTP.
3824 cricket::MediaSessionOptions options;
3825 options.data_channel_type = cricket::DCT_SCTP;
3826 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003827 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003828 SetRemoteDescriptionWithoutError(offer);
3829
3830 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003831 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003832 EXPECT_TRUE(answer != NULL);
3833 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3834 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003835}
3836
Henrik Boström87713d02015-08-25 09:53:21 +02003837TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003838 constraints_.reset(new FakeConstraints());
3839 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003840 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003841 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003842
3843 SetLocalDescriptionWithDataChannel();
3844 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3845}
3846
Henrik Boström87713d02015-08-25 09:53:21 +02003847TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003848 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003849
Henrik Boström87713d02015-08-25 09:53:21 +02003850 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003851
3852 SetLocalDescriptionWithDataChannel();
3853 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3854}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003855
Henrik Boström87713d02015-08-25 09:53:21 +02003856TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003857 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003858 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003859 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003860
3861 SetLocalDescriptionWithDataChannel();
3862 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3863}
3864
Henrik Boström87713d02015-08-25 09:53:21 +02003865TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003866 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003867 const int new_send_port = 9998;
3868 const int new_recv_port = 7775;
3869
Henrik Boström87713d02015-08-25 09:53:21 +02003870 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003871 SetFactoryDtlsSrtp();
3872
3873 // By default, don't actually add the codecs to desc_factory_; they don't
3874 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3875 // let the session description get parsed. That'll get the proper codecs
3876 // into the stream.
3877 cricket::MediaSessionOptions options;
3878 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3879 "stream1", new_send_port, options);
3880
3881 // SetRemoteDescription will take the ownership of the offer.
3882 SetRemoteDescriptionWithoutError(offer);
3883
3884 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3885 new_recv_port, CreateAnswer(NULL));
3886 ASSERT_TRUE(answer != NULL);
3887
3888 // Now set the local description, which'll take ownership of the answer.
3889 SetLocalDescriptionWithoutError(answer);
3890
3891 // TEST PLAN: Set the port number to something new, set it in the SDP,
3892 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003893 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003894 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003895
3896 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3897 int portnum = -1;
3898 ASSERT_TRUE(ch != NULL);
3899 ASSERT_EQ(1UL, ch->send_codecs().size());
3900 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003901 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003902 ch->send_codecs()[0].name.c_str()));
3903 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3904 &portnum));
3905 EXPECT_EQ(new_send_port, portnum);
3906
3907 ASSERT_EQ(1UL, ch->recv_codecs().size());
3908 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003909 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003910 ch->recv_codecs()[0].name.c_str()));
3911 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3912 &portnum));
3913 EXPECT_EQ(new_recv_port, portnum);
3914}
3915
deadbeefab9b2d12015-10-14 11:33:11 -07003916// Verifies that when a session's DataChannel receives an OPEN message,
3917// WebRtcSession signals the DataChannel creation request with the expected
3918// config.
3919TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3920 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3921
3922 InitWithDtls(GetParam());
3923
3924 SetLocalDescriptionWithDataChannel();
3925 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3926
3927 webrtc::DataChannelInit config;
3928 config.id = 1;
3929 rtc::Buffer payload;
3930 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3931 cricket::ReceiveDataParams params;
3932 params.ssrc = config.id;
3933 params.type = cricket::DMT_CONTROL;
3934
3935 cricket::DataChannel* data_channel = session_->data_channel();
3936 data_channel->SignalDataReceived(data_channel, params, payload);
3937
3938 EXPECT_EQ("a", last_data_channel_label_);
3939 EXPECT_EQ(config.id, last_data_channel_config_.id);
3940 EXPECT_FALSE(last_data_channel_config_.negotiated);
3941 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3942 last_data_channel_config_.open_handshake_role);
3943}
3944
3945TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003946 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3947 FakeDtlsIdentityStore::GenerateCertificate();
3948
3949 PeerConnectionInterface::RTCConfiguration configuration;
3950 configuration.certificates.push_back(certificate);
3951 Init(nullptr, configuration);
3952 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3953
3954 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3955}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003956
Henrik Boström87713d02015-08-25 09:53:21 +02003957// Verifies that CreateOffer succeeds when CreateOffer is called before async
3958// identity generation is finished (even if a certificate is provided this is
3959// an async op).
3960TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3961 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3962 InitWithDtls(GetParam());
3963
Henrik Boströmd8281982015-08-27 10:12:24 +02003964 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003965 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003966 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3967
wu@webrtc.org91053e72013-08-10 07:18:04 +00003968 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003969 VerifyNoCryptoParams(offer->description(), true);
3970 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003971}
3972
3973// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003974// identity generation is finished (even if a certificate is provided this is
3975// an async op).
3976TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003978 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003979 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003980
3981 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003982 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003983 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003984 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003985 ASSERT_TRUE(offer.get() != NULL);
3986 SetRemoteDescriptionWithoutError(offer.release());
3987
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003988 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003990 VerifyNoCryptoParams(answer->description(), true);
3991 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003992}
3993
3994// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003995// identity generation is finished (even if a certificate is provided this is
3996// an async op).
3997TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003998 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003999 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004000
Henrik Boströmd8281982015-08-27 10:12:24 +02004001 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004002
4003 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004004 EXPECT_TRUE(offer != NULL);
4005}
4006
4007// Verifies that CreateOffer fails when CreateOffer is called after async
4008// identity generation fails.
4009TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004010 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004011 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004012
Henrik Boströmd8281982015-08-27 10:12:24 +02004013 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004014
4015 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004016 EXPECT_TRUE(offer == NULL);
4017}
4018
4019// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4020// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004021TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004022 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004023 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004024 VerifyMultipleAsyncCreateDescription(GetParam(),
4025 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004026}
4027
4028// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4029// before async identity generation fails.
4030TEST_F(WebRtcSessionTest,
4031 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004033 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4034 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035}
4036
4037// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4038// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004039TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004040 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004042 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004043 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004044}
4045
4046// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4047// before async identity generation fails.
4048TEST_F(WebRtcSessionTest,
4049 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004050 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004051 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4052 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004053}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004054
4055// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4056// offer has no SDES crypto but only DTLS fingerprint.
4057TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4058 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004059 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004060 // Create a remote offer with secured transport disabled.
4061 cricket::MediaSessionOptions options;
4062 JsepSessionDescription* offer(CreateRemoteOffer(
4063 options, cricket::SEC_DISABLED));
4064 // Adds a DTLS fingerprint to the remote offer.
4065 cricket::SessionDescription* sdp = offer->description();
4066 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4067 ASSERT_TRUE(audio != NULL);
4068 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4069 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004070 rtc::SSLFingerprint::CreateFromRfc4572(
4071 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004072 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004073 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004074}
4075
wu@webrtc.orgde305012013-10-31 15:40:38 +00004076// This test verifies DSCP is properly applied on the media channels.
4077TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4078 constraints_.reset(new FakeConstraints());
4079 constraints_->AddOptional(
4080 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004081 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004082 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004083 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004084
4085 SetLocalDescriptionWithoutError(offer);
4086
4087 video_channel_ = media_engine_->GetVideoChannel(0);
4088 voice_channel_ = media_engine_->GetVoiceChannel(0);
4089
4090 ASSERT_TRUE(video_channel_ != NULL);
4091 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004092 const cricket::AudioOptions& audio_options = voice_channel_->options();
4093 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004094 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4095 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004096}
4097
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004098TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4099 constraints_.reset(new FakeConstraints());
4100 constraints_->AddOptional(
4101 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4102 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004103 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004104 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004105 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004106
4107 SetLocalDescriptionWithoutError(offer);
4108
4109 video_channel_ = media_engine_->GetVideoChannel(0);
4110
4111 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004112 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004113 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004114}
4115
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004116TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4117 constraints_.reset(new FakeConstraints());
4118 constraints_->AddOptional(
4119 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4120 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004121 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004122 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004123 SessionDescriptionInterface* offer = CreateOffer();
4124
4125 SetLocalDescriptionWithoutError(offer);
4126
4127 voice_channel_ = media_engine_->GetVoiceChannel(0);
4128
4129 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004130 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004131 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004132}
4133
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004134// Tests that we can renegotiate new media content with ICE candidates in the
4135// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004136TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004137 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004138 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004139 SetFactoryDtlsSrtp();
4140
deadbeefab9b2d12015-10-14 11:33:11 -07004141 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004142 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004143 SetLocalDescriptionWithoutError(offer);
4144
4145 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4146 SetRemoteDescriptionWithoutError(answer);
4147
4148 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004149 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004150 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4151
4152 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004153 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004154 candidate1.set_component(1);
4155 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4156 candidate1);
4157 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4158 SetRemoteDescriptionWithoutError(offer);
4159
4160 answer = CreateAnswer(NULL);
4161 SetLocalDescriptionWithoutError(answer);
4162}
4163
4164// Tests that we can renegotiate new media content with ICE candidates separated
4165// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004166TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004167 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004168 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169 SetFactoryDtlsSrtp();
4170
deadbeefab9b2d12015-10-14 11:33:11 -07004171 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004172 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004173 SetLocalDescriptionWithoutError(offer);
4174
4175 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4176 SetRemoteDescriptionWithoutError(answer);
4177
4178 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004179 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004180 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4181 SetRemoteDescriptionWithoutError(offer);
4182
4183 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004184 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004185 candidate1.set_component(1);
4186 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4187 candidate1);
4188 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4189
4190 answer = CreateAnswer(NULL);
4191 SetLocalDescriptionWithoutError(answer);
4192}
honghaiz7f777492016-02-02 21:54:01 -08004193
4194// Flaky on Win and Mac only. See webrtc:4943
4195#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4196#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4197#else
4198#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4199#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004200// Tests that RTX codec is removed from the answer when it isn't supported
4201// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004202TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004203 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004204 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004205 std::string offer_sdp(kSdpWithRtx);
4206
4207 SessionDescriptionInterface* offer =
4208 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4209 EXPECT_TRUE(offer->ToString(&offer_sdp));
4210
4211 // Offer SDP contains the RTX codec.
4212 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4213 SetRemoteDescriptionWithoutError(offer);
4214
4215 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4216 std::string answer_sdp;
4217 answer->ToString(&answer_sdp);
4218 // Answer SDP removes the unsupported RTX codec.
4219 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4220 SetLocalDescriptionWithoutError(answer);
4221}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004222
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004223// This verifies that the voice channel after bundle has both options from video
4224// and voice channels.
4225TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4226 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004227 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004228
4229 PeerConnectionInterface::RTCOfferAnswerOptions options;
4230 options.use_rtp_mux = true;
4231
4232 SessionDescriptionInterface* offer = CreateOffer(options);
4233 SetLocalDescriptionWithoutError(offer);
4234
4235 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4236 rtc::Socket::Option::OPT_SNDBUF, 4000);
4237
4238 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4239 rtc::Socket::Option::OPT_RCVBUF, 8000);
4240
4241 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004242 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004243 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4244 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004245 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004246 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4247
deadbeefcbecd352015-09-23 11:50:27 -07004248 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004249 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4250 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004251 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004252 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4253
deadbeefcbecd352015-09-23 11:50:27 -07004254 EXPECT_NE(session_->voice_rtp_transport_channel(),
4255 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004256
deadbeefab9b2d12015-10-14 11:33:11 -07004257 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004258 SessionDescriptionInterface* answer =
4259 CreateRemoteAnswer(session_->local_description());
4260 SetRemoteDescriptionWithoutError(answer);
4261
deadbeefcbecd352015-09-23 11:50:27 -07004262 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004263 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4264 EXPECT_EQ(4000, option_val);
4265
deadbeefcbecd352015-09-23 11:50:27 -07004266 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004267 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4268 EXPECT_EQ(8000, option_val);
4269}
4270
tommi0f620f42015-07-09 03:25:02 -07004271// Test creating a session, request multiple offers, destroy the session
4272// and make sure we got success/failure callbacks for all of the requests.
4273// Background: crbug.com/507307
4274TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4275 Init();
4276
4277 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4278 PeerConnectionInterface::RTCOfferAnswerOptions options;
4279 options.offer_to_receive_audio =
4280 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004281 cricket::MediaSessionOptions session_options;
4282 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004283
4284 for (auto& o : observers) {
4285 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004286 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004287 }
4288
4289 session_.reset();
4290
tommi0f620f42015-07-09 03:25:02 -07004291 for (auto& o : observers) {
4292 // We expect to have received a notification now even if the session was
4293 // terminated. The offer creation may or may not have succeeded, but we
4294 // must have received a notification which, so the only invalid state
4295 // is kInit.
4296 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4297 }
4298}
4299
stefanc1aeaf02015-10-15 07:26:07 -07004300TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4301 TestPacketOptions();
4302}
4303
deadbeef057ecf02016-01-20 14:30:43 -08004304// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4305// is destroyed.
4306TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4307 Init();
4308 session_.reset();
4309 EXPECT_TRUE(session_destroyed_);
4310}
4311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004312// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4313// currently fails because upon disconnection and reconnection OnIceComplete is
4314// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004315
deadbeefcbecd352015-09-23 11:50:27 -07004316INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4317 WebRtcSessionTest,
4318 testing::Values(ALREADY_GENERATED,
4319 DTLS_IDENTITY_STORE));