blob: 5f4856dc610e1ff08460dbda4e05984214f0382d [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
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000767 void SetAndVerifyNumUnsignalledRecvStreams(
768 int value_set, int value_expected) {
769 constraints_.reset(new FakeConstraints());
770 constraints_->AddOptional(
771 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
772 value_set);
773 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000774 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700775 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000776 SessionDescriptionInterface* offer = CreateOffer();
777
778 SetLocalDescriptionWithoutError(offer);
779
780 video_channel_ = media_engine_->GetVideoChannel(0);
781
782 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700783 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000784 EXPECT_EQ(value_expected,
kwiberg102c6a62015-10-30 02:47:38 -0700785 video_options.unsignalled_recv_stream_limit.value_or(-1));
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
789 const cricket::SessionDescription* desc2,
790 bool expect_equal) {
791 if (desc1->contents().size() != desc2->contents().size()) {
792 EXPECT_FALSE(expect_equal);
793 return;
794 }
795
796 const cricket::ContentInfos& contents = desc1->contents();
797 cricket::ContentInfos::const_iterator it = contents.begin();
798
799 for (; it != contents.end(); ++it) {
800 const cricket::TransportDescription* transport_desc1 =
801 desc1->GetTransportDescriptionByName(it->name);
802 const cricket::TransportDescription* transport_desc2 =
803 desc2->GetTransportDescriptionByName(it->name);
804 if (!transport_desc1 || !transport_desc2) {
805 EXPECT_FALSE(expect_equal);
806 return;
807 }
808 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
809 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
810 EXPECT_FALSE(expect_equal);
811 return;
812 }
813 }
814 EXPECT_TRUE(expect_equal);
815 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000816
817 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
818 std::string *sdp) {
819 const cricket::SessionDescription* desc = current_desc->description();
820 EXPECT_TRUE(current_desc->ToString(sdp));
821
822 const cricket::ContentInfos& contents = desc->contents();
823 cricket::ContentInfos::const_iterator it = contents.begin();
824 // Replace ufrag and pwd lines with empty strings.
825 for (; it != contents.end(); ++it) {
826 const cricket::TransportDescription* transport_desc =
827 desc->GetTransportDescriptionByName(it->name);
828 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
829 + "\r\n";
830 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
831 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000832 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000833 "", 0,
834 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000835 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000836 "", 0,
837 sdp);
838 }
839 }
840
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000841 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
842 const std::string& modified_ice_ufrag,
843 const std::string& modified_ice_pwd,
844 std::string* sdp) {
845 const cricket::SessionDescription* desc = current_desc->description();
846 EXPECT_TRUE(current_desc->ToString(sdp));
847
848 const cricket::ContentInfos& contents = desc->contents();
849 cricket::ContentInfos::const_iterator it = contents.begin();
850 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
851 // |modified_ice_pwd| strings.
852 for (; it != contents.end(); ++it) {
853 const cricket::TransportDescription* transport_desc =
854 desc->GetTransportDescriptionByName(it->name);
855 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
856 + "\r\n";
857 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
858 + "\r\n";
859 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
860 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000861 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000862 mod_ufrag.c_str(), mod_ufrag.length(),
863 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000864 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000865 mod_pwd.c_str(), mod_pwd.length(),
866 sdp);
867 }
868 }
869
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 // Creates a remote offer and and applies it as a remote description,
871 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700872 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 // to decide which local and remote streams to create.
874 void CreateAndSetRemoteOfferAndLocalAnswer() {
875 SessionDescriptionInterface* offer = CreateRemoteOffer();
876 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000877 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 SetLocalDescriptionWithoutError(answer);
879 }
880 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
881 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700882 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 }
884 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700885 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 SetLocalDescriptionWithoutError(desc);
887 EXPECT_EQ(expected_state, session_->state());
888 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000889 void SetLocalDescriptionExpectError(const std::string& action,
890 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 SessionDescriptionInterface* desc) {
892 std::string error;
893 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000894 std::string sdp_type = "local ";
895 sdp_type.append(action);
896 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 EXPECT_NE(std::string::npos, error.find(expected_error));
898 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000899 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
900 SessionDescriptionInterface* desc) {
901 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
902 expected_error, desc);
903 }
904 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
905 SessionDescriptionInterface* desc) {
906 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
907 expected_error, desc);
908 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
910 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
911 }
912 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700913 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 SetRemoteDescriptionWithoutError(desc);
915 EXPECT_EQ(expected_state, session_->state());
916 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000917 void SetRemoteDescriptionExpectError(const std::string& action,
918 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 SessionDescriptionInterface* desc) {
920 std::string error;
921 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000922 std::string sdp_type = "remote ";
923 sdp_type.append(action);
924 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 EXPECT_NE(std::string::npos, error.find(expected_error));
926 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000927 void SetRemoteDescriptionOfferExpectError(
928 const std::string& expected_error, SessionDescriptionInterface* desc) {
929 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
930 expected_error, desc);
931 }
932 void SetRemoteDescriptionPranswerExpectError(
933 const std::string& expected_error, SessionDescriptionInterface* desc) {
934 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
935 expected_error, desc);
936 }
937 void SetRemoteDescriptionAnswerExpectError(
938 const std::string& expected_error, SessionDescriptionInterface* desc) {
939 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
940 expected_error, desc);
941 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942
943 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
944 SessionDescriptionInterface** nocrypto_answer) {
945 // Create a SDP without Crypto.
946 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000947 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 options.bundle_enabled = true;
949 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
950 ASSERT_TRUE(*offer != NULL);
951 VerifyCryptoParams((*offer)->description());
952
953 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
954 cricket::SEC_DISABLED);
955 EXPECT_TRUE(*nocrypto_answer != NULL);
956 }
957
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000958 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
959 SessionDescriptionInterface** nodtls_answer) {
960 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000961 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000962 options.bundle_enabled = true;
963
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000965 CreateRemoteOffer(options, cricket::SEC_ENABLED));
966
967 *nodtls_answer =
968 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
969 EXPECT_TRUE(*nodtls_answer != NULL);
970 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
971 VerifyCryptoParams((*nodtls_answer)->description());
972
973 SetFactoryDtlsSrtp();
974 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
975 ASSERT_TRUE(*offer != NULL);
976 VerifyFingerprintStatus((*offer)->description(), true);
977 VerifyCryptoParams((*offer)->description());
978 }
979
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 JsepSessionDescription* CreateRemoteOfferWithVersion(
981 cricket::MediaSessionOptions options,
982 cricket::SecurePolicy secure_policy,
983 const std::string& session_version,
984 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000985 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 const cricket::SessionDescription* cricket_desc = NULL;
987 if (current_desc) {
988 cricket_desc = current_desc->description();
989 session_id = current_desc->session_id();
990 }
991
992 desc_factory_->set_secure(secure_policy);
993 JsepSessionDescription* offer(
994 new JsepSessionDescription(JsepSessionDescription::kOffer));
995 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
996 session_id, session_version)) {
997 delete offer;
998 offer = NULL;
999 }
1000 return offer;
1001 }
1002 JsepSessionDescription* CreateRemoteOffer(
1003 cricket::MediaSessionOptions options) {
1004 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1005 kSessionVersion, NULL);
1006 }
1007 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001008 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1009 return CreateRemoteOfferWithVersion(
1010 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 }
1012 JsepSessionDescription* CreateRemoteOffer(
1013 cricket::MediaSessionOptions options,
1014 const SessionDescriptionInterface* current_desc) {
1015 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1016 kSessionVersion, current_desc);
1017 }
1018
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001019 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1020 const char* sctp_stream_name, int new_port,
1021 cricket::MediaSessionOptions options) {
1022 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001023 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1024 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001025 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1026 }
1027
1028 // Takes ownership of offer_basis (and deletes it).
1029 JsepSessionDescription* ChangeSDPSctpPort(
1030 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1031 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1032 // SessionDescription from the mutated string.
1033 const char* default_port_str = "5000";
1034 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001035 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001036 std::string offer_str;
1037 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001038 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001039 new_port_str, strlen(new_port_str),
1040 &offer_str);
1041 JsepSessionDescription* offer = new JsepSessionDescription(
1042 offer_basis->type());
1043 delete offer_basis;
1044 offer->Initialize(offer_str, NULL);
1045 return offer;
1046 }
1047
deadbeefab9b2d12015-10-14 11:33:11 -07001048 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 // before this function to decide which streams to create.
1050 JsepSessionDescription* CreateRemoteOffer() {
1051 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001052 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 return CreateRemoteOffer(options, session_->remote_description());
1054 }
1055
1056 JsepSessionDescription* CreateRemoteAnswer(
1057 const SessionDescriptionInterface* offer,
1058 cricket::MediaSessionOptions options,
1059 cricket::SecurePolicy policy) {
1060 desc_factory_->set_secure(policy);
1061 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 JsepSessionDescription* answer(
1064 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1065 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1066 options, NULL),
1067 session_id, kSessionVersion)) {
1068 delete answer;
1069 answer = NULL;
1070 }
1071 return answer;
1072 }
1073
1074 JsepSessionDescription* CreateRemoteAnswer(
1075 const SessionDescriptionInterface* offer,
1076 cricket::MediaSessionOptions options) {
1077 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1078 }
1079
deadbeefab9b2d12015-10-14 11:33:11 -07001080 // Creates an answer session description.
1081 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 // to decide which streams to create.
1083 JsepSessionDescription* CreateRemoteAnswer(
1084 const SessionDescriptionInterface* offer) {
1085 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001086 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1088 }
1089
1090 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001091 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001092 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001093 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001094
1095 PeerConnectionInterface::RTCOfferAnswerOptions options;
1096 options.use_rtp_mux = bundle;
1097
1098 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1100 // and answer.
1101 SetLocalDescriptionWithoutError(offer);
1102
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001103 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001104 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 std::string sdp;
1106 EXPECT_TRUE(answer->ToString(&sdp));
1107
1108 size_t expected_candidate_num = 2;
1109 if (!rtcp_mux) {
1110 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1111 // for rtp and rtcp.
1112 expected_candidate_num = 4;
1113 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 const std::string kRtcpMux = "a=rtcp-mux";
1115 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001116 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 kXRtcpMux.c_str(), kXRtcpMux.length(),
1118 &sdp);
1119 }
1120
1121 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1122 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123
1124 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001125 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1127 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001128 if (bundle) {
1129 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1130 } else {
1131 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 }
1133 }
1134 // Tests that we can only send DTMF when the dtmf codec is supported.
1135 void TestCanInsertDtmf(bool can) {
1136 if (can) {
1137 InitWithDtmfCodec();
1138 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001139 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 }
deadbeefab9b2d12015-10-14 11:33:11 -07001141 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 CreateAndSetRemoteOfferAndLocalAnswer();
1143 EXPECT_FALSE(session_->CanInsertDtmf(""));
1144 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1145 }
1146
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001147 // Helper class to configure loopback network and verify Best
1148 // Connection using right IP protocol for TestLoopbackCall
1149 // method. LoopbackNetworkManager applies firewall rules to block
1150 // all ping traffic once ICE completed, and remove them to observe
1151 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1152 // verifies the best connection is using the right IP protocol after
1153 // initial ICE convergences.
1154
1155 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001156 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 LoopbackNetworkConfiguration()
1158 : test_ipv6_network_(false),
1159 test_extra_ipv4_network_(false),
1160 best_connection_after_initial_ice_converged_(1, 0) {}
1161
1162 // Used to track the expected best connection count in each IP protocol.
1163 struct ExpectedBestConnection {
1164 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1165 : ipv4_count_(ipv4_count),
1166 ipv6_count_(ipv6_count) {}
1167
1168 int ipv4_count_;
1169 int ipv6_count_;
1170 };
1171
1172 bool test_ipv6_network_;
1173 bool test_extra_ipv4_network_;
1174 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1175
1176 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001177 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001178 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1179 }
1180
1181 private:
jbauchac8869e2015-07-03 01:36:14 -07001182 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 const ExpectedBestConnection& expected) const {
1184 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001185 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1186 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 expected.ipv4_count_);
1188 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001189 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1190 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001191 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001192 // This is used in the loopback call so there is only single host to host
1193 // candidate pair.
1194 EXPECT_EQ(metrics_observer->GetEnumCounter(
1195 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1196 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001197 0);
1198 EXPECT_EQ(metrics_observer->GetEnumCounter(
1199 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1200 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001201 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001202 }
1203 };
1204
1205 class LoopbackNetworkManager {
1206 public:
1207 LoopbackNetworkManager(WebRtcSessionTest* session,
1208 const LoopbackNetworkConfiguration& config)
1209 : config_(config) {
1210 session->AddInterface(
1211 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1212 if (config_.test_extra_ipv4_network_) {
1213 session->AddInterface(
1214 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1215 }
1216 if (config_.test_ipv6_network_) {
1217 session->AddInterface(
1218 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1219 }
1220 }
1221
1222 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1223 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1224 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1225 if (config_.test_extra_ipv4_network_) {
1226 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1227 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1228 }
1229 if (config_.test_ipv6_network_) {
1230 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1231 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1232 }
1233 }
1234
1235 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1236
1237 private:
1238 LoopbackNetworkConfiguration config_;
1239 };
1240
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 // The method sets up a call from the session to itself, in a loopback
1242 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001243 // disconnection, and then a permanent disconnection.
1244 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1246 // While running the call, this method also checks if the session goes through
1247 // the correct sequence of ICE states when a connection is established,
1248 // broken, and re-established.
1249 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001250 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1251 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001253
stefanc1aeaf02015-10-15 07:26:07 -07001254 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001255 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001256 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001257 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258
1259 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1260 observer_.ice_gathering_state_);
1261 SetLocalDescriptionWithoutError(offer);
1262 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1263 observer_.ice_connection_state_);
1264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001265 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1267 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001268 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269
1270 std::string sdp;
1271 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001272 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1273 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 ASSERT_TRUE(desc != NULL);
1275 SetRemoteDescriptionWithoutError(desc);
1276
1277 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001278 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001279
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001280 // The ice connection state is "Connected" too briefly to catch in a test.
1281 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001282 observer_.ice_connection_state_, kIceCandidatesTimeout);
1283 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284
stefanc1aeaf02015-10-15 07:26:07 -07001285 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1286 LoopbackNetworkManager loopback_network_manager(this, config);
1287 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001288 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 // Adding firewall rule to block ping requests, which should cause
1290 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291
1292 loopback_network_manager.ApplyFirewallRules(fss_.get());
1293
1294 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1296 observer_.ice_connection_state_,
1297 kIceCandidatesTimeout);
1298
jbauchac8869e2015-07-03 01:36:14 -07001299 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001302 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001304 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001305 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 observer_.ice_connection_state_,
1307 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001308
1309 // Now we block ping requests and wait until the ICE connection transitions
1310 // to the Failed state. This will take at least 30 seconds because it must
1311 // wait for the Port to timeout.
1312 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001313
1314 loopback_network_manager.ApplyFirewallRules(fss_.get());
1315 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001316 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001317 observer_.ice_connection_state_,
1318 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 }
1320
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001321 void TestLoopbackCall() {
1322 LoopbackNetworkConfiguration config;
1323 TestLoopbackCall(config);
1324 }
1325
stefanc1aeaf02015-10-15 07:26:07 -07001326 void TestPacketOptions() {
1327 media_controller_.reset(
1328 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1329 LoopbackNetworkConfiguration config;
1330 LoopbackNetworkManager loopback_network_manager(this, config);
1331
1332 SetupLoopbackCall();
1333
1334 uint8_t test_packet[15] = {0};
1335 rtc::PacketOptions options;
1336 options.packet_id = 10;
1337 media_engine_->GetVideoChannel(0)
1338 ->SendRtp(test_packet, sizeof(test_packet), options);
1339
1340 const int kPacketTimeout = 2000;
1341 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1342 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1343 }
1344
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1346 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001347 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1348 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1349
1350 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1352 codecs.push_back(kCNCodec1);
1353 codecs.push_back(kCNCodec2);
1354 media_engine_->SetAudioCodecs(codecs);
1355 desc_factory_->set_audio_codecs(codecs);
1356 }
1357
1358 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1359 const cricket::ContentDescription* description = content->description;
1360 ASSERT(description != NULL);
1361 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001362 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 ASSERT(audio_content_desc != NULL);
1364 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1365 if (audio_content_desc->codecs()[i].name == "CN")
1366 return false;
1367 }
1368 return true;
1369 }
1370
deadbeefab9b2d12015-10-14 11:33:11 -07001371 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001372 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001373 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1374 data_channel_ = DataChannel::Create(
1375 session_.get(), session_->data_channel_type(), "datachannel", dci);
1376 }
1377
1378 void SetLocalDescriptionWithDataChannel() {
1379 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001380 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 SetLocalDescriptionWithoutError(offer);
1382 }
1383
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001385 RTCCertificateGenerationMethod cert_gen_method,
1386 CreateSessionDescriptionRequest::Type type) {
1387 InitWithDtls(cert_gen_method);
1388 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1389 }
1390
1391 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1392 CreateSessionDescriptionRequest::Type type) {
1393 InitWithDtlsIdentityGenFail();
1394 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1395 }
1396
1397 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001398 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001399 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001400 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001401 if (type == CreateSessionDescriptionRequest::kAnswer) {
1402 cricket::MediaSessionOptions options;
1403 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001404 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 ASSERT_TRUE(offer.get() != NULL);
1406 SetRemoteDescriptionWithoutError(offer.release());
1407 }
1408
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001409 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001410 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001411 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001413 observers[kNumber];
1414 for (int i = 0; i < kNumber; ++i) {
1415 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1416 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001417 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001418 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001419 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001420 }
1421 }
1422
1423 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1424 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1425 WebRtcSessionCreateSDPObserverForTest::kFailed;
1426
1427 for (int i = 0; i < kNumber; ++i) {
1428 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1429 if (success) {
1430 EXPECT_TRUE(observers[i]->description() != NULL);
1431 } else {
1432 EXPECT_TRUE(observers[i]->description() == NULL);
1433 }
1434 }
1435 }
1436
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001437 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001438 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001439 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001440 turn_server.credentials = credentials;
1441 turn_server.ports.push_back(
1442 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1443 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001444 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001445 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001446 }
1447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 cricket::FakeMediaEngine* media_engine_;
1449 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001451 cricket::FakeCall fake_call_;
1452 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001453 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001454 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1455 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1456 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1457 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1458 rtc::SocketServerScope ss_scope_;
1459 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001460 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001461 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001462 rtc::FakeNetworkManager network_manager_;
1463 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001464 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001465 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001466 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 MockIceObserver observer_;
1468 cricket::FakeVideoMediaChannel* video_channel_;
1469 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001470 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001471 // The following flags affect options created for CreateOffer/CreateAnswer.
1472 bool send_stream_1_ = false;
1473 bool send_stream_2_ = false;
1474 bool send_audio_ = false;
1475 bool send_video_ = false;
1476 rtc::scoped_refptr<DataChannel> data_channel_;
1477 // Last values received from data channel creation signal.
1478 std::string last_data_channel_label_;
1479 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001480 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481};
1482
Henrik Boström87713d02015-08-25 09:53:21 +02001483TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1484 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001485 // SDES is disabled when DTLS is on.
1486 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487}
1488
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001489TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001490 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001491 // SDES is required if DTLS is off.
1492 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001493}
1494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1496 TestSessionCandidatesWithBundleRtcpMux(false, false);
1497}
1498
1499// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1500// with rtcp-mux and/or bundle.
1501TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1502 TestSessionCandidatesWithBundleRtcpMux(false, true);
1503}
1504
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1506 TestSessionCandidatesWithBundleRtcpMux(true, true);
1507}
1508
1509TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001510 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1511 AddInterface(rtc::SocketAddress(kClientAddrHost2, 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();
1515 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1516 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1517 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1518}
1519
minyuec8930ba2016-01-22 06:17:46 -08001520// Crashes on Win only. See webrtc:5411.
1521#if defined(WEBRTC_WIN)
1522#define MAYBE_TestStunError DISABLED_TestStunError
1523#else
1524#define MAYBE_TestStunError TestStunError
1525#endif
1526TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001527 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1528 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001529 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001530 rtc::FP_UDP,
1531 rtc::FD_ANY,
1532 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001534 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001536 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1538 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1539 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1540}
1541
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001542// Test session delivers no candidates gathered when constraint set to "none".
1543TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1544 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001545 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001546 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001547 InitiateCall();
1548 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1549 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1550 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1551}
1552
1553// Test session delivers only relay candidates gathered when constaint set to
1554// "relay".
1555TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1556 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1557 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001558 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001559 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001560 InitiateCall();
1561 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1562 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1563 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1564 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1565 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1566 observer_.mline_0_candidates_[i].type());
1567 }
1568 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1569 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1570 observer_.mline_1_candidates_[i].type());
1571 }
1572}
1573
1574// Test session delivers all candidates gathered when constaint set to "all".
1575TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1576 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001577 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001578 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001579 InitiateCall();
1580 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1581 // Host + STUN. By default allocator is disabled to gather relay candidates.
1582 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1583 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1584}
1585
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001586TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001587 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001588 SessionDescriptionInterface* offer = NULL;
1589 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1590 std::string unknown_action;
1591 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1592 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1593}
1594
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595// Test creating offers and receive answers and make sure the
1596// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001597TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001599 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001600 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 const std::string session_id_orig = offer->session_id();
1602 const std::string session_version_orig = offer->session_version();
1603 SetLocalDescriptionWithoutError(offer);
1604
deadbeefab9b2d12015-10-14 11:33:11 -07001605 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 SessionDescriptionInterface* answer =
1607 CreateRemoteAnswer(session_->local_description());
1608 SetRemoteDescriptionWithoutError(answer);
1609
1610 video_channel_ = media_engine_->GetVideoChannel(0);
1611 voice_channel_ = media_engine_->GetVoiceChannel(0);
1612
1613 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1614 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1615
1616 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1617 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1618
1619 ASSERT_EQ(1u, video_channel_->send_streams().size());
1620 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1621 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1622 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1623
1624 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001625 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001626 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
1628 // Verify the session id is the same and the session version is
1629 // increased.
1630 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001631 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1632 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
1634 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001635 EXPECT_EQ(0u, video_channel_->send_streams().size());
1636 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637
deadbeefab9b2d12015-10-14 11:33:11 -07001638 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 answer = CreateRemoteAnswer(session_->local_description());
1640 SetRemoteDescriptionWithoutError(answer);
1641
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 // Make sure the receive streams have not changed.
1643 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1644 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1645 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1646 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1647}
1648
1649// Test receiving offers and creating answers and make sure the
1650// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001652 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001653 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001654 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001655 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 SetRemoteDescriptionWithoutError(offer);
1657
deadbeefab9b2d12015-10-14 11:33:11 -07001658 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001659 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001660 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 SetLocalDescriptionWithoutError(answer);
1662
1663 const std::string session_id_orig = answer->session_id();
1664 const std::string session_version_orig = answer->session_version();
1665
1666 video_channel_ = media_engine_->GetVideoChannel(0);
1667 voice_channel_ = media_engine_->GetVoiceChannel(0);
1668
1669 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1670 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1671
1672 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1673 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1674
1675 ASSERT_EQ(1u, video_channel_->send_streams().size());
1676 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1677 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1678 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1679
deadbeefab9b2d12015-10-14 11:33:11 -07001680 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001681 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 SetRemoteDescriptionWithoutError(offer);
1683
1684 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001685 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001686 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 // Verify the session id is the same and the session version is
1689 // increased.
1690 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001691 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1692 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 SetLocalDescriptionWithoutError(answer);
1694
1695 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1696 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1697 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1698 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1699 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1700 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1701
1702 // Make sure we have no send streams.
1703 EXPECT_EQ(0u, video_channel_->send_streams().size());
1704 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1705}
1706
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001707TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001708 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 media_engine_->set_fail_create_channel(true);
1710
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001711 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001712 ASSERT_TRUE(offer != NULL);
1713 // SetRemoteDescription and SetLocalDescription will take the ownership of
1714 // the offer.
1715 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001716 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001717 ASSERT_TRUE(offer != NULL);
1718 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1719}
1720
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001721//
1722// Tests for creating/setting SDP under different SDES/DTLS polices:
1723//
1724// --DTLS off and SDES on
1725// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1726// set local/remote offer/answer with crypto --> success
1727// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1728// failure
1729// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1730// failure
1731// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1732// failure
1733//
1734// --DTLS on and SDES off
1735// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1736// set local/remote offer/answer with DTLS fingerprint --> success
1737// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1738// fingerprint --> failure
1739// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1740// --> failure
1741// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1742// --> failure
1743//
1744// --Encryption disabled: DTLS off and SDES off
1745// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1746// answer without SDES or DTLS --> success
1747// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1748// answer without SDES or DTLS --> success
1749//
1750
1751// Test that we return a failure when applying a remote/local offer that doesn't
1752// have cryptos enabled when DTLS is off.
1753TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001754 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001756 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 JsepSessionDescription* offer = CreateRemoteOffer(
1758 options, cricket::SEC_DISABLED);
1759 ASSERT_TRUE(offer != NULL);
1760 VerifyNoCryptoParams(offer->description(), false);
1761 // SetRemoteDescription and SetLocalDescription will take the ownership of
1762 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001763 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1765 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767}
1768
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769// Test that we return a failure when applying a local answer that doesn't have
1770// cryptos enabled when DTLS is off.
1771TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001772 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 SessionDescriptionInterface* offer = NULL;
1774 SessionDescriptionInterface* answer = NULL;
1775 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1776 // SetRemoteDescription and SetLocalDescription will take the ownership of
1777 // the offer.
1778 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780}
1781
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001782// Test we will return fail when apply an remote answer that doesn't have
1783// crypto enabled when DTLS is off.
1784TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 SessionDescriptionInterface* offer = NULL;
1787 SessionDescriptionInterface* answer = NULL;
1788 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1789 // SetRemoteDescription and SetLocalDescription will take the ownership of
1790 // the offer.
1791 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793}
1794
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001795// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1796// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001797TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001798 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001799 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001800 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 SetFactoryDtlsSrtp();
1802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001803 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 JsepSessionDescription* offer =
1805 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 ASSERT_TRUE(offer != NULL);
1807 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001808 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809
1810 // SetRemoteDescription will take the ownership of the offer.
1811 SetRemoteDescriptionWithoutError(offer);
1812
1813 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001814 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 ASSERT_TRUE(answer != NULL);
1816 VerifyFingerprintStatus(answer->description(), true);
1817 // Check that we don't have an a=crypto line in the answer.
1818 VerifyNoCryptoParams(answer->description(), true);
1819
1820 // Now set the local description, which should work, even without a=crypto.
1821 SetLocalDescriptionWithoutError(answer);
1822}
1823
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1825// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001826TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001827 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001828 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001829 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 SetFactoryDtlsSrtp();
1831
1832 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001833 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001834 ASSERT_TRUE(offer != NULL);
1835 VerifyFingerprintStatus(offer->description(), true);
1836 // Check that we don't have an a=crypto line in the offer.
1837 VerifyNoCryptoParams(offer->description(), true);
1838
1839 // Now set the local description, which should work, even without a=crypto.
1840 SetLocalDescriptionWithoutError(offer);
1841
1842 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001843 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844 JsepSessionDescription* answer =
1845 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1846 ASSERT_TRUE(answer != NULL);
1847 VerifyFingerprintStatus(answer->description(), true);
1848 VerifyNoCryptoParams(answer->description(), true);
1849
1850 // SetRemoteDescription will take the ownership of the answer.
1851 SetRemoteDescriptionWithoutError(answer);
1852}
1853
1854// Test that if we support DTLS and the other side didn't offer a fingerprint,
1855// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001856TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001857 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001858 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001860 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001861 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 JsepSessionDescription* offer = CreateRemoteOffer(
1863 options, cricket::SEC_REQUIRED);
1864 ASSERT_TRUE(offer != NULL);
1865 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 // SetRemoteDescription will take the ownership of the offer.
1869 SetRemoteDescriptionOfferExpectError(
1870 kSdpWithoutDtlsFingerprint, offer);
1871
1872 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1873 // SetLocalDescription will take the ownership of the offer.
1874 SetLocalDescriptionOfferExpectError(
1875 kSdpWithoutDtlsFingerprint, offer);
1876}
1877
1878// Test that we return a failure when applying a local answer that doesn't have
1879// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001880TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001881 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001882 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 SessionDescriptionInterface* offer = NULL;
1884 SessionDescriptionInterface* answer = NULL;
1885 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1886
1887 // SetRemoteDescription and SetLocalDescription will take the ownership of
1888 // the offer and answer.
1889 SetRemoteDescriptionWithoutError(offer);
1890 SetLocalDescriptionAnswerExpectError(
1891 kSdpWithoutDtlsFingerprint, answer);
1892}
1893
1894// Test that we return a failure when applying a remote answer that doesn't have
1895// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001896TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001897 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001898 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001899 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001901 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001902 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1903 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001905 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906
1907 // SetRemoteDescription and SetLocalDescription will take the ownership of
1908 // the offer and answer.
1909 SetLocalDescriptionWithoutError(offer);
1910 SetRemoteDescriptionAnswerExpectError(
1911 kSdpWithoutDtlsFingerprint, answer);
1912}
1913
1914// Test that we create a local offer without SDES or DTLS and accept a remote
1915// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001916TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001917 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001919 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920
1921 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001922 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 ASSERT_TRUE(offer != NULL);
1924 VerifyFingerprintStatus(offer->description(), false);
1925 // Check that we don't have an a=crypto line in the offer.
1926 VerifyNoCryptoParams(offer->description(), false);
1927
1928 // Now set the local description, which should work, even without a=crypto.
1929 SetLocalDescriptionWithoutError(offer);
1930
1931 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001932 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001933 JsepSessionDescription* answer =
1934 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1935 ASSERT_TRUE(answer != NULL);
1936 VerifyFingerprintStatus(answer->description(), false);
1937 VerifyNoCryptoParams(answer->description(), false);
1938
1939 // SetRemoteDescription will take the ownership of the answer.
1940 SetRemoteDescriptionWithoutError(answer);
1941}
1942
1943// Test that we create a local answer without SDES or DTLS and accept a remote
1944// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001945TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001946 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001947 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948
1949 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001950 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001951 JsepSessionDescription* offer =
1952 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1953 ASSERT_TRUE(offer != NULL);
1954 VerifyFingerprintStatus(offer->description(), false);
1955 VerifyNoCryptoParams(offer->description(), false);
1956
1957 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 SetRemoteDescriptionWithoutError(offer);
1959
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001960 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001961 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 ASSERT_TRUE(answer != NULL);
1963 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964 // Check that we don't have an a=crypto line in the answer.
1965 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001967 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 SetLocalDescriptionWithoutError(answer);
1969}
1970
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001971// Test that we can create and set an answer correctly when different
1972// SSL roles have been negotiated for different transports.
1973// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1974TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1975 SendAudioVideoStream1();
1976 InitWithDtls(GetParam());
1977 SetFactoryDtlsSrtp();
1978
1979 SessionDescriptionInterface* offer = CreateOffer();
1980 SetLocalDescriptionWithoutError(offer);
1981
1982 cricket::MediaSessionOptions options;
1983 options.recv_video = true;
1984
1985 // First, negotiate different SSL roles.
1986 SessionDescriptionInterface* answer =
1987 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1988 TransportInfo* audio_transport_info =
1989 answer->description()->GetTransportInfoByName("audio");
1990 audio_transport_info->description.connection_role =
1991 cricket::CONNECTIONROLE_ACTIVE;
1992 TransportInfo* video_transport_info =
1993 answer->description()->GetTransportInfoByName("video");
1994 video_transport_info->description.connection_role =
1995 cricket::CONNECTIONROLE_PASSIVE;
1996 SetRemoteDescriptionWithoutError(answer);
1997
1998 // Now create an offer in the reverse direction, and ensure the initial
1999 // offerer responds with an answer with correct SSL roles.
2000 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2001 kSessionVersion,
2002 session_->remote_description());
2003 SetRemoteDescriptionWithoutError(offer);
2004
2005 answer = CreateAnswer(nullptr);
2006 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2007 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2008 audio_transport_info->description.connection_role);
2009 video_transport_info = answer->description()->GetTransportInfoByName("video");
2010 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2011 video_transport_info->description.connection_role);
2012 SetLocalDescriptionWithoutError(answer);
2013
2014 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2015 // audio is transferred over to video in the answer that completes the BUNDLE
2016 // negotiation.
2017 options.bundle_enabled = true;
2018 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2019 kSessionVersion,
2020 session_->remote_description());
2021 SetRemoteDescriptionWithoutError(offer);
2022 answer = CreateAnswer(nullptr);
2023 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2024 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2025 audio_transport_info->description.connection_role);
2026 video_transport_info = answer->description()->GetTransportInfoByName("video");
2027 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2028 video_transport_info->description.connection_role);
2029 SetLocalDescriptionWithoutError(answer);
2030}
2031
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002033 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002034 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002036 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 SetLocalDescriptionWithoutError(offer);
2038
2039 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetLocalDescriptionWithoutError(offer2);
2042}
2043
2044TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SetRemoteDescriptionWithoutError(offer);
2050
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 SetRemoteDescriptionWithoutError(offer2);
2053}
2054
2055TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002060 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002061 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2062 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063}
2064
2065TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002066 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002067 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002068 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002070 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002071 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002072 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
2075TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002079 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
2081 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002082 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002084 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085
deadbeefab9b2d12015-10-14 11:33:11 -07002086 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002088 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2090
deadbeefd59daf82015-10-14 15:02:44 -07002091 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
deadbeefab9b2d12015-10-14 11:33:11 -07002093 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002094 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002095 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096}
2097
2098TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002102 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
2104 JsepSessionDescription* pranswer =
2105 CreateRemoteAnswer(session_->local_description());
2106 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2107
2108 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002109 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 JsepSessionDescription* pranswer2 =
2113 CreateRemoteAnswer(session_->local_description());
2114 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2115
2116 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002117 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118
deadbeefab9b2d12015-10-14 11:33:11 -07002119 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 SessionDescriptionInterface* answer =
2121 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002122 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123}
2124
2125TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002126 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002127 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2129
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 SessionDescriptionInterface* answer =
2131 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002132 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2133 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134}
2135
2136TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002138 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002139 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 SessionDescriptionInterface* answer =
2142 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002143 SetRemoteDescriptionAnswerExpectError(
2144 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145}
2146
2147TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002148 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002149 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150
2151 cricket::Candidate candidate;
2152 candidate.set_component(1);
2153 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2154
deadbeefd59daf82015-10-14 15:02:44 -07002155 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2157
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002158 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002160
2161 // Fail since we have not set a remote description.
2162 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163
2164 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2165 session_->local_description());
2166 SetRemoteDescriptionWithoutError(answer);
2167
deadbeefd59daf82015-10-14 15:02:44 -07002168 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2169 candidate.set_component(2);
2170 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2171 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 // Verifying the candidates are copied properly from internal vector.
2174 const SessionDescriptionInterface* remote_desc =
2175 session_->remote_description();
2176 ASSERT_TRUE(remote_desc != NULL);
2177 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2178 const IceCandidateCollection* candidates =
2179 remote_desc->candidates(kMediaContentIndex0);
2180 ASSERT_EQ(2u, candidates->count());
2181 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2182 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2183 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2184 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2185
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002186 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2187 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 candidate.set_component(2);
2189 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2190 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002191 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192
2193 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2194 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2195}
2196
2197// Test that a remote candidate is added to the remote session description and
2198// that it is retained if the remote session description is changed.
2199TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002200 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 cricket::Candidate candidate1;
2202 candidate1.set_component(1);
2203 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2204 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002205 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 CreateAndSetRemoteOfferAndLocalAnswer();
2207
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2209 const SessionDescriptionInterface* remote_desc =
2210 session_->remote_description();
2211 ASSERT_TRUE(remote_desc != NULL);
2212 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2213 const IceCandidateCollection* candidates =
2214 remote_desc->candidates(kMediaContentIndex0);
2215 ASSERT_EQ(1u, candidates->count());
2216 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2217
2218 // Update the RemoteSessionDescription with a new session description and
2219 // a candidate and check that the new remote session description contains both
2220 // candidates.
2221 SessionDescriptionInterface* offer = CreateRemoteOffer();
2222 cricket::Candidate candidate2;
2223 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2224 candidate2);
2225 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2226 SetRemoteDescriptionWithoutError(offer);
2227
2228 remote_desc = session_->remote_description();
2229 ASSERT_TRUE(remote_desc != NULL);
2230 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2231 candidates = remote_desc->candidates(kMediaContentIndex0);
2232 ASSERT_EQ(2u, candidates->count());
2233 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2234 // Username and password have be updated with the TransportInfo of the
2235 // SessionDescription, won't be equal to the original one.
2236 candidate2.set_username(candidates->at(0)->candidate().username());
2237 candidate2.set_password(candidates->at(0)->candidate().password());
2238 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2239 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2240 // No need to verify the username and password.
2241 candidate1.set_username(candidates->at(1)->candidate().username());
2242 candidate1.set_password(candidates->at(1)->candidate().password());
2243 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2244
2245 // Test that the candidate is ignored if we can add the same candidate again.
2246 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2247}
2248
2249// Test that local candidates are added to the local session description and
2250// that they are retained if the local session description is changed.
2251TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002252 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002253 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002254 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 CreateAndSetRemoteOfferAndLocalAnswer();
2256
2257 const SessionDescriptionInterface* local_desc = session_->local_description();
2258 const IceCandidateCollection* candidates =
2259 local_desc->candidates(kMediaContentIndex0);
2260 ASSERT_TRUE(candidates != NULL);
2261 EXPECT_EQ(0u, candidates->count());
2262
2263 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2264
2265 local_desc = session_->local_description();
2266 candidates = local_desc->candidates(kMediaContentIndex0);
2267 ASSERT_TRUE(candidates != NULL);
2268 EXPECT_LT(0u, candidates->count());
2269 candidates = local_desc->candidates(1);
2270 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002271 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272
2273 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002274 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 CreateAndSetRemoteOfferAndLocalAnswer();
2276
2277 local_desc = session_->local_description();
2278 candidates = local_desc->candidates(kMediaContentIndex0);
2279 ASSERT_TRUE(candidates != NULL);
2280 EXPECT_LT(0u, candidates->count());
2281 candidates = local_desc->candidates(1);
2282 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002283 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284}
2285
2286// Test that we can set a remote session description with remote candidates.
2287TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002288 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
2290 cricket::Candidate candidate1;
2291 candidate1.set_component(1);
2292 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2293 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002294 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002295 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296
2297 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2298 SetRemoteDescriptionWithoutError(offer);
2299
2300 const SessionDescriptionInterface* remote_desc =
2301 session_->remote_description();
2302 ASSERT_TRUE(remote_desc != NULL);
2303 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2304 const IceCandidateCollection* candidates =
2305 remote_desc->candidates(kMediaContentIndex0);
2306 ASSERT_EQ(1u, candidates->count());
2307 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2308
wu@webrtc.org91053e72013-08-10 07:18:04 +00002309 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 SetLocalDescriptionWithoutError(answer);
2311}
2312
2313// Test that offers and answers contains ice candidates when Ice candidates have
2314// been gathered.
2315TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002316 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002317 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002318 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 // Ice is started but candidates are not provided until SetLocalDescription
2320 // is called.
2321 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2322 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2323 CreateAndSetRemoteOfferAndLocalAnswer();
2324 // Wait until at least one local candidate has been collected.
2325 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2326 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002328 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2331 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332
2333 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2334 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002335 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2337 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 SetLocalDescriptionWithoutError(answer);
2339}
2340
2341// Verifies TransportProxy and media channels are created with content names
2342// present in the SessionDescription.
2343TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002344 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002345 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002346 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347
2348 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002349 // "video". Goal is to modify these content names and verify transport
2350 // channels
2351 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 // present in SDP.
2353 std::string sdp;
2354 EXPECT_TRUE(offer->ToString(&sdp));
2355 const std::string kAudioMid = "a=mid:audio";
2356 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2357 const std::string kVideoMid = "a=mid:video";
2358 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2359
2360 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002361 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 kAudioMidReplaceStr.c_str(),
2363 kAudioMidReplaceStr.length(),
2364 &sdp);
2365 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002366 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 kVideoMidReplaceStr.c_str(),
2368 kVideoMidReplaceStr.length(),
2369 &sdp);
2370
2371 SessionDescriptionInterface* modified_offer =
2372 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2373
2374 SetRemoteDescriptionWithoutError(modified_offer);
2375
2376 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002377 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 SetLocalDescriptionWithoutError(answer);
2379
deadbeefcbecd352015-09-23 11:50:27 -07002380 cricket::TransportChannel* voice_transport_channel =
2381 session_->voice_rtp_transport_channel();
2382 EXPECT_TRUE(voice_transport_channel != NULL);
2383 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2384 cricket::TransportChannel* video_transport_channel =
2385 session_->video_rtp_transport_channel();
2386 EXPECT_TRUE(video_transport_channel != NULL);
2387 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2389 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2390}
2391
2392// Test that an offer contains the correct media content descriptions based on
2393// the send streams when no constraints have been set.
2394TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002395 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002396 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 ASSERT_TRUE(offer != NULL);
2399 const cricket::ContentInfo* content =
2400 cricket::GetFirstAudioContent(offer->description());
2401 EXPECT_TRUE(content != NULL);
2402 content = cricket::GetFirstVideoContent(offer->description());
2403 EXPECT_TRUE(content == NULL);
2404}
2405
2406// Test that an offer contains the correct media content descriptions based on
2407// the send streams when no constraints have been set.
2408TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002409 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002411 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002412 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2413
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 const cricket::ContentInfo* content =
2415 cricket::GetFirstAudioContent(offer->description());
2416 EXPECT_TRUE(content != NULL);
2417 content = cricket::GetFirstVideoContent(offer->description());
2418 EXPECT_TRUE(content == NULL);
2419
2420 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002421 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002422 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 content = cricket::GetFirstAudioContent(offer->description());
2424 EXPECT_TRUE(content != NULL);
2425 content = cricket::GetFirstVideoContent(offer->description());
2426 EXPECT_TRUE(content != NULL);
2427}
2428
2429// Test that an offer contains no media content descriptions if
2430// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2431TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002432 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002433 PeerConnectionInterface::RTCOfferAnswerOptions options;
2434 options.offer_to_receive_audio = 0;
2435 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002437 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002438 CreateOffer(options));
2439
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 ASSERT_TRUE(offer != NULL);
2441 const cricket::ContentInfo* content =
2442 cricket::GetFirstAudioContent(offer->description());
2443 EXPECT_TRUE(content == NULL);
2444 content = cricket::GetFirstVideoContent(offer->description());
2445 EXPECT_TRUE(content == NULL);
2446}
2447
2448// Test that an offer contains only audio media content descriptions if
2449// kOfferToReceiveAudio constraints are set to true.
2450TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002451 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002452 PeerConnectionInterface::RTCOfferAnswerOptions options;
2453 options.offer_to_receive_audio =
2454 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2455
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));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458
2459 const cricket::ContentInfo* content =
2460 cricket::GetFirstAudioContent(offer->description());
2461 EXPECT_TRUE(content != NULL);
2462 content = cricket::GetFirstVideoContent(offer->description());
2463 EXPECT_TRUE(content == NULL);
2464}
2465
2466// Test that an offer contains audio and video media content descriptions if
2467// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2468TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002469 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002471 PeerConnectionInterface::RTCOfferAnswerOptions options;
2472 options.offer_to_receive_audio =
2473 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2474 options.offer_to_receive_video =
2475 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2476
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002477 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002478 CreateOffer(options));
2479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 const cricket::ContentInfo* content =
2481 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002482 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002483
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 content = cricket::GetFirstVideoContent(offer->description());
2485 EXPECT_TRUE(content != NULL);
2486
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002487 // Sets constraints to false and verifies that audio/video contents are
2488 // removed.
2489 options.offer_to_receive_audio = 0;
2490 options.offer_to_receive_video = 0;
2491 offer.reset(CreateOffer(options));
2492
2493 content = cricket::GetFirstAudioContent(offer->description());
2494 EXPECT_TRUE(content == NULL);
2495 content = cricket::GetFirstVideoContent(offer->description());
2496 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497}
2498
2499// Test that an answer can not be created if the last remote description is not
2500// an offer.
2501TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002502 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002503 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 SetLocalDescriptionWithoutError(offer);
2505 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2506 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002507 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508}
2509
2510// Test that an answer contains the correct media content descriptions when no
2511// constraints have been set.
2512TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002515 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002517 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002518 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 const cricket::ContentInfo* content =
2520 cricket::GetFirstAudioContent(answer->description());
2521 ASSERT_TRUE(content != NULL);
2522 EXPECT_FALSE(content->rejected);
2523
2524 content = cricket::GetFirstVideoContent(answer->description());
2525 ASSERT_TRUE(content != NULL);
2526 EXPECT_FALSE(content->rejected);
2527}
2528
2529// Test that an answer contains the correct media content descriptions when no
2530// constraints have been set and the offer only contain audio.
2531TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002532 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 // Create a remote offer with audio only.
2534 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002535
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002536 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 CreateRemoteOffer(options));
2538 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2539 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2540
2541 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002542 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002543 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 const cricket::ContentInfo* content =
2545 cricket::GetFirstAudioContent(answer->description());
2546 ASSERT_TRUE(content != NULL);
2547 EXPECT_FALSE(content->rejected);
2548
2549 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2550}
2551
2552// Test that an answer contains the correct media content descriptions when no
2553// constraints have been set.
2554TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
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 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002560 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002561 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002562 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 const cricket::ContentInfo* content =
2564 cricket::GetFirstAudioContent(answer->description());
2565 ASSERT_TRUE(content != NULL);
2566 EXPECT_FALSE(content->rejected);
2567
2568 content = cricket::GetFirstVideoContent(answer->description());
2569 ASSERT_TRUE(content != NULL);
2570 EXPECT_FALSE(content->rejected);
2571}
2572
2573// Test that an answer contains the correct media content descriptions when
2574// constraints have been set but no stream is sent.
2575TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002576 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002578 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 SetRemoteDescriptionWithoutError(offer.release());
2580
2581 webrtc::FakeConstraints constraints_no_receive;
2582 constraints_no_receive.SetMandatoryReceiveAudio(false);
2583 constraints_no_receive.SetMandatoryReceiveVideo(false);
2584
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002585 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002586 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 const cricket::ContentInfo* content =
2588 cricket::GetFirstAudioContent(answer->description());
2589 ASSERT_TRUE(content != NULL);
2590 EXPECT_TRUE(content->rejected);
2591
2592 content = cricket::GetFirstVideoContent(answer->description());
2593 ASSERT_TRUE(content != NULL);
2594 EXPECT_TRUE(content->rejected);
2595}
2596
2597// Test that an answer contains the correct media content descriptions when
2598// constraints have been set and streams are sent.
2599TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002600 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002602 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 SetRemoteDescriptionWithoutError(offer.release());
2604
2605 webrtc::FakeConstraints constraints_no_receive;
2606 constraints_no_receive.SetMandatoryReceiveAudio(false);
2607 constraints_no_receive.SetMandatoryReceiveVideo(false);
2608
2609 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002610 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002611 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002612 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613
2614 // TODO(perkj): Should the direction be set to SEND_ONLY?
2615 const cricket::ContentInfo* content =
2616 cricket::GetFirstAudioContent(answer->description());
2617 ASSERT_TRUE(content != NULL);
2618 EXPECT_FALSE(content->rejected);
2619
2620 // TODO(perkj): Should the direction be set to SEND_ONLY?
2621 content = cricket::GetFirstVideoContent(answer->description());
2622 ASSERT_TRUE(content != NULL);
2623 EXPECT_FALSE(content->rejected);
2624}
2625
2626TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2627 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002628 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002629 PeerConnectionInterface::RTCOfferAnswerOptions options;
2630 options.offer_to_receive_audio =
2631 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2632 options.voice_activity_detection = false;
2633
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002634 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002635 CreateOffer(options));
2636
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 const cricket::ContentInfo* content =
2638 cricket::GetFirstAudioContent(offer->description());
2639 EXPECT_TRUE(content != NULL);
2640 EXPECT_TRUE(VerifyNoCNCodecs(content));
2641}
2642
2643TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2644 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002645 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002647 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 SetRemoteDescriptionWithoutError(offer.release());
2649
2650 webrtc::FakeConstraints constraints;
2651 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002652 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002653 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 const cricket::ContentInfo* content =
2655 cricket::GetFirstAudioContent(answer->description());
2656 ASSERT_TRUE(content != NULL);
2657 EXPECT_TRUE(VerifyNoCNCodecs(content));
2658}
2659
2660// This test verifies the call setup when remote answer with audio only and
2661// later updates with video.
2662TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002663 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2665 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2666
deadbeefab9b2d12015-10-14 11:33:11 -07002667 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002668 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669
2670 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2672
2673 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2674 // and answer;
2675 SetLocalDescriptionWithoutError(offer);
2676 SetRemoteDescriptionWithoutError(answer);
2677
2678 video_channel_ = media_engine_->GetVideoChannel(0);
2679 voice_channel_ = media_engine_->GetVoiceChannel(0);
2680
2681 ASSERT_TRUE(video_channel_ == NULL);
2682
2683 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2684 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2685 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2686
2687 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002688 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 CreateAndSetRemoteOfferAndLocalAnswer();
2690
2691 video_channel_ = media_engine_->GetVideoChannel(0);
2692 voice_channel_ = media_engine_->GetVoiceChannel(0);
2693
2694 ASSERT_TRUE(video_channel_ != NULL);
2695 ASSERT_TRUE(voice_channel_ != NULL);
2696
2697 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2698 ASSERT_EQ(1u, video_channel_->send_streams().size());
2699 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2700 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2701 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2702 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2703 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2704 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2705
2706 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002707 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 CreateAndSetRemoteOfferAndLocalAnswer();
2709
2710 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2711 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2712 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2713 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2714 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2715}
2716
2717// This test verifies the call setup when remote answer with video only and
2718// later updates with audio.
2719TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002720 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2722 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002723 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002724 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725
2726 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002727 options.recv_audio = false;
2728 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2730 offer, options, cricket::SEC_ENABLED);
2731
2732 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2733 // and answer.
2734 SetLocalDescriptionWithoutError(offer);
2735 SetRemoteDescriptionWithoutError(answer);
2736
2737 video_channel_ = media_engine_->GetVideoChannel(0);
2738 voice_channel_ = media_engine_->GetVoiceChannel(0);
2739
2740 ASSERT_TRUE(voice_channel_ == NULL);
2741 ASSERT_TRUE(video_channel_ != NULL);
2742
2743 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2744 ASSERT_EQ(1u, video_channel_->send_streams().size());
2745 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2746
2747 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002748 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 CreateAndSetRemoteOfferAndLocalAnswer();
2750
2751 voice_channel_ = media_engine_->GetVoiceChannel(0);
2752 ASSERT_TRUE(voice_channel_ != NULL);
2753
2754 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2755 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2756 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2757 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2758
2759 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002760 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 CreateAndSetRemoteOfferAndLocalAnswer();
2762
2763 video_channel_ = media_engine_->GetVideoChannel(0);
2764 voice_channel_ = media_engine_->GetVoiceChannel(0);
2765
2766 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2767 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2768 ASSERT_EQ(1u, video_channel_->send_streams().size());
2769 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2770}
2771
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002773 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002774 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002775 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyCryptoParams(offer->description());
2777 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002778 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 VerifyCryptoParams(answer->description());
2780}
2781
2782TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002783 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002785 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002786 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 VerifyNoCryptoParams(offer->description(), false);
2788}
2789
2790TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002791 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 VerifyAnswerFromNonCryptoOffer();
2793}
2794
2795TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002796 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797 VerifyAnswerFromCryptoOffer();
2798}
2799
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002800// This test verifies that setLocalDescription fails if
2801// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2802TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002803 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002804 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002805 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2806
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002807 std::string sdp;
2808 RemoveIceUfragPwdLines(offer.get(), &sdp);
2809 SessionDescriptionInterface* modified_offer =
2810 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002811 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002812}
2813
2814// This test verifies that setRemoteDescription fails if
2815// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2816TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002817 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002818 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002819 std::string sdp;
2820 RemoveIceUfragPwdLines(offer.get(), &sdp);
2821 SessionDescriptionInterface* modified_offer =
2822 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002823 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002824}
2825
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002826// This test verifies that setLocalDescription fails if local offer has
2827// too short ice ufrag and pwd strings.
2828TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002829 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002830 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002831 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2832
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002833 std::string sdp;
2834 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2835 // recommended values of 4 and 22 bytes respectively.
2836 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2837 SessionDescriptionInterface* modified_offer =
2838 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2839 std::string error;
2840 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2841
2842 // Test with string greater than 256.
2843 sdp.clear();
2844 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2845 &sdp);
2846 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2847 NULL);
2848 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2849}
2850
2851// This test verifies that setRemoteDescription fails if remote offer has
2852// too short ice ufrag and pwd strings.
2853TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002854 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002855 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002856 std::string sdp;
2857 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2858 // recommended values of 4 and 22 bytes respectively.
2859 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2860 SessionDescriptionInterface* modified_offer =
2861 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2862 std::string error;
2863 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2864
2865 sdp.clear();
2866 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2867 &sdp);
2868 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2869 NULL);
2870 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2871}
2872
Honghai Zhang04e91462015-12-11 14:26:22 -08002873// Test that if the remote offer indicates the peer requested ICE restart (via
2874// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2875TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002876 Init();
2877 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2878
2879 // Create the first offer.
2880 std::string sdp;
2881 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2882 "abcdefghijklmnopqrstuvwx", &sdp);
2883 SessionDescriptionInterface* offer1 =
2884 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2885 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2886 0, "", "", "relay", 0, "");
2887 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2888 candidate1);
2889 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2890 SetRemoteDescriptionWithoutError(offer1);
2891 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2892
2893 // The second offer has the same ufrag and pwd but different address.
2894 sdp.clear();
2895 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2896 "abcdefghijklmnopqrstuvwx", &sdp);
2897 SessionDescriptionInterface* offer2 =
2898 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2899 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2900 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2901 candidate1);
2902 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2903 SetRemoteDescriptionWithoutError(offer2);
2904 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2905
2906 // The third offer has a different ufrag and different address.
2907 sdp.clear();
2908 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2909 "abcdefghijklmnopqrstuvwx", &sdp);
2910 SessionDescriptionInterface* offer3 =
2911 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2912 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2913 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2914 candidate1);
2915 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2916 SetRemoteDescriptionWithoutError(offer3);
2917 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2918
2919 // The fourth offer has no candidate but a different ufrag/pwd.
2920 sdp.clear();
2921 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2922 "abcdefghijklmnopqrstuvyz", &sdp);
2923 SessionDescriptionInterface* offer4 =
2924 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2925 SetRemoteDescriptionWithoutError(offer4);
2926 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2927}
2928
Honghai Zhang04e91462015-12-11 14:26:22 -08002929// Test that if the remote answer indicates the peer requested ICE restart (via
2930// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2931TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2932 Init();
2933 SessionDescriptionInterface* offer = CreateOffer();
2934 SetLocalDescriptionWithoutError(offer);
2935 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2936
2937 // Create the first answer.
2938 std::string sdp;
2939 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2940 "abcdefghijklmnopqrstuvwx", &sdp);
2941 SessionDescriptionInterface* answer1 =
2942 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2943 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2944 0, "", "", "relay", 0, "");
2945 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2946 candidate1);
2947 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2948 SetRemoteDescriptionWithoutError(answer1);
2949 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2950
2951 // The second answer has the same ufrag and pwd but different address.
2952 sdp.clear();
2953 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2954 "abcdefghijklmnopqrstuvwx", &sdp);
2955 SessionDescriptionInterface* answer2 =
2956 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2957 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2958 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2959 candidate1);
2960 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2961 SetRemoteDescriptionWithoutError(answer2);
2962 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2963
2964 // The third answer has a different ufrag and different address.
2965 sdp.clear();
2966 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2967 "abcdefghijklmnopqrstuvwx", &sdp);
2968 SessionDescriptionInterface* answer3 =
2969 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2970 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2971 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2972 candidate1);
2973 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2974 SetRemoteDescriptionWithoutError(answer3);
2975 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2976
2977 // The fourth answer has no candidate but a different ufrag/pwd.
2978 sdp.clear();
2979 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2980 "abcdefghijklmnopqrstuvyz", &sdp);
2981 SessionDescriptionInterface* offer4 =
2982 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2983 SetRemoteDescriptionWithoutError(offer4);
2984 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2985}
2986
Donald Curtisd4f769d2015-05-28 09:48:21 -07002987// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002988// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002989TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2990 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2991
2992 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002993 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002994
2995 PeerConnectionInterface::RTCOfferAnswerOptions options;
2996 options.use_rtp_mux = true;
2997
2998 SessionDescriptionInterface* offer = CreateRemoteOffer();
2999 SetRemoteDescriptionWithoutError(offer);
3000
3001 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3002 SetLocalDescriptionWithoutError(answer);
3003
deadbeefcbecd352015-09-23 11:50:27 -07003004 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3005 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003006
deadbeefcbecd352015-09-23 11:50:27 -07003007 cricket::BaseChannel* voice_channel = session_->voice_channel();
3008 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003009
3010 // Checks if one of the transport channels contains a connection using a given
3011 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003012 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003013 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003014 session_->GetChannelTransportStats(voice_channel, &stats);
3015 for (auto& kv : stats.transport_stats) {
3016 for (auto& chan_stat : kv.second.channel_stats) {
3017 for (auto& conn_info : chan_stat.connection_infos) {
3018 if (conn_info.remote_candidate.address().port() == port) {
3019 return true;
3020 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003021 }
3022 }
3023 }
3024 return false;
3025 };
3026
3027 EXPECT_FALSE(connection_with_remote_port(5000));
3028 EXPECT_FALSE(connection_with_remote_port(5001));
3029 EXPECT_FALSE(connection_with_remote_port(6000));
3030
3031 // The way the *_WAIT checks work is they only wait if the condition fails,
3032 // which does not help in the case where state is not changing. This is
3033 // problematic in this test since we want to verify that adding a video
3034 // candidate does _not_ change state. So we interleave candidates and assume
3035 // that messages are executed in the order they were posted.
3036
3037 // First audio candidate.
3038 cricket::Candidate candidate0;
3039 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3040 candidate0.set_component(1);
3041 candidate0.set_protocol("udp");
3042 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3043 candidate0);
3044 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3045
3046 // Video candidate.
3047 cricket::Candidate candidate1;
3048 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3049 candidate1.set_component(1);
3050 candidate1.set_protocol("udp");
3051 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3052 candidate1);
3053 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3054
3055 // Second audio candidate.
3056 cricket::Candidate candidate2;
3057 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3058 candidate2.set_component(1);
3059 candidate2.set_protocol("udp");
3060 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3061 candidate2);
3062 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3063
3064 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3065 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3066
3067 // No need here for a _WAIT check since we are checking that state hasn't
3068 // changed: if this is false we would be doing waits for nothing and if this
3069 // is true then there will be no messages processed anyways.
3070 EXPECT_FALSE(connection_with_remote_port(6000));
3071}
3072
deadbeefcbecd352015-09-23 11:50:27 -07003073// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003074TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3075 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003076 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003077
3078 PeerConnectionInterface::RTCOfferAnswerOptions options;
3079 options.use_rtp_mux = true;
3080
3081 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003083
deadbeefcbecd352015-09-23 11:50:27 -07003084 EXPECT_NE(session_->voice_rtp_transport_channel(),
3085 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003086
deadbeefab9b2d12015-10-14 11:33:11 -07003087 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003088 SessionDescriptionInterface* answer =
3089 CreateRemoteAnswer(session_->local_description());
3090 SetRemoteDescriptionWithoutError(answer);
3091
deadbeefcbecd352015-09-23 11:50:27 -07003092 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3093 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003094}
3095
deadbeefcbecd352015-09-23 11:50:27 -07003096// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003097TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3098 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003099 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003100
Donald Curtis0e209b02015-03-24 09:29:54 -07003101 PeerConnectionInterface::RTCOfferAnswerOptions options;
3102 options.use_rtp_mux = true;
3103
3104 SessionDescriptionInterface* offer = CreateOffer(options);
3105 SetLocalDescriptionWithoutError(offer);
3106
deadbeefcbecd352015-09-23 11:50:27 -07003107 EXPECT_NE(session_->voice_rtp_transport_channel(),
3108 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003109
deadbeefab9b2d12015-10-14 11:33:11 -07003110 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003111
3112 // Remove BUNDLE from the answer.
3113 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3114 CreateRemoteAnswer(session_->local_description()));
3115 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3116 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3117 JsepSessionDescription* modified_answer =
3118 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3119 modified_answer->Initialize(answer_copy, "1", "1");
3120 SetRemoteDescriptionWithoutError(modified_answer); //
3121
deadbeefcbecd352015-09-23 11:50:27 -07003122 EXPECT_NE(session_->voice_rtp_transport_channel(),
3123 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003124}
3125
3126// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3127TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3128 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003129 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003130
3131 PeerConnectionInterface::RTCOfferAnswerOptions options;
3132 options.use_rtp_mux = true;
3133
3134 SessionDescriptionInterface* offer = CreateOffer(options);
3135 SetLocalDescriptionWithoutError(offer);
3136
deadbeefcbecd352015-09-23 11:50:27 -07003137 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3138 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003139
deadbeefab9b2d12015-10-14 11:33:11 -07003140 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003141 SessionDescriptionInterface* answer =
3142 CreateRemoteAnswer(session_->local_description());
3143 SetRemoteDescriptionWithoutError(answer);
3144
deadbeefcbecd352015-09-23 11:50:27 -07003145 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3146 session_->video_rtp_transport_channel());
3147}
3148
3149// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3150// audio content in the answer.
3151TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3152 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003153 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003154
3155 PeerConnectionInterface::RTCOfferAnswerOptions options;
3156 options.use_rtp_mux = true;
3157
3158 SessionDescriptionInterface* offer = CreateOffer(options);
3159 SetLocalDescriptionWithoutError(offer);
3160
3161 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3162 session_->video_rtp_transport_channel());
3163
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003165 cricket::MediaSessionOptions recv_options;
3166 recv_options.recv_audio = false;
3167 recv_options.recv_video = true;
3168 SessionDescriptionInterface* answer =
3169 CreateRemoteAnswer(session_->local_description(), recv_options);
3170 SetRemoteDescriptionWithoutError(answer);
3171
deadbeefd59daf82015-10-14 15:02:44 -07003172 EXPECT_TRUE(nullptr == session_->voice_channel());
3173 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003174
deadbeefd59daf82015-10-14 15:02:44 -07003175 session_->Close();
3176 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3177 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3178 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3179 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003180}
3181
3182// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3183TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3184 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003185 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003186
Donald Curtis0e209b02015-03-24 09:29:54 -07003187 PeerConnectionInterface::RTCOfferAnswerOptions options;
3188 options.use_rtp_mux = true;
3189
3190 SessionDescriptionInterface* offer = CreateOffer(options);
3191 SetLocalDescriptionWithoutError(offer);
3192
deadbeefcbecd352015-09-23 11:50:27 -07003193 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3194 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003195
deadbeefab9b2d12015-10-14 11:33:11 -07003196 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003197
3198 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003199 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200 CreateRemoteAnswer(session_->local_description()));
3201 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3202 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3203 JsepSessionDescription* modified_answer =
3204 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3205 modified_answer->Initialize(answer_copy, "1", "1");
3206 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207
deadbeefcbecd352015-09-23 11:50:27 -07003208 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3209 session_->video_rtp_transport_channel());
3210}
3211
3212// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3213TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3214 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003215 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003216
3217 SessionDescriptionInterface* offer = CreateRemoteOffer();
3218 SetRemoteDescriptionWithoutError(offer);
3219
3220 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3221 session_->video_rtp_transport_channel());
3222
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003224 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3225 SetLocalDescriptionWithoutError(answer);
3226
3227 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3228 session_->video_rtp_transport_channel());
3229}
3230
3231// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3232TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3233 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003235
3236 // Remove BUNDLE from the offer.
3237 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3238 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3239 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3240 JsepSessionDescription* modified_offer =
3241 new JsepSessionDescription(JsepSessionDescription::kOffer);
3242 modified_offer->Initialize(offer_copy, "1", "1");
3243
3244 // Expect an error when applying the remote description
3245 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3246 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003247}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248
Peter Thatcher4eddf182015-04-30 10:55:59 -07003249// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003250TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3251 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253
Donald Curtis0e209b02015-03-24 09:29:54 -07003254 PeerConnectionInterface::RTCOfferAnswerOptions options;
3255 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256
Donald Curtis0e209b02015-03-24 09:29:54 -07003257 SessionDescriptionInterface* offer = CreateOffer(options);
3258 SetLocalDescriptionWithoutError(offer);
3259
deadbeefcbecd352015-09-23 11:50:27 -07003260 EXPECT_NE(session_->voice_rtp_transport_channel(),
3261 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003262
deadbeefab9b2d12015-10-14 11:33:11 -07003263 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003264 SessionDescriptionInterface* answer =
3265 CreateRemoteAnswer(session_->local_description());
3266 SetRemoteDescriptionWithoutError(answer);
3267
3268 // This should lead to an audio-only call but isn't implemented
3269 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003270 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3271 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003272}
3273
deadbeefcbecd352015-09-23 11:50:27 -07003274// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003275TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3276 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003277 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003278 PeerConnectionInterface::RTCOfferAnswerOptions options;
3279 options.use_rtp_mux = true;
3280
3281 SessionDescriptionInterface* offer = CreateOffer(options);
3282 SetLocalDescriptionWithoutError(offer);
3283
deadbeefcbecd352015-09-23 11:50:27 -07003284 EXPECT_NE(session_->voice_rtp_transport_channel(),
3285 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003286
deadbeefab9b2d12015-10-14 11:33:11 -07003287 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003288
3289 // Remove BUNDLE from the answer.
3290 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3291 CreateRemoteAnswer(session_->local_description()));
3292 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3293 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3294 JsepSessionDescription* modified_answer =
3295 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3296 modified_answer->Initialize(answer_copy, "1", "1");
3297 SetRemoteDescriptionWithoutError(modified_answer); //
3298
deadbeefcbecd352015-09-23 11:50:27 -07003299 EXPECT_NE(session_->voice_rtp_transport_channel(),
3300 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301}
3302
Peter Thatcher4eddf182015-04-30 10:55:59 -07003303// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3304TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3305 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003306 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003307
3308 PeerConnectionInterface::RTCOfferAnswerOptions options;
3309 options.use_rtp_mux = true;
3310
3311 SessionDescriptionInterface* offer = CreateOffer(options);
3312 SetRemoteDescriptionWithoutError(offer);
3313
deadbeefcbecd352015-09-23 11:50:27 -07003314 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3315 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003316}
3317
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003318TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3319 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003320 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003321
3322 PeerConnectionInterface::RTCOfferAnswerOptions options;
3323 SessionDescriptionInterface* offer = CreateOffer(options);
3324 SetLocalDescriptionWithoutError(offer);
3325
deadbeefcbecd352015-09-23 11:50:27 -07003326 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3327 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003328
deadbeefab9b2d12015-10-14 11:33:11 -07003329 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003330 SessionDescriptionInterface* answer =
3331 CreateRemoteAnswer(session_->local_description());
3332 SetRemoteDescriptionWithoutError(answer);
3333
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3335 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003336}
3337
3338TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3339 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003340 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003341
3342 PeerConnectionInterface::RTCOfferAnswerOptions options;
3343 SessionDescriptionInterface* offer = CreateOffer(options);
3344 SetLocalDescriptionWithoutError(offer);
3345
deadbeefcbecd352015-09-23 11:50:27 -07003346 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3347 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003348
deadbeefab9b2d12015-10-14 11:33:11 -07003349 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003350 SessionDescriptionInterface* answer =
3351 CreateRemoteAnswer(session_->local_description());
3352 SetRemoteDescriptionWithoutError(answer);
3353
deadbeefcbecd352015-09-23 11:50:27 -07003354 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3355 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003356}
3357
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003358// This test verifies that SetLocalDescription and SetRemoteDescription fails
3359// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3360TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003361 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003362 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003363
3364 PeerConnectionInterface::RTCOfferAnswerOptions options;
3365 options.use_rtp_mux = true;
3366
3367 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003368 std::string offer_str;
3369 offer->ToString(&offer_str);
3370 // Disable rtcp-mux
3371 const std::string rtcp_mux = "rtcp-mux";
3372 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003373 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003374 xrtcp_mux.c_str(), xrtcp_mux.length(),
3375 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003376 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003377 new JsepSessionDescription(JsepSessionDescription::kOffer);
3378 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003379 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003380 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003381 new JsepSessionDescription(JsepSessionDescription::kOffer);
3382 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003383 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003384 // Trying unmodified SDP.
3385 SetLocalDescriptionWithoutError(offer);
3386}
3387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003389 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003390 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 CreateAndSetRemoteOfferAndLocalAnswer();
3392 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3393 ASSERT_TRUE(channel != NULL);
3394 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003395 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003396 double volume;
3397 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3398 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003399 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003400 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3401 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003402 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003403 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3404 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405}
3406
3407TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003408 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003409 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 CreateAndSetRemoteOfferAndLocalAnswer();
3411 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3412 ASSERT_TRUE(channel != NULL);
3413 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003414 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3416
3417 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003418 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003420 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003421 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003423 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003424 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003426 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003427 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003429 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003430 EXPECT_TRUE(renderer->sink() == NULL);
3431}
3432
3433TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003434 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003435 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003436 CreateAndSetRemoteOfferAndLocalAnswer();
3437 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3438 ASSERT_TRUE(channel != NULL);
3439 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003440 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003441
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003442 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003443 cricket::AudioOptions options;
3444 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3445 EXPECT_TRUE(renderer->sink() != NULL);
3446
3447 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3448 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3449 // SetSink(NULL) callback afterwards.
3450 renderer.reset();
3451
3452 // This will trigger SetSink(NULL) if no OnClose() callback.
3453 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454}
3455
3456TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003457 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003458 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 CreateAndSetRemoteOfferAndLocalAnswer();
3460 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3461 ASSERT_TRUE(channel != NULL);
3462 ASSERT_LT(0u, channel->renderers().size());
3463 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3464 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003465 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466 cricket::FakeVideoRenderer renderer;
3467 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3468 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3469 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3470 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3471}
3472
3473TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003474 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003475 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 CreateAndSetRemoteOfferAndLocalAnswer();
3477 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3478 ASSERT_TRUE(channel != NULL);
3479 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003480 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3482 cricket::VideoOptions* options = NULL;
3483 session_->SetVideoSend(send_ssrc, false, options);
3484 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3485 session_->SetVideoSend(send_ssrc, true, options);
3486 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3487}
3488
3489TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3490 TestCanInsertDtmf(false);
3491}
3492
3493TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3494 TestCanInsertDtmf(true);
3495}
3496
3497TEST_F(WebRtcSessionTest, InsertDtmf) {
3498 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003499 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003500 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 CreateAndSetRemoteOfferAndLocalAnswer();
3502 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3503 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3504
3505 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 const int expected_duration = 90;
3507 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3508 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3509 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3510
3511 // Verify
3512 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003513 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003515 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003517 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003519 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520}
3521
deadbeefd59daf82015-10-14 15:02:44 -07003522// This test verifies the |initial_offerer| flag when session initiates the
3523// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003525 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003526 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003527 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3529 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003530 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003532 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533}
3534
deadbeefd59daf82015-10-14 15:02:44 -07003535// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003537 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003538 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 SessionDescriptionInterface* offer = CreateRemoteOffer();
3540 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003541 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542
deadbeefd59daf82015-10-14 15:02:44 -07003543 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003545 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546}
3547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003548// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3549TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003550 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003551 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003552 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003554 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555 CreateRemoteAnswer(session_->local_description()));
3556
3557 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3558 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003559 JsepSessionDescription* modified_answer =
3560 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003561
3562 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3563 answer->session_id(),
3564 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003565 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566
wu@webrtc.org4e393072014-04-07 17:04:35 +00003567 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 std::string sdp;
3569 EXPECT_TRUE(answer->ToString(&sdp));
3570 const std::string kAudioMid = "a=mid:audio";
3571 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003572 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 kAudioMidReplaceStr.c_str(),
3574 kAudioMidReplaceStr.length(),
3575 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003576 SessionDescriptionInterface* modified_answer1 =
3577 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003578 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579
wu@webrtc.org4e393072014-04-07 17:04:35 +00003580 // Different media types.
3581 EXPECT_TRUE(answer->ToString(&sdp));
3582 const std::string kAudioMline = "m=audio";
3583 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003584 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003585 kAudioMlineReplaceStr.c_str(),
3586 kAudioMlineReplaceStr.length(),
3587 &sdp);
3588 SessionDescriptionInterface* modified_answer2 =
3589 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3590 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592 SetRemoteDescriptionWithoutError(answer.release());
3593}
3594
3595// Verifying remote offer and local answer have matching m-lines as per
3596// RFC 3264.
3597TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
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 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003602 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603
3604 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3605 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003606 JsepSessionDescription* modified_answer =
3607 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608
3609 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3610 answer->session_id(),
3611 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003612 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613 SetLocalDescriptionWithoutError(answer);
3614}
3615
3616// This test verifies that WebRtcSession does not start candidate allocation
3617// before SetLocalDescription is called.
3618TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003619 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003620 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 SessionDescriptionInterface* offer = CreateRemoteOffer();
3622 cricket::Candidate candidate;
3623 candidate.set_component(1);
3624 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3625 candidate);
3626 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3627 cricket::Candidate candidate1;
3628 candidate1.set_component(1);
3629 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3630 candidate1);
3631 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3632 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003633 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3634 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635
3636 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003637 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3639 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3640
wu@webrtc.org91053e72013-08-10 07:18:04 +00003641 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3644}
3645
3646// This test verifies that crypto parameter is updated in local session
3647// description as per security policy set in MediaSessionDescriptionFactory.
3648TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003650 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003651 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652
3653 // Making sure SetLocalDescription correctly sets crypto value in
3654 // SessionDescription object after de-serialization of sdp string. The value
3655 // will be set as per MediaSessionDescriptionFactory.
3656 std::string offer_str;
3657 offer->ToString(&offer_str);
3658 SessionDescriptionInterface* jsep_offer_str =
3659 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3660 SetLocalDescriptionWithoutError(jsep_offer_str);
3661 EXPECT_TRUE(session_->voice_channel()->secure_required());
3662 EXPECT_TRUE(session_->video_channel()->secure_required());
3663}
3664
3665// This test verifies the crypto parameter when security is disabled.
3666TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003667 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003668 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003669 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003670 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671
3672 // Making sure SetLocalDescription correctly sets crypto value in
3673 // SessionDescription object after de-serialization of sdp string. The value
3674 // will be set as per MediaSessionDescriptionFactory.
3675 std::string offer_str;
3676 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003677 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003678 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3679 SetLocalDescriptionWithoutError(jsep_offer_str);
3680 EXPECT_FALSE(session_->voice_channel()->secure_required());
3681 EXPECT_FALSE(session_->video_channel()->secure_required());
3682}
3683
3684// This test verifies that an answer contains new ufrag and password if an offer
3685// with new ufrag and password is received.
3686TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003687 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003689 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003690 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003691 CreateRemoteOffer(options));
3692 SetRemoteDescriptionWithoutError(offer.release());
3693
deadbeefab9b2d12015-10-14 11:33:11 -07003694 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003695 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003696 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003697 SetLocalDescriptionWithoutError(answer.release());
3698
3699 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003700 options.audio_transport_options.ice_restart = true;
3701 options.video_transport_options.ice_restart = true;
3702 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003703 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003704 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003705 SetRemoteDescriptionWithoutError(updated_offer1.release());
3706
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003707 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003708 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709
3710 CompareIceUfragAndPassword(updated_answer1->description(),
3711 session_->local_description()->description(),
3712 false);
3713
3714 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003715}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716
wu@webrtc.org91053e72013-08-10 07:18:04 +00003717// This test verifies that an answer contains old ufrag and password if an offer
3718// with old ufrag and password is received.
3719TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003720 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003721 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003722 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003723 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003724 CreateRemoteOffer(options));
3725 SetRemoteDescriptionWithoutError(offer.release());
3726
deadbeefab9b2d12015-10-14 11:33:11 -07003727 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003728 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003729 CreateAnswer(NULL));
3730 SetLocalDescriptionWithoutError(answer.release());
3731
3732 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003733 options.audio_transport_options.ice_restart = false;
3734 options.video_transport_options.ice_restart = false;
3735 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003736 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003737 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003738 SetRemoteDescriptionWithoutError(updated_offer2.release());
3739
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003740 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003741 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742
3743 CompareIceUfragAndPassword(updated_answer2->description(),
3744 session_->local_description()->description(),
3745 true);
3746
3747 SetLocalDescriptionWithoutError(updated_answer2.release());
3748}
3749
3750TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003751 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003752 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003753 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754 const std::string session_id_orig = offer->session_id();
3755 const std::string session_version_orig = offer->session_version();
3756 SetLocalDescriptionWithoutError(offer);
3757
3758 video_channel_ = media_engine_->GetVideoChannel(0);
3759 video_channel_->set_fail_set_send_codecs(true);
3760
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003761 SessionDescriptionInterface* answer =
3762 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003763 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003764
3765 // Test that after a content error, setting any description will
3766 // result in an error.
3767 video_channel_->set_fail_set_send_codecs(false);
3768 answer = CreateRemoteAnswer(session_->local_description());
3769 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3770 offer = CreateRemoteOffer();
3771 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003772}
3773
3774// Runs the loopback call test with BUNDLE and STUN disabled.
3775TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3776 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003777 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003778 cricket::PORTALLOCATOR_DISABLE_STUN |
3779 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003780 TestLoopbackCall();
3781}
3782
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003783TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003784 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003785 cricket::PORTALLOCATOR_DISABLE_STUN |
3786 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3787 cricket::PORTALLOCATOR_DISABLE_RELAY);
3788
3789 // best connection is IPv6 since it has higher network preference.
3790 LoopbackNetworkConfiguration config;
3791 config.test_ipv6_network_ = true;
3792 config.best_connection_after_initial_ice_converged_ =
3793 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3794
3795 TestLoopbackCall(config);
3796}
3797
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003798// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003799TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003800 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3801 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003802 TestLoopbackCall();
3803}
3804
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3806 constraints_.reset(new FakeConstraints());
3807 constraints_->AddOptional(
3808 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003809 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003810
3811 SetLocalDescriptionWithDataChannel();
3812 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3813}
3814
Henrik Boström87713d02015-08-25 09:53:21 +02003815TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003816 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817
3818 constraints_.reset(new FakeConstraints());
3819 constraints_->AddOptional(
3820 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003821 options_.disable_sctp_data_channels = false;
3822
Henrik Boström87713d02015-08-25 09:53:21 +02003823 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003824
3825 SetLocalDescriptionWithDataChannel();
3826 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3827}
3828
Henrik Boström87713d02015-08-25 09:53:21 +02003829TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003830 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003831
Henrik Boström87713d02015-08-25 09:53:21 +02003832 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003833
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003834 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003835 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003836 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3837}
3838
Henrik Boström87713d02015-08-25 09:53:21 +02003839TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003840 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003841 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003842 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003843
3844 // Create remote offer with SCTP.
3845 cricket::MediaSessionOptions options;
3846 options.data_channel_type = cricket::DCT_SCTP;
3847 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003848 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003849 SetRemoteDescriptionWithoutError(offer);
3850
3851 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003852 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003853 EXPECT_TRUE(answer != NULL);
3854 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3855 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003856}
3857
Henrik Boström87713d02015-08-25 09:53:21 +02003858TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003859 constraints_.reset(new FakeConstraints());
3860 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003861 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003862 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863
3864 SetLocalDescriptionWithDataChannel();
3865 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3866}
3867
Henrik Boström87713d02015-08-25 09:53:21 +02003868TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003869 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870
Henrik Boström87713d02015-08-25 09:53:21 +02003871 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003872
3873 SetLocalDescriptionWithDataChannel();
3874 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3875}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003876
Henrik Boström87713d02015-08-25 09:53:21 +02003877TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003878 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003879 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003880 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003881
3882 SetLocalDescriptionWithDataChannel();
3883 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3884}
3885
Henrik Boström87713d02015-08-25 09:53:21 +02003886TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003887 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003888 const int new_send_port = 9998;
3889 const int new_recv_port = 7775;
3890
Henrik Boström87713d02015-08-25 09:53:21 +02003891 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003892 SetFactoryDtlsSrtp();
3893
3894 // By default, don't actually add the codecs to desc_factory_; they don't
3895 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3896 // let the session description get parsed. That'll get the proper codecs
3897 // into the stream.
3898 cricket::MediaSessionOptions options;
3899 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3900 "stream1", new_send_port, options);
3901
3902 // SetRemoteDescription will take the ownership of the offer.
3903 SetRemoteDescriptionWithoutError(offer);
3904
3905 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3906 new_recv_port, CreateAnswer(NULL));
3907 ASSERT_TRUE(answer != NULL);
3908
3909 // Now set the local description, which'll take ownership of the answer.
3910 SetLocalDescriptionWithoutError(answer);
3911
3912 // TEST PLAN: Set the port number to something new, set it in the SDP,
3913 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003914 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003915 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003916
3917 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3918 int portnum = -1;
3919 ASSERT_TRUE(ch != NULL);
3920 ASSERT_EQ(1UL, ch->send_codecs().size());
3921 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003922 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003923 ch->send_codecs()[0].name.c_str()));
3924 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3925 &portnum));
3926 EXPECT_EQ(new_send_port, portnum);
3927
3928 ASSERT_EQ(1UL, ch->recv_codecs().size());
3929 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003930 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003931 ch->recv_codecs()[0].name.c_str()));
3932 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3933 &portnum));
3934 EXPECT_EQ(new_recv_port, portnum);
3935}
3936
deadbeefab9b2d12015-10-14 11:33:11 -07003937// Verifies that when a session's DataChannel receives an OPEN message,
3938// WebRtcSession signals the DataChannel creation request with the expected
3939// config.
3940TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3941 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3942
3943 InitWithDtls(GetParam());
3944
3945 SetLocalDescriptionWithDataChannel();
3946 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3947
3948 webrtc::DataChannelInit config;
3949 config.id = 1;
3950 rtc::Buffer payload;
3951 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3952 cricket::ReceiveDataParams params;
3953 params.ssrc = config.id;
3954 params.type = cricket::DMT_CONTROL;
3955
3956 cricket::DataChannel* data_channel = session_->data_channel();
3957 data_channel->SignalDataReceived(data_channel, params, payload);
3958
3959 EXPECT_EQ("a", last_data_channel_label_);
3960 EXPECT_EQ(config.id, last_data_channel_config_.id);
3961 EXPECT_FALSE(last_data_channel_config_.negotiated);
3962 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3963 last_data_channel_config_.open_handshake_role);
3964}
3965
3966TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003967 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3968 FakeDtlsIdentityStore::GenerateCertificate();
3969
3970 PeerConnectionInterface::RTCConfiguration configuration;
3971 configuration.certificates.push_back(certificate);
3972 Init(nullptr, configuration);
3973 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3974
3975 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3976}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003977
Henrik Boström87713d02015-08-25 09:53:21 +02003978// Verifies that CreateOffer succeeds when CreateOffer is called before async
3979// identity generation is finished (even if a certificate is provided this is
3980// an async op).
3981TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3982 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3983 InitWithDtls(GetParam());
3984
Henrik Boströmd8281982015-08-27 10:12:24 +02003985 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003986 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003987 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3988
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003990 VerifyNoCryptoParams(offer->description(), true);
3991 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003992}
3993
3994// Verifies that CreateAnswer succeeds when CreateOffer is called before 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, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
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());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004000 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004001
4002 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004003 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004004 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004005 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004006 ASSERT_TRUE(offer.get() != NULL);
4007 SetRemoteDescriptionWithoutError(offer.release());
4008
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004009 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004010 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004011 VerifyNoCryptoParams(answer->description(), true);
4012 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004013}
4014
4015// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004016// identity generation is finished (even if a certificate is provided this is
4017// an async op).
4018TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004019 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004020 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004021
Henrik Boströmd8281982015-08-27 10:12:24 +02004022 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004023
4024 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004025 EXPECT_TRUE(offer != NULL);
4026}
4027
4028// Verifies that CreateOffer fails when CreateOffer is called after async
4029// identity generation fails.
4030TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004031 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004032 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004033
Henrik Boströmd8281982015-08-27 10:12:24 +02004034 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004035
4036 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004037 EXPECT_TRUE(offer == NULL);
4038}
4039
4040// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4041// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004042TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004043 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004044 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004045 VerifyMultipleAsyncCreateDescription(GetParam(),
4046 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004047}
4048
4049// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4050// before async identity generation fails.
4051TEST_F(WebRtcSessionTest,
4052 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004053 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004054 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4055 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056}
4057
4058// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4059// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004060TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004062 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004063 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004064 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065}
4066
4067// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4068// before async identity generation fails.
4069TEST_F(WebRtcSessionTest,
4070 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004071 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004072 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4073 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004074}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004075
4076// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4077// offer has no SDES crypto but only DTLS fingerprint.
4078TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4079 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004080 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004081 // Create a remote offer with secured transport disabled.
4082 cricket::MediaSessionOptions options;
4083 JsepSessionDescription* offer(CreateRemoteOffer(
4084 options, cricket::SEC_DISABLED));
4085 // Adds a DTLS fingerprint to the remote offer.
4086 cricket::SessionDescription* sdp = offer->description();
4087 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4088 ASSERT_TRUE(audio != NULL);
4089 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4090 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004091 rtc::SSLFingerprint::CreateFromRfc4572(
4092 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004093 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004094 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004095}
4096
wu@webrtc.orgde305012013-10-31 15:40:38 +00004097// This test verifies DSCP is properly applied on the media channels.
4098TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4099 constraints_.reset(new FakeConstraints());
4100 constraints_->AddOptional(
4101 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004102 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004103 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004104 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004105
4106 SetLocalDescriptionWithoutError(offer);
4107
4108 video_channel_ = media_engine_->GetVideoChannel(0);
4109 voice_channel_ = media_engine_->GetVoiceChannel(0);
4110
4111 ASSERT_TRUE(video_channel_ != NULL);
4112 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004113 const cricket::AudioOptions& audio_options = voice_channel_->options();
4114 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004115 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4116 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004117}
4118
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004119TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4120 constraints_.reset(new FakeConstraints());
4121 constraints_->AddOptional(
4122 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4123 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004124 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004125 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004126 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004127
4128 SetLocalDescriptionWithoutError(offer);
4129
4130 video_channel_ = media_engine_->GetVideoChannel(0);
4131
4132 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004133 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004134 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004135}
4136
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004137TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4138 // Number of unsignalled receiving streams should be between 0 and
4139 // kMaxUnsignalledRecvStreams.
4140 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4141 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4142 kMaxUnsignalledRecvStreams);
4143 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4144}
4145
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004146TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4147 constraints_.reset(new FakeConstraints());
4148 constraints_->AddOptional(
4149 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4150 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004151 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004152 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004153 SessionDescriptionInterface* offer = CreateOffer();
4154
4155 SetLocalDescriptionWithoutError(offer);
4156
4157 voice_channel_ = media_engine_->GetVoiceChannel(0);
4158
4159 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004160 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004161 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004162}
4163
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004164// Tests that we can renegotiate new media content with ICE candidates in the
4165// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004166TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
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
4182 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004183 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004184 candidate1.set_component(1);
4185 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4186 candidate1);
4187 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4188 SetRemoteDescriptionWithoutError(offer);
4189
4190 answer = CreateAnswer(NULL);
4191 SetLocalDescriptionWithoutError(answer);
4192}
4193
4194// Tests that we can renegotiate new media content with ICE candidates separated
4195// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004196TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004197 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004198 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199 SetFactoryDtlsSrtp();
4200
deadbeefab9b2d12015-10-14 11:33:11 -07004201 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004202 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004203 SetLocalDescriptionWithoutError(offer);
4204
4205 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4206 SetRemoteDescriptionWithoutError(answer);
4207
4208 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004209 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004210 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4211 SetRemoteDescriptionWithoutError(offer);
4212
4213 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004214 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004215 candidate1.set_component(1);
4216 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4217 candidate1);
4218 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4219
4220 answer = CreateAnswer(NULL);
4221 SetLocalDescriptionWithoutError(answer);
4222}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004223// Tests that RTX codec is removed from the answer when it isn't supported
4224// by local side.
4225TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4226 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004227 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004228 std::string offer_sdp(kSdpWithRtx);
4229
4230 SessionDescriptionInterface* offer =
4231 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4232 EXPECT_TRUE(offer->ToString(&offer_sdp));
4233
4234 // Offer SDP contains the RTX codec.
4235 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4236 SetRemoteDescriptionWithoutError(offer);
4237
4238 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4239 std::string answer_sdp;
4240 answer->ToString(&answer_sdp);
4241 // Answer SDP removes the unsupported RTX codec.
4242 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4243 SetLocalDescriptionWithoutError(answer);
4244}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004245
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004246// This verifies that the voice channel after bundle has both options from video
4247// and voice channels.
4248TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4249 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004250 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004251
4252 PeerConnectionInterface::RTCOfferAnswerOptions options;
4253 options.use_rtp_mux = true;
4254
4255 SessionDescriptionInterface* offer = CreateOffer(options);
4256 SetLocalDescriptionWithoutError(offer);
4257
4258 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4259 rtc::Socket::Option::OPT_SNDBUF, 4000);
4260
4261 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4262 rtc::Socket::Option::OPT_RCVBUF, 8000);
4263
4264 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004265 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004266 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4267 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004268 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004269 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4270
deadbeefcbecd352015-09-23 11:50:27 -07004271 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004272 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4273 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004274 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004275 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4276
deadbeefcbecd352015-09-23 11:50:27 -07004277 EXPECT_NE(session_->voice_rtp_transport_channel(),
4278 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004279
deadbeefab9b2d12015-10-14 11:33:11 -07004280 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004281 SessionDescriptionInterface* answer =
4282 CreateRemoteAnswer(session_->local_description());
4283 SetRemoteDescriptionWithoutError(answer);
4284
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4287 EXPECT_EQ(4000, option_val);
4288
deadbeefcbecd352015-09-23 11:50:27 -07004289 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004290 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4291 EXPECT_EQ(8000, option_val);
4292}
4293
tommi0f620f42015-07-09 03:25:02 -07004294// Test creating a session, request multiple offers, destroy the session
4295// and make sure we got success/failure callbacks for all of the requests.
4296// Background: crbug.com/507307
4297TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4298 Init();
4299
4300 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4301 PeerConnectionInterface::RTCOfferAnswerOptions options;
4302 options.offer_to_receive_audio =
4303 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004304 cricket::MediaSessionOptions session_options;
4305 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004306
4307 for (auto& o : observers) {
4308 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004309 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004310 }
4311
4312 session_.reset();
4313
tommi0f620f42015-07-09 03:25:02 -07004314 for (auto& o : observers) {
4315 // We expect to have received a notification now even if the session was
4316 // terminated. The offer creation may or may not have succeeded, but we
4317 // must have received a notification which, so the only invalid state
4318 // is kInit.
4319 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4320 }
4321}
4322
stefanc1aeaf02015-10-15 07:26:07 -07004323TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4324 TestPacketOptions();
4325}
4326
deadbeef057ecf02016-01-20 14:30:43 -08004327// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4328// is destroyed.
4329TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4330 Init();
4331 session_.reset();
4332 EXPECT_TRUE(session_destroyed_);
4333}
4334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004335// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4336// currently fails because upon disconnection and reconnection OnIceComplete is
4337// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004338
deadbeefcbecd352015-09-23 11:50:27 -07004339INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4340 WebRtcSessionTest,
4341 testing::Values(ALREADY_GENERATED,
4342 DTLS_IDENTITY_STORE));