blob: 6a38351cb5c29fa5941ab8e234e71a6cca124517 [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
deadbeefcbecd352015-09-23 11:50:27 -070028#include <vector>
29
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/audiotrack.h"
stefanc1aeaf02015-10-15 07:26:07 -070031#include "talk/app/webrtc/fakemediacontroller.h"
jbauchac8869e2015-07-03 01:36:14 -070032#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/jsepicecandidate.h"
34#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070035#include "talk/app/webrtc/peerconnection.h"
deadbeefab9b2d12015-10-14 11:33:11 -070036#include "talk/app/webrtc/sctputils.h"
37#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020040#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000041#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000043#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000044#include "talk/media/base/fakemediaengine.h"
45#include "talk/media/base/fakevideorenderer.h"
46#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070047#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/base/stunserver.h"
49#include "webrtc/p2p/base/teststunserver.h"
50#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000051#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000052#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000053#include "talk/session/media/channelmanager.h"
54#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055#include "webrtc/base/fakenetwork.h"
56#include "webrtc/base/firewallsocketserver.h"
57#include "webrtc/base/gunit.h"
58#include "webrtc/base/logging.h"
59#include "webrtc/base/network.h"
60#include "webrtc/base/physicalsocketserver.h"
61#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020062#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063#include "webrtc/base/sslstreamadapter.h"
64#include "webrtc/base/stringutils.h"
65#include "webrtc/base/thread.h"
66#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
68#define MAYBE_SKIP_TEST(feature) \
69 if (!(feature())) { \
70 LOG(LS_INFO) << "Feature disabled... skipping"; \
71 return; \
72 }
73
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000076using rtc::SocketAddress;
77using rtc::scoped_ptr;
78using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000080using webrtc::CreateSessionDescriptionObserver;
81using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070082using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020083using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070085using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070087using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::JsepIceCandidate;
89using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000090using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091using webrtc::PeerConnectionInterface;
92using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070093using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000095using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000096using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000097using webrtc::kCreateChannelFailed;
98using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000101using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000102using webrtc::kSdpWithoutDtlsFingerprint;
103using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000105using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000106using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000108typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
109
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const int kClientAddrPort = 0;
111static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000112static const char kClientIPv6AddrHost1[] =
113 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000114static const char kClientAddrHost2[] = "22.22.22.22";
115static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000116static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
117static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000118static const char kTurnUsername[] = "test";
119static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
121static const char kSessionVersion[] = "1";
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123// Media index of candidates belonging to the first media content.
124static const int kMediaContentIndex0 = 0;
125static const char kMediaContentName0[] = "audio";
126
127// Media index of candidates belonging to the second media content.
128static const int kMediaContentIndex1 = 1;
129static const char kMediaContentName1[] = "video";
130
131static const int kIceCandidatesTimeout = 10000;
132
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000133static const char kFakeDtlsFingerprint[] =
134 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
135 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
136
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000137static const char kTooLongIceUfragPwd[] =
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
142
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000143static const char kSdpWithRtx[] =
144 "v=0\r\n"
145 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
146 "s=-\r\n"
147 "t=0 0\r\n"
148 "a=msid-semantic: WMS stream1\r\n"
149 "m=video 9 RTP/SAVPF 0 96\r\n"
150 "c=IN IP4 0.0.0.0\r\n"
151 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
152 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
153 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
154 "a=mid:video\r\n"
155 "a=sendrecv\r\n"
156 "a=rtcp-mux\r\n"
157 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
158 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
159 "a=rtpmap:0 fake_video_codec/90000\r\n"
160 "a=rtpmap:96 rtx/90000\r\n"
161 "a=fmtp:96 apt=0\r\n";
162
deadbeefab9b2d12015-10-14 11:33:11 -0700163static const char kStream1[] = "stream1";
164static const char kVideoTrack1[] = "video1";
165static const char kAudioTrack1[] = "audio1";
166
167static const char kStream2[] = "stream2";
168static const char kVideoTrack2[] = "video2";
169static const char kAudioTrack2[] = "audio2";
170
Henrik Boström87713d02015-08-25 09:53:21 +0200171enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
172
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173// Add some extra |newlines| to the |message| after |line|.
174static void InjectAfter(const std::string& line,
175 const std::string& newlines,
176 std::string* message) {
177 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700178 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
179 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180}
181
182class MockIceObserver : public webrtc::IceObserver {
183 public:
184 MockIceObserver()
185 : oncandidatesready_(false),
186 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
187 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
188 }
189
190 virtual void OnIceConnectionChange(
191 PeerConnectionInterface::IceConnectionState new_state) {
192 ice_connection_state_ = new_state;
193 }
194 virtual void OnIceGatheringChange(
195 PeerConnectionInterface::IceGatheringState new_state) {
196 // We can never transition back to "new".
197 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
198 ice_gathering_state_ = new_state;
199
200 // oncandidatesready_ really means "ICE gathering is complete".
201 // This if statement ensures that this value remains correct when we
202 // transition from kIceGatheringComplete to kIceGatheringGathering.
203 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
204 oncandidatesready_ = false;
205 }
206 }
207
208 // Found a new candidate.
209 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000210 switch (candidate->sdp_mline_index()) {
211 case kMediaContentIndex0:
212 mline_0_candidates_.push_back(candidate->candidate());
213 break;
214 case kMediaContentIndex1:
215 mline_1_candidates_.push_back(candidate->candidate());
216 break;
217 default:
218 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000220
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 // The ICE gathering state should always be Gathering when a candidate is
222 // received (or possibly Completed in the case of the final candidate).
223 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
224 }
225
226 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
227 virtual void OnIceComplete() {
228 EXPECT_FALSE(oncandidatesready_);
229 oncandidatesready_ = true;
230
231 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
232 // be called approximately simultaneously. For ease of testing, this
233 // check additionally requires that they be called in the above order.
234 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
235 ice_gathering_state_);
236 }
237
238 bool oncandidatesready_;
239 std::vector<cricket::Candidate> mline_0_candidates_;
240 std::vector<cricket::Candidate> mline_1_candidates_;
241 PeerConnectionInterface::IceConnectionState ice_connection_state_;
242 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
243};
244
245class WebRtcSessionForTest : public webrtc::WebRtcSession {
246 public:
stefanc1aeaf02015-10-15 07:26:07 -0700247 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 rtc::Thread* signaling_thread,
249 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700251 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700252 : WebRtcSession(media_controller,
253 signaling_thread,
254 worker_thread,
255 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 RegisterIceObserver(ice_observer);
257 }
258 virtual ~WebRtcSessionForTest() {}
259
deadbeefcbecd352015-09-23 11:50:27 -0700260 // Note that these methods are only safe to use if the signaling thread
261 // is the same as the worker thread
262 cricket::TransportChannel* voice_rtp_transport_channel() {
263 return rtp_transport_channel(voice_channel());
264 }
265
266 cricket::TransportChannel* voice_rtcp_transport_channel() {
267 return rtcp_transport_channel(voice_channel());
268 }
269
270 cricket::TransportChannel* video_rtp_transport_channel() {
271 return rtp_transport_channel(video_channel());
272 }
273
274 cricket::TransportChannel* video_rtcp_transport_channel() {
275 return rtcp_transport_channel(video_channel());
276 }
277
278 cricket::TransportChannel* data_rtp_transport_channel() {
279 return rtp_transport_channel(data_channel());
280 }
281
282 cricket::TransportChannel* data_rtcp_transport_channel() {
283 return rtcp_transport_channel(data_channel());
284 }
285
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 using webrtc::WebRtcSession::SetAudioPlayout;
287 using webrtc::WebRtcSession::SetAudioSend;
288 using webrtc::WebRtcSession::SetCaptureDevice;
289 using webrtc::WebRtcSession::SetVideoPlayout;
290 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700291
292 private:
293 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
294 if (!ch) {
295 return nullptr;
296 }
297 return ch->transport_channel();
298 }
299
300 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
301 if (!ch) {
302 return nullptr;
303 }
304 return ch->rtcp_transport_channel();
305 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306};
307
wu@webrtc.org91053e72013-08-10 07:18:04 +0000308class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000309 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000311 enum State {
312 kInit,
313 kFailed,
314 kSucceeded,
315 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000316 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000317
318 // CreateSessionDescriptionObserver implementation.
319 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000320 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000321 state_ = kSucceeded;
322 }
323 virtual void OnFailure(const std::string& error) {
324 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000327 SessionDescriptionInterface* description() { return description_.get(); }
328
329 SessionDescriptionInterface* ReleaseDescription() {
330 return description_.release();
331 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332
wu@webrtc.org91053e72013-08-10 07:18:04 +0000333 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
wu@webrtc.org91053e72013-08-10 07:18:04 +0000335 protected:
336 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337
338 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000339 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000340 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341};
342
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000343class FakeAudioRenderer : public cricket::AudioRenderer {
344 public:
solenberg98c68862015-10-09 03:27:14 -0700345 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000346 virtual ~FakeAudioRenderer() {
347 if (sink_)
348 sink_->OnClose();
349 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000350
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000351 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000352
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000353 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000354 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000355 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356};
357
Henrik Boström87713d02015-08-25 09:53:21 +0200358class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700359 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
360 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 protected:
362 // TODO Investigate why ChannelManager crashes, if it's created
363 // after stun_server.
364 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700365 : media_engine_(new cricket::FakeMediaEngine()),
366 data_engine_(new cricket::FakeDataEngine()),
367 channel_manager_(
368 new cricket::ChannelManager(media_engine_,
369 data_engine_,
370 new cricket::CaptureManager(),
371 rtc::Thread::Current())),
372 fake_call_(webrtc::Call::Config()),
373 media_controller_(
374 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
375 channel_manager_.get())),
376 tdesc_factory_(new cricket::TransportDescriptionFactory()),
377 desc_factory_(
378 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
379 tdesc_factory_.get())),
380 pss_(new rtc::PhysicalSocketServer),
381 vss_(new rtc::VirtualSocketServer(pss_.get())),
382 fss_(new rtc::FirewallSocketServer(vss_.get())),
383 ss_scope_(fss_.get()),
384 stun_socket_addr_(
385 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
386 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
387 stun_socket_addr_)),
388 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
389 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000390 cricket::ServerAddresses stun_servers;
391 stun_servers.insert(stun_socket_addr_);
392 allocator_.reset(new cricket::BasicPortAllocator(
393 &network_manager_,
394 stun_servers,
395 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000396 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700397 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 EXPECT_TRUE(channel_manager_->Init());
399 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000400 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 }
402
403 void AddInterface(const SocketAddress& addr) {
404 network_manager_.AddInterface(addr);
405 }
406
Henrik Boström87713d02015-08-25 09:53:21 +0200407 // If |dtls_identity_store| != null or |rtc_configuration| contains
408 // |certificates| then DTLS will be enabled unless explicitly disabled by
409 // |rtc_configuration| options. When DTLS is enabled a certificate will be
410 // used if provided, otherwise one will be generated using the
411 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000412 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200413 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200414 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 ASSERT_TRUE(session_.get() == NULL);
416 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700417 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700418 allocator_.get(), &observer_));
419 session_->SignalDataChannelOpenMessage.connect(
420 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421
422 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
423 observer_.ice_connection_state_);
424 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
425 observer_.ice_gathering_state_);
426
deadbeefcbecd352015-09-23 11:50:27 -0700427 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
428 dtls_identity_store.Pass(),
429 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700430 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 }
432
deadbeefab9b2d12015-10-14 11:33:11 -0700433 void OnDataChannelOpenMessage(const std::string& label,
434 const InternalDataChannelInit& config) {
435 last_data_channel_label_ = label;
436 last_data_channel_config_ = config;
437 }
438
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000439 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200440 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200441 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000442 }
443
444 void InitWithIceTransport(
445 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200446 PeerConnectionInterface::RTCConfiguration configuration;
447 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200448 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 }
450
451 void InitWithBundlePolicy(
452 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200453 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200454 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200455 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700456 }
457
458 void InitWithRtcpMuxPolicy(
459 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
460 PeerConnectionInterface::RTCConfiguration configuration;
461 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200462 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000463 }
464
Henrik Boström87713d02015-08-25 09:53:21 +0200465 // Successfully init with DTLS; with a certificate generated and supplied or
466 // with a store that generates it for us.
467 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
468 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
469 PeerConnectionInterface::RTCConfiguration configuration;
470 if (cert_gen_method == ALREADY_GENERATED) {
471 configuration.certificates.push_back(
472 FakeDtlsIdentityStore::GenerateCertificate());
473 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
474 dtls_identity_store.reset(new FakeDtlsIdentityStore());
475 dtls_identity_store->set_should_fail(false);
476 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700477 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200478 }
479 Init(dtls_identity_store.Pass(), configuration);
480 }
481
482 // Init with DTLS with a store that will fail to generate a certificate.
483 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200484 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
485 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200486 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200487 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200488 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000489 }
490
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 void InitWithDtmfCodec() {
492 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000493 const cricket::AudioCodec kTelephoneEventCodec(
494 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 std::vector<cricket::AudioCodec> codecs;
496 codecs.push_back(kTelephoneEventCodec);
497 media_engine_->SetAudioCodecs(codecs);
498 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000499 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 }
501
deadbeefab9b2d12015-10-14 11:33:11 -0700502 void SendAudioVideoStream1() {
503 send_stream_1_ = true;
504 send_stream_2_ = false;
505 send_audio_ = true;
506 send_video_ = true;
507 }
508
509 void SendAudioVideoStream2() {
510 send_stream_1_ = false;
511 send_stream_2_ = true;
512 send_audio_ = true;
513 send_video_ = true;
514 }
515
516 void SendAudioVideoStream1And2() {
517 send_stream_1_ = true;
518 send_stream_2_ = true;
519 send_audio_ = true;
520 send_video_ = true;
521 }
522
523 void SendNothing() {
524 send_stream_1_ = false;
525 send_stream_2_ = false;
526 send_audio_ = false;
527 send_video_ = false;
528 }
529
530 void SendAudioOnlyStream2() {
531 send_stream_1_ = false;
532 send_stream_2_ = true;
533 send_audio_ = true;
534 send_video_ = false;
535 }
536
537 void SendVideoOnlyStream2() {
538 send_stream_1_ = false;
539 send_stream_2_ = true;
540 send_audio_ = false;
541 send_video_ = true;
542 }
543
544 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
545 if (send_stream_1_ && send_audio_) {
546 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
547 kStream1);
548 }
549 if (send_stream_1_ && send_video_) {
550 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
551 kStream1);
552 }
553 if (send_stream_2_ && send_audio_) {
554 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
555 kStream2);
556 }
557 if (send_stream_2_ && send_video_) {
558 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
559 kStream2);
560 }
561 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
562 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
563 data_channel_->label(),
564 data_channel_->label());
565 }
566 }
567
568 void GetOptionsForOffer(
569 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
570 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700571 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
572
deadbeefc80741f2015-10-22 13:14:45 -0700573 AddStreamsToOptions(session_options);
574 if (rtc_options.offer_to_receive_audio ==
575 RTCOfferAnswerOptions::kUndefined) {
576 session_options->recv_audio =
577 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
578 }
579 if (rtc_options.offer_to_receive_video ==
580 RTCOfferAnswerOptions::kUndefined) {
581 session_options->recv_video =
582 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
583 }
584 session_options->bundle_enabled =
585 session_options->bundle_enabled &&
586 (session_options->has_audio() || session_options->has_video() ||
587 session_options->has_data());
588
deadbeefab9b2d12015-10-14 11:33:11 -0700589 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
590 session_options->data_channel_type = cricket::DCT_SCTP;
591 }
592 }
593
594 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
595 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700596 session_options->recv_audio = false;
597 session_options->recv_video = false;
598 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
599
deadbeefc80741f2015-10-22 13:14:45 -0700600 AddStreamsToOptions(session_options);
601 session_options->bundle_enabled =
602 session_options->bundle_enabled &&
603 (session_options->has_audio() || session_options->has_video() ||
604 session_options->has_data());
605
deadbeefab9b2d12015-10-14 11:33:11 -0700606 if (session_->data_channel_type() == cricket::DCT_SCTP) {
607 session_options->data_channel_type = cricket::DCT_SCTP;
608 }
609 }
610
611 // Creates a local offer and applies it. Starts ICE.
612 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 // to decide which streams to create.
614 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000615 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 SetLocalDescriptionWithoutError(offer);
617 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
618 observer_.ice_gathering_state_,
619 kIceCandidatesTimeout);
620 }
621
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000622 SessionDescriptionInterface* CreateOffer() {
623 PeerConnectionInterface::RTCOfferAnswerOptions options;
624 options.offer_to_receive_audio =
625 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
626
627 return CreateOffer(options);
628 }
629
wu@webrtc.org91053e72013-08-10 07:18:04 +0000630 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000631 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000632 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700634 cricket::MediaSessionOptions session_options;
635 GetOptionsForOffer(options, &session_options);
636 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000637 EXPECT_TRUE_WAIT(
638 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000639 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000640 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000641 }
642
643 SessionDescriptionInterface* CreateAnswer(
644 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000645 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000646 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700647 cricket::MediaSessionOptions session_options;
648 GetOptionsForAnswer(constraints, &session_options);
649 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000650 EXPECT_TRUE_WAIT(
651 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000652 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000653 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000654 }
655
wu@webrtc.org364f2042013-11-20 21:49:41 +0000656 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 return (session_->voice_channel() != NULL &&
658 session_->video_channel() != NULL);
659 }
660
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
662 ASSERT_TRUE(session_.get() != NULL);
663 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
664 ASSERT_TRUE(content != NULL);
665 const cricket::AudioContentDescription* audio_content =
666 static_cast<const cricket::AudioContentDescription*>(
667 content->description);
668 ASSERT_TRUE(audio_content != NULL);
669 ASSERT_EQ(1U, audio_content->cryptos().size());
670 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
671 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
672 audio_content->cryptos()[0].cipher_suite);
673 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
674 audio_content->protocol());
675
676 content = cricket::GetFirstVideoContent(sdp);
677 ASSERT_TRUE(content != NULL);
678 const cricket::VideoContentDescription* video_content =
679 static_cast<const cricket::VideoContentDescription*>(
680 content->description);
681 ASSERT_TRUE(video_content != NULL);
682 ASSERT_EQ(1U, video_content->cryptos().size());
683 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
684 video_content->cryptos()[0].cipher_suite);
685 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
686 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
687 video_content->protocol());
688 }
689
690 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
691 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
692 ASSERT_TRUE(content != NULL);
693 const cricket::AudioContentDescription* audio_content =
694 static_cast<const cricket::AudioContentDescription*>(
695 content->description);
696 ASSERT_TRUE(audio_content != NULL);
697 ASSERT_EQ(0U, audio_content->cryptos().size());
698
699 content = cricket::GetFirstVideoContent(sdp);
700 ASSERT_TRUE(content != NULL);
701 const cricket::VideoContentDescription* video_content =
702 static_cast<const cricket::VideoContentDescription*>(
703 content->description);
704 ASSERT_TRUE(video_content != NULL);
705 ASSERT_EQ(0U, video_content->cryptos().size());
706
707 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700708 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700710 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 video_content->protocol());
712 } else {
713 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
714 audio_content->protocol());
715 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
716 video_content->protocol());
717 }
718 }
719
720 // Set the internal fake description factories to do DTLS-SRTP.
721 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000722 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000724 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200725 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200726 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700727 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
728 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
730 }
731
732 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
733 bool expected) {
734 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
735 ASSERT_TRUE(audio != NULL);
736 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 const TransportInfo* video = sdp->GetTransportInfoByName("video");
738 ASSERT_TRUE(video != NULL);
739 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 }
741
742 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000743 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000745 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000746 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000748 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000750 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
751 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000752 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 // Answer should be NULL as no crypto params in offer.
754 ASSERT_TRUE(answer == NULL);
755 }
756
757 void VerifyAnswerFromCryptoOffer() {
758 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000759 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 options.bundle_enabled = true;
761 scoped_ptr<JsepSessionDescription> offer(
762 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
763 ASSERT_TRUE(offer.get() != NULL);
764 VerifyCryptoParams(offer->description());
765 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000766 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 ASSERT_TRUE(answer.get() != NULL);
768 VerifyCryptoParams(answer->description());
769 }
770
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000771 void SetAndVerifyNumUnsignalledRecvStreams(
772 int value_set, int value_expected) {
773 constraints_.reset(new FakeConstraints());
774 constraints_->AddOptional(
775 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
776 value_set);
777 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000778 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700779 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000780 SessionDescriptionInterface* offer = CreateOffer();
781
782 SetLocalDescriptionWithoutError(offer);
783
784 video_channel_ = media_engine_->GetVideoChannel(0);
785
786 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700787 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000788 EXPECT_EQ(value_expected,
kwiberg102c6a62015-10-30 02:47:38 -0700789 video_options.unsignalled_recv_stream_limit.value_or(-1));
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000790 }
791
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
793 const cricket::SessionDescription* desc2,
794 bool expect_equal) {
795 if (desc1->contents().size() != desc2->contents().size()) {
796 EXPECT_FALSE(expect_equal);
797 return;
798 }
799
800 const cricket::ContentInfos& contents = desc1->contents();
801 cricket::ContentInfos::const_iterator it = contents.begin();
802
803 for (; it != contents.end(); ++it) {
804 const cricket::TransportDescription* transport_desc1 =
805 desc1->GetTransportDescriptionByName(it->name);
806 const cricket::TransportDescription* transport_desc2 =
807 desc2->GetTransportDescriptionByName(it->name);
808 if (!transport_desc1 || !transport_desc2) {
809 EXPECT_FALSE(expect_equal);
810 return;
811 }
812 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
813 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
814 EXPECT_FALSE(expect_equal);
815 return;
816 }
817 }
818 EXPECT_TRUE(expect_equal);
819 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000820
821 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
822 std::string *sdp) {
823 const cricket::SessionDescription* desc = current_desc->description();
824 EXPECT_TRUE(current_desc->ToString(sdp));
825
826 const cricket::ContentInfos& contents = desc->contents();
827 cricket::ContentInfos::const_iterator it = contents.begin();
828 // Replace ufrag and pwd lines with empty strings.
829 for (; it != contents.end(); ++it) {
830 const cricket::TransportDescription* transport_desc =
831 desc->GetTransportDescriptionByName(it->name);
832 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
833 + "\r\n";
834 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
835 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000836 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000837 "", 0,
838 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000839 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 "", 0,
841 sdp);
842 }
843 }
844
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000845 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
846 const std::string& modified_ice_ufrag,
847 const std::string& modified_ice_pwd,
848 std::string* sdp) {
849 const cricket::SessionDescription* desc = current_desc->description();
850 EXPECT_TRUE(current_desc->ToString(sdp));
851
852 const cricket::ContentInfos& contents = desc->contents();
853 cricket::ContentInfos::const_iterator it = contents.begin();
854 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
855 // |modified_ice_pwd| strings.
856 for (; it != contents.end(); ++it) {
857 const cricket::TransportDescription* transport_desc =
858 desc->GetTransportDescriptionByName(it->name);
859 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
860 + "\r\n";
861 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
862 + "\r\n";
863 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
864 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000865 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000866 mod_ufrag.c_str(), mod_ufrag.length(),
867 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000869 mod_pwd.c_str(), mod_pwd.length(),
870 sdp);
871 }
872 }
873
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 // Creates a remote offer and and applies it as a remote description,
875 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700876 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 // to decide which local and remote streams to create.
878 void CreateAndSetRemoteOfferAndLocalAnswer() {
879 SessionDescriptionInterface* offer = CreateRemoteOffer();
880 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000881 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 SetLocalDescriptionWithoutError(answer);
883 }
884 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
885 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700886 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 }
888 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700889 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 SetLocalDescriptionWithoutError(desc);
891 EXPECT_EQ(expected_state, session_->state());
892 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000893 void SetLocalDescriptionExpectError(const std::string& action,
894 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 SessionDescriptionInterface* desc) {
896 std::string error;
897 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000898 std::string sdp_type = "local ";
899 sdp_type.append(action);
900 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 EXPECT_NE(std::string::npos, error.find(expected_error));
902 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000903 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
904 SessionDescriptionInterface* desc) {
905 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
906 expected_error, desc);
907 }
908 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
909 SessionDescriptionInterface* desc) {
910 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
911 expected_error, desc);
912 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
914 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
915 }
916 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700917 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 SetRemoteDescriptionWithoutError(desc);
919 EXPECT_EQ(expected_state, session_->state());
920 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000921 void SetRemoteDescriptionExpectError(const std::string& action,
922 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 SessionDescriptionInterface* desc) {
924 std::string error;
925 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000926 std::string sdp_type = "remote ";
927 sdp_type.append(action);
928 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 EXPECT_NE(std::string::npos, error.find(expected_error));
930 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000931 void SetRemoteDescriptionOfferExpectError(
932 const std::string& expected_error, SessionDescriptionInterface* desc) {
933 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
934 expected_error, desc);
935 }
936 void SetRemoteDescriptionPranswerExpectError(
937 const std::string& expected_error, SessionDescriptionInterface* desc) {
938 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
939 expected_error, desc);
940 }
941 void SetRemoteDescriptionAnswerExpectError(
942 const std::string& expected_error, SessionDescriptionInterface* desc) {
943 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
944 expected_error, desc);
945 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946
947 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
948 SessionDescriptionInterface** nocrypto_answer) {
949 // Create a SDP without Crypto.
950 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000951 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 options.bundle_enabled = true;
953 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
954 ASSERT_TRUE(*offer != NULL);
955 VerifyCryptoParams((*offer)->description());
956
957 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
958 cricket::SEC_DISABLED);
959 EXPECT_TRUE(*nocrypto_answer != NULL);
960 }
961
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000962 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
963 SessionDescriptionInterface** nodtls_answer) {
964 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000965 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000966 options.bundle_enabled = true;
967
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000968 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000969 CreateRemoteOffer(options, cricket::SEC_ENABLED));
970
971 *nodtls_answer =
972 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
973 EXPECT_TRUE(*nodtls_answer != NULL);
974 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
975 VerifyCryptoParams((*nodtls_answer)->description());
976
977 SetFactoryDtlsSrtp();
978 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
979 ASSERT_TRUE(*offer != NULL);
980 VerifyFingerprintStatus((*offer)->description(), true);
981 VerifyCryptoParams((*offer)->description());
982 }
983
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 JsepSessionDescription* CreateRemoteOfferWithVersion(
985 cricket::MediaSessionOptions options,
986 cricket::SecurePolicy secure_policy,
987 const std::string& session_version,
988 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000989 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 const cricket::SessionDescription* cricket_desc = NULL;
991 if (current_desc) {
992 cricket_desc = current_desc->description();
993 session_id = current_desc->session_id();
994 }
995
996 desc_factory_->set_secure(secure_policy);
997 JsepSessionDescription* offer(
998 new JsepSessionDescription(JsepSessionDescription::kOffer));
999 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1000 session_id, session_version)) {
1001 delete offer;
1002 offer = NULL;
1003 }
1004 return offer;
1005 }
1006 JsepSessionDescription* CreateRemoteOffer(
1007 cricket::MediaSessionOptions options) {
1008 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1009 kSessionVersion, NULL);
1010 }
1011 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001012 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1013 return CreateRemoteOfferWithVersion(
1014 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 }
1016 JsepSessionDescription* CreateRemoteOffer(
1017 cricket::MediaSessionOptions options,
1018 const SessionDescriptionInterface* current_desc) {
1019 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1020 kSessionVersion, current_desc);
1021 }
1022
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001023 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1024 const char* sctp_stream_name, int new_port,
1025 cricket::MediaSessionOptions options) {
1026 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001027 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1028 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001029 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1030 }
1031
1032 // Takes ownership of offer_basis (and deletes it).
1033 JsepSessionDescription* ChangeSDPSctpPort(
1034 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1035 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1036 // SessionDescription from the mutated string.
1037 const char* default_port_str = "5000";
1038 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001039 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001040 std::string offer_str;
1041 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001042 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001043 new_port_str, strlen(new_port_str),
1044 &offer_str);
1045 JsepSessionDescription* offer = new JsepSessionDescription(
1046 offer_basis->type());
1047 delete offer_basis;
1048 offer->Initialize(offer_str, NULL);
1049 return offer;
1050 }
1051
deadbeefab9b2d12015-10-14 11:33:11 -07001052 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 // before this function to decide which streams to create.
1054 JsepSessionDescription* CreateRemoteOffer() {
1055 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001056 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 return CreateRemoteOffer(options, session_->remote_description());
1058 }
1059
1060 JsepSessionDescription* CreateRemoteAnswer(
1061 const SessionDescriptionInterface* offer,
1062 cricket::MediaSessionOptions options,
1063 cricket::SecurePolicy policy) {
1064 desc_factory_->set_secure(policy);
1065 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001066 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 JsepSessionDescription* answer(
1068 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1069 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1070 options, NULL),
1071 session_id, kSessionVersion)) {
1072 delete answer;
1073 answer = NULL;
1074 }
1075 return answer;
1076 }
1077
1078 JsepSessionDescription* CreateRemoteAnswer(
1079 const SessionDescriptionInterface* offer,
1080 cricket::MediaSessionOptions options) {
1081 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1082 }
1083
deadbeefab9b2d12015-10-14 11:33:11 -07001084 // Creates an answer session description.
1085 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 // to decide which streams to create.
1087 JsepSessionDescription* CreateRemoteAnswer(
1088 const SessionDescriptionInterface* offer) {
1089 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001090 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1092 }
1093
1094 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001095 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001096 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001097 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001098
1099 PeerConnectionInterface::RTCOfferAnswerOptions options;
1100 options.use_rtp_mux = bundle;
1101
1102 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1104 // and answer.
1105 SetLocalDescriptionWithoutError(offer);
1106
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001107 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001108 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 std::string sdp;
1110 EXPECT_TRUE(answer->ToString(&sdp));
1111
1112 size_t expected_candidate_num = 2;
1113 if (!rtcp_mux) {
1114 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1115 // for rtp and rtcp.
1116 expected_candidate_num = 4;
1117 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 const std::string kRtcpMux = "a=rtcp-mux";
1119 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001120 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 kXRtcpMux.c_str(), kXRtcpMux.length(),
1122 &sdp);
1123 }
1124
1125 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1126 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127
1128 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001129 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1131 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001132 if (bundle) {
1133 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1134 } else {
1135 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 }
1137 }
1138 // Tests that we can only send DTMF when the dtmf codec is supported.
1139 void TestCanInsertDtmf(bool can) {
1140 if (can) {
1141 InitWithDtmfCodec();
1142 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001143 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 }
deadbeefab9b2d12015-10-14 11:33:11 -07001145 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 CreateAndSetRemoteOfferAndLocalAnswer();
1147 EXPECT_FALSE(session_->CanInsertDtmf(""));
1148 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1149 }
1150
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001151 // Helper class to configure loopback network and verify Best
1152 // Connection using right IP protocol for TestLoopbackCall
1153 // method. LoopbackNetworkManager applies firewall rules to block
1154 // all ping traffic once ICE completed, and remove them to observe
1155 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1156 // verifies the best connection is using the right IP protocol after
1157 // initial ICE convergences.
1158
1159 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001160 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001161 LoopbackNetworkConfiguration()
1162 : test_ipv6_network_(false),
1163 test_extra_ipv4_network_(false),
1164 best_connection_after_initial_ice_converged_(1, 0) {}
1165
1166 // Used to track the expected best connection count in each IP protocol.
1167 struct ExpectedBestConnection {
1168 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1169 : ipv4_count_(ipv4_count),
1170 ipv6_count_(ipv6_count) {}
1171
1172 int ipv4_count_;
1173 int ipv6_count_;
1174 };
1175
1176 bool test_ipv6_network_;
1177 bool test_extra_ipv4_network_;
1178 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1179
1180 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001181 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001182 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1183 }
1184
1185 private:
jbauchac8869e2015-07-03 01:36:14 -07001186 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 const ExpectedBestConnection& expected) const {
1188 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001189 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1190 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001191 expected.ipv4_count_);
1192 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001193 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1194 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001195 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001196 // This is used in the loopback call so there is only single host to host
1197 // candidate pair.
1198 EXPECT_EQ(metrics_observer->GetEnumCounter(
1199 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1200 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001201 0);
1202 EXPECT_EQ(metrics_observer->GetEnumCounter(
1203 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1204 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001205 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001206 }
1207 };
1208
1209 class LoopbackNetworkManager {
1210 public:
1211 LoopbackNetworkManager(WebRtcSessionTest* session,
1212 const LoopbackNetworkConfiguration& config)
1213 : config_(config) {
1214 session->AddInterface(
1215 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1216 if (config_.test_extra_ipv4_network_) {
1217 session->AddInterface(
1218 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1219 }
1220 if (config_.test_ipv6_network_) {
1221 session->AddInterface(
1222 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1223 }
1224 }
1225
1226 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1227 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1228 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1229 if (config_.test_extra_ipv4_network_) {
1230 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1231 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1232 }
1233 if (config_.test_ipv6_network_) {
1234 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1235 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1236 }
1237 }
1238
1239 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1240
1241 private:
1242 LoopbackNetworkConfiguration config_;
1243 };
1244
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 // The method sets up a call from the session to itself, in a loopback
1246 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001247 // disconnection, and then a permanent disconnection.
1248 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1250 // While running the call, this method also checks if the session goes through
1251 // the correct sequence of ICE states when a connection is established,
1252 // broken, and re-established.
1253 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001254 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1255 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001257
stefanc1aeaf02015-10-15 07:26:07 -07001258 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001259 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001260 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001261 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262
1263 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1264 observer_.ice_gathering_state_);
1265 SetLocalDescriptionWithoutError(offer);
1266 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1267 observer_.ice_connection_state_);
1268 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001269 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1271 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001272 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273
1274 std::string sdp;
1275 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001276 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1277 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 ASSERT_TRUE(desc != NULL);
1279 SetRemoteDescriptionWithoutError(desc);
1280
1281 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001282 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001283
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001284 // The ice connection state is "Connected" too briefly to catch in a test.
1285 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001286 observer_.ice_connection_state_, kIceCandidatesTimeout);
1287 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288
stefanc1aeaf02015-10-15 07:26:07 -07001289 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1290 LoopbackNetworkManager loopback_network_manager(this, config);
1291 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001292 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 // Adding firewall rule to block ping requests, which should cause
1294 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001295
1296 loopback_network_manager.ApplyFirewallRules(fss_.get());
1297
1298 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1300 observer_.ice_connection_state_,
1301 kIceCandidatesTimeout);
1302
jbauchac8869e2015-07-03 01:36:14 -07001303 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001306 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001309 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 observer_.ice_connection_state_,
1311 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001312
1313 // Now we block ping requests and wait until the ICE connection transitions
1314 // to the Failed state. This will take at least 30 seconds because it must
1315 // wait for the Port to timeout.
1316 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001317
1318 loopback_network_manager.ApplyFirewallRules(fss_.get());
1319 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001320 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001321 observer_.ice_connection_state_,
1322 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 }
1324
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001325 void TestLoopbackCall() {
1326 LoopbackNetworkConfiguration config;
1327 TestLoopbackCall(config);
1328 }
1329
stefanc1aeaf02015-10-15 07:26:07 -07001330 void TestPacketOptions() {
1331 media_controller_.reset(
1332 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1333 LoopbackNetworkConfiguration config;
1334 LoopbackNetworkManager loopback_network_manager(this, config);
1335
1336 SetupLoopbackCall();
1337
1338 uint8_t test_packet[15] = {0};
1339 rtc::PacketOptions options;
1340 options.packet_id = 10;
1341 media_engine_->GetVideoChannel(0)
1342 ->SendRtp(test_packet, sizeof(test_packet), options);
1343
1344 const int kPacketTimeout = 2000;
1345 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1346 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1347 }
1348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1350 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001351 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1352 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1353
1354 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1356 codecs.push_back(kCNCodec1);
1357 codecs.push_back(kCNCodec2);
1358 media_engine_->SetAudioCodecs(codecs);
1359 desc_factory_->set_audio_codecs(codecs);
1360 }
1361
1362 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1363 const cricket::ContentDescription* description = content->description;
1364 ASSERT(description != NULL);
1365 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001366 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 ASSERT(audio_content_desc != NULL);
1368 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1369 if (audio_content_desc->codecs()[i].name == "CN")
1370 return false;
1371 }
1372 return true;
1373 }
1374
deadbeefab9b2d12015-10-14 11:33:11 -07001375 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001376 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001377 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1378 data_channel_ = DataChannel::Create(
1379 session_.get(), session_->data_channel_type(), "datachannel", dci);
1380 }
1381
1382 void SetLocalDescriptionWithDataChannel() {
1383 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001384 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 SetLocalDescriptionWithoutError(offer);
1386 }
1387
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001389 RTCCertificateGenerationMethod cert_gen_method,
1390 CreateSessionDescriptionRequest::Type type) {
1391 InitWithDtls(cert_gen_method);
1392 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1393 }
1394
1395 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1396 CreateSessionDescriptionRequest::Type type) {
1397 InitWithDtlsIdentityGenFail();
1398 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1399 }
1400
1401 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001402 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001403 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001404 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 if (type == CreateSessionDescriptionRequest::kAnswer) {
1406 cricket::MediaSessionOptions options;
1407 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001408 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001409 ASSERT_TRUE(offer.get() != NULL);
1410 SetRemoteDescriptionWithoutError(offer.release());
1411 }
1412
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001413 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001414 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001415 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001416 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001417 observers[kNumber];
1418 for (int i = 0; i < kNumber; ++i) {
1419 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1420 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001421 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001422 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001423 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001424 }
1425 }
1426
1427 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1428 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1429 WebRtcSessionCreateSDPObserverForTest::kFailed;
1430
1431 for (int i = 0; i < kNumber; ++i) {
1432 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1433 if (success) {
1434 EXPECT_TRUE(observers[i]->description() != NULL);
1435 } else {
1436 EXPECT_TRUE(observers[i]->description() == NULL);
1437 }
1438 }
1439 }
1440
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001441 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001442 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001443 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001444 turn_server.credentials = credentials;
1445 turn_server.ports.push_back(
1446 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1447 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001448 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001449 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001450 }
1451
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 cricket::FakeMediaEngine* media_engine_;
1453 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001454 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001455 cricket::FakeCall fake_call_;
1456 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001457 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001458 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1459 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1460 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1461 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1462 rtc::SocketServerScope ss_scope_;
1463 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001464 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001465 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001466 rtc::FakeNetworkManager network_manager_;
1467 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001468 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001469 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001470 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 MockIceObserver observer_;
1472 cricket::FakeVideoMediaChannel* video_channel_;
1473 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001474 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001475 // The following flags affect options created for CreateOffer/CreateAnswer.
1476 bool send_stream_1_ = false;
1477 bool send_stream_2_ = false;
1478 bool send_audio_ = false;
1479 bool send_video_ = false;
1480 rtc::scoped_refptr<DataChannel> data_channel_;
1481 // Last values received from data channel creation signal.
1482 std::string last_data_channel_label_;
1483 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484};
1485
Henrik Boström87713d02015-08-25 09:53:21 +02001486TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1487 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001488 // SDES is disabled when DTLS is on.
1489 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490}
1491
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001492TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001493 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001494 // SDES is required if DTLS is off.
1495 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001496}
1497
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1499 TestSessionCandidatesWithBundleRtcpMux(false, false);
1500}
1501
1502// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1503// with rtcp-mux and/or bundle.
1504TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1505 TestSessionCandidatesWithBundleRtcpMux(false, true);
1506}
1507
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1509 TestSessionCandidatesWithBundleRtcpMux(true, true);
1510}
1511
1512TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001513 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1514 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001515 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001516 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 InitiateCall();
1518 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1519 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1520 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1521}
1522
1523TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001524 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1525 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001526 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001527 rtc::FP_UDP,
1528 rtc::FD_ANY,
1529 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001530 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001531 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001533 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1535 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1536 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1537}
1538
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001539// Test session delivers no candidates gathered when constraint set to "none".
1540TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1541 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001542 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001543 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001544 InitiateCall();
1545 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1546 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1547 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1548}
1549
1550// Test session delivers only relay candidates gathered when constaint set to
1551// "relay".
1552TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1553 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1554 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001555 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001556 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001557 InitiateCall();
1558 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1559 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1560 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1561 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1562 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1563 observer_.mline_0_candidates_[i].type());
1564 }
1565 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1566 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1567 observer_.mline_1_candidates_[i].type());
1568 }
1569}
1570
1571// Test session delivers all candidates gathered when constaint set to "all".
1572TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1573 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001574 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001575 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001576 InitiateCall();
1577 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1578 // Host + STUN. By default allocator is disabled to gather relay candidates.
1579 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1580 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1581}
1582
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001583TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001584 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001585 SessionDescriptionInterface* offer = NULL;
1586 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1587 std::string unknown_action;
1588 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1589 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1590}
1591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592// Test creating offers and receive answers and make sure the
1593// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001595 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001597 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 const std::string session_id_orig = offer->session_id();
1599 const std::string session_version_orig = offer->session_version();
1600 SetLocalDescriptionWithoutError(offer);
1601
deadbeefab9b2d12015-10-14 11:33:11 -07001602 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 SessionDescriptionInterface* answer =
1604 CreateRemoteAnswer(session_->local_description());
1605 SetRemoteDescriptionWithoutError(answer);
1606
1607 video_channel_ = media_engine_->GetVideoChannel(0);
1608 voice_channel_ = media_engine_->GetVoiceChannel(0);
1609
1610 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1611 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1612
1613 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1614 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1615
1616 ASSERT_EQ(1u, video_channel_->send_streams().size());
1617 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1618 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1619 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1620
1621 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001622 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001623 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624
1625 // Verify the session id is the same and the session version is
1626 // increased.
1627 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001628 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1629 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630
1631 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001632 EXPECT_EQ(0u, video_channel_->send_streams().size());
1633 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
deadbeefab9b2d12015-10-14 11:33:11 -07001635 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 answer = CreateRemoteAnswer(session_->local_description());
1637 SetRemoteDescriptionWithoutError(answer);
1638
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 // Make sure the receive streams have not changed.
1640 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1641 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1642 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1643 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1644}
1645
1646// Test receiving offers and creating answers and make sure the
1647// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001648TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001649 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001650 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001651 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001652 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 SetRemoteDescriptionWithoutError(offer);
1654
deadbeefab9b2d12015-10-14 11:33:11 -07001655 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001656 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 SetLocalDescriptionWithoutError(answer);
1659
1660 const std::string session_id_orig = answer->session_id();
1661 const std::string session_version_orig = answer->session_version();
1662
1663 video_channel_ = media_engine_->GetVideoChannel(0);
1664 voice_channel_ = media_engine_->GetVoiceChannel(0);
1665
1666 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1667 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1668
1669 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1670 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1671
1672 ASSERT_EQ(1u, video_channel_->send_streams().size());
1673 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1674 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1675 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1676
deadbeefab9b2d12015-10-14 11:33:11 -07001677 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001678 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 SetRemoteDescriptionWithoutError(offer);
1680
1681 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001682 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001683 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684
1685 // Verify the session id is the same and the session version is
1686 // increased.
1687 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001688 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1689 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 SetLocalDescriptionWithoutError(answer);
1691
1692 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1693 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1694 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1695 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1696 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1697 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1698
1699 // Make sure we have no send streams.
1700 EXPECT_EQ(0u, video_channel_->send_streams().size());
1701 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1702}
1703
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001704TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001705 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001706 media_engine_->set_fail_create_channel(true);
1707
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001708 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 ASSERT_TRUE(offer != NULL);
1710 // SetRemoteDescription and SetLocalDescription will take the ownership of
1711 // the offer.
1712 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001713 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001714 ASSERT_TRUE(offer != NULL);
1715 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1716}
1717
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001718//
1719// Tests for creating/setting SDP under different SDES/DTLS polices:
1720//
1721// --DTLS off and SDES on
1722// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1723// set local/remote offer/answer with crypto --> success
1724// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1725// failure
1726// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1727// failure
1728// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1729// failure
1730//
1731// --DTLS on and SDES off
1732// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1733// set local/remote offer/answer with DTLS fingerprint --> success
1734// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1735// fingerprint --> failure
1736// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1737// --> failure
1738// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1739// --> failure
1740//
1741// --Encryption disabled: DTLS off and SDES off
1742// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1743// answer without SDES or DTLS --> success
1744// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1745// answer without SDES or DTLS --> success
1746//
1747
1748// Test that we return a failure when applying a remote/local offer that doesn't
1749// have cryptos enabled when DTLS is off.
1750TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001751 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001753 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 JsepSessionDescription* offer = CreateRemoteOffer(
1755 options, cricket::SEC_DISABLED);
1756 ASSERT_TRUE(offer != NULL);
1757 VerifyNoCryptoParams(offer->description(), false);
1758 // SetRemoteDescription and SetLocalDescription will take the ownership of
1759 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1762 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001763 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764}
1765
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766// Test that we return a failure when applying a local answer that doesn't have
1767// cryptos enabled when DTLS is off.
1768TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001769 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 SessionDescriptionInterface* offer = NULL;
1771 SessionDescriptionInterface* answer = NULL;
1772 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1773 // SetRemoteDescription and SetLocalDescription will take the ownership of
1774 // the offer.
1775 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777}
1778
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779// Test we will return fail when apply an remote answer that doesn't have
1780// crypto enabled when DTLS is off.
1781TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001782 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 SessionDescriptionInterface* offer = NULL;
1784 SessionDescriptionInterface* answer = NULL;
1785 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1786 // SetRemoteDescription and SetLocalDescription will take the ownership of
1787 // the offer.
1788 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790}
1791
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1793// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001794TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001795 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001796 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001797 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SetFactoryDtlsSrtp();
1799 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001800 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001801 JsepSessionDescription* offer =
1802 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 ASSERT_TRUE(offer != NULL);
1804 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001805 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806
1807 // SetRemoteDescription will take the ownership of the offer.
1808 SetRemoteDescriptionWithoutError(offer);
1809
1810 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001811 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 ASSERT_TRUE(answer != NULL);
1813 VerifyFingerprintStatus(answer->description(), true);
1814 // Check that we don't have an a=crypto line in the answer.
1815 VerifyNoCryptoParams(answer->description(), true);
1816
1817 // Now set the local description, which should work, even without a=crypto.
1818 SetLocalDescriptionWithoutError(answer);
1819}
1820
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001821// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1822// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001823TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001824 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001825 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001826 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001827 SetFactoryDtlsSrtp();
1828
1829 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001830 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001831 ASSERT_TRUE(offer != NULL);
1832 VerifyFingerprintStatus(offer->description(), true);
1833 // Check that we don't have an a=crypto line in the offer.
1834 VerifyNoCryptoParams(offer->description(), true);
1835
1836 // Now set the local description, which should work, even without a=crypto.
1837 SetLocalDescriptionWithoutError(offer);
1838
1839 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001840 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001841 JsepSessionDescription* answer =
1842 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1843 ASSERT_TRUE(answer != NULL);
1844 VerifyFingerprintStatus(answer->description(), true);
1845 VerifyNoCryptoParams(answer->description(), true);
1846
1847 // SetRemoteDescription will take the ownership of the answer.
1848 SetRemoteDescriptionWithoutError(answer);
1849}
1850
1851// Test that if we support DTLS and the other side didn't offer a fingerprint,
1852// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001853TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001854 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001855 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001857 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001858 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 JsepSessionDescription* offer = CreateRemoteOffer(
1860 options, cricket::SEC_REQUIRED);
1861 ASSERT_TRUE(offer != NULL);
1862 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 // SetRemoteDescription will take the ownership of the offer.
1866 SetRemoteDescriptionOfferExpectError(
1867 kSdpWithoutDtlsFingerprint, offer);
1868
1869 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1870 // SetLocalDescription will take the ownership of the offer.
1871 SetLocalDescriptionOfferExpectError(
1872 kSdpWithoutDtlsFingerprint, offer);
1873}
1874
1875// Test that we return a failure when applying a local answer that doesn't have
1876// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001877TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001878 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001879 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880 SessionDescriptionInterface* offer = NULL;
1881 SessionDescriptionInterface* answer = NULL;
1882 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1883
1884 // SetRemoteDescription and SetLocalDescription will take the ownership of
1885 // the offer and answer.
1886 SetRemoteDescriptionWithoutError(offer);
1887 SetLocalDescriptionAnswerExpectError(
1888 kSdpWithoutDtlsFingerprint, answer);
1889}
1890
1891// Test that we return a failure when applying a remote answer that doesn't have
1892// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001893TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001894 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001895 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001896 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001897 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001898 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001899 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1900 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001901 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001902 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903
1904 // SetRemoteDescription and SetLocalDescription will take the ownership of
1905 // the offer and answer.
1906 SetLocalDescriptionWithoutError(offer);
1907 SetRemoteDescriptionAnswerExpectError(
1908 kSdpWithoutDtlsFingerprint, answer);
1909}
1910
1911// Test that we create a local offer without SDES or DTLS and accept a remote
1912// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001913TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001914 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001916 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917
1918 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001919 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920 ASSERT_TRUE(offer != NULL);
1921 VerifyFingerprintStatus(offer->description(), false);
1922 // Check that we don't have an a=crypto line in the offer.
1923 VerifyNoCryptoParams(offer->description(), false);
1924
1925 // Now set the local description, which should work, even without a=crypto.
1926 SetLocalDescriptionWithoutError(offer);
1927
1928 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001929 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001930 JsepSessionDescription* answer =
1931 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1932 ASSERT_TRUE(answer != NULL);
1933 VerifyFingerprintStatus(answer->description(), false);
1934 VerifyNoCryptoParams(answer->description(), false);
1935
1936 // SetRemoteDescription will take the ownership of the answer.
1937 SetRemoteDescriptionWithoutError(answer);
1938}
1939
1940// Test that we create a local answer without SDES or DTLS and accept a remote
1941// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001942TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001943 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001944 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945
1946 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001947 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 JsepSessionDescription* offer =
1949 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1950 ASSERT_TRUE(offer != NULL);
1951 VerifyFingerprintStatus(offer->description(), false);
1952 VerifyNoCryptoParams(offer->description(), false);
1953
1954 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 SetRemoteDescriptionWithoutError(offer);
1956
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001957 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001958 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 ASSERT_TRUE(answer != NULL);
1960 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961 // Check that we don't have an a=crypto line in the answer.
1962 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 SetLocalDescriptionWithoutError(answer);
1966}
1967
1968TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001969 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001970 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001972 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 SetLocalDescriptionWithoutError(offer);
1974
1975 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001976 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 SetLocalDescriptionWithoutError(offer2);
1978}
1979
1980TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001981 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001982 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001984 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 SetRemoteDescriptionWithoutError(offer);
1986
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001987 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 SetRemoteDescriptionWithoutError(offer2);
1989}
1990
1991TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001992 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001993 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001994 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001996 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001997 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
1998 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999}
2000
2001TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002002 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002003 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002006 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002007 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002008 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009}
2010
2011TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002012 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002013 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002015 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016
2017 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002018 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002020 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021
deadbeefab9b2d12015-10-14 11:33:11 -07002022 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002024 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2026
deadbeefd59daf82015-10-14 15:02:44 -07002027 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002030 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002031 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032}
2033
2034TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002035 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002036 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002037 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002038 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 JsepSessionDescription* pranswer =
2041 CreateRemoteAnswer(session_->local_description());
2042 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2043
2044 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002045 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
deadbeefab9b2d12015-10-14 11:33:11 -07002047 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 JsepSessionDescription* pranswer2 =
2049 CreateRemoteAnswer(session_->local_description());
2050 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2051
2052 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002053 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 SessionDescriptionInterface* answer =
2057 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002058 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059}
2060
2061TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002062 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002063 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002064 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2065
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 SessionDescriptionInterface* answer =
2067 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002068 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2069 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070}
2071
2072TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002073 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002074 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002075 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2076
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 SessionDescriptionInterface* answer =
2078 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002079 SetRemoteDescriptionAnswerExpectError(
2080 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081}
2082
2083TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002084 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002085 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086
2087 cricket::Candidate candidate;
2088 candidate.set_component(1);
2089 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2090
deadbeefd59daf82015-10-14 15:02:44 -07002091 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2093
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002094 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002096
2097 // Fail since we have not set a remote description.
2098 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
2100 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2101 session_->local_description());
2102 SetRemoteDescriptionWithoutError(answer);
2103
deadbeefd59daf82015-10-14 15:02:44 -07002104 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2105 candidate.set_component(2);
2106 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2107 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2108
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 // Verifying the candidates are copied properly from internal vector.
2110 const SessionDescriptionInterface* remote_desc =
2111 session_->remote_description();
2112 ASSERT_TRUE(remote_desc != NULL);
2113 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2114 const IceCandidateCollection* candidates =
2115 remote_desc->candidates(kMediaContentIndex0);
2116 ASSERT_EQ(2u, candidates->count());
2117 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2118 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2119 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2120 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2121
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002122 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2123 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 candidate.set_component(2);
2125 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2126 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002127 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
2129 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2130 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2131}
2132
2133// Test that a remote candidate is added to the remote session description and
2134// that it is retained if the remote session description is changed.
2135TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002136 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 cricket::Candidate candidate1;
2138 candidate1.set_component(1);
2139 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2140 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002141 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 CreateAndSetRemoteOfferAndLocalAnswer();
2143
2144 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2145 const SessionDescriptionInterface* remote_desc =
2146 session_->remote_description();
2147 ASSERT_TRUE(remote_desc != NULL);
2148 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2149 const IceCandidateCollection* candidates =
2150 remote_desc->candidates(kMediaContentIndex0);
2151 ASSERT_EQ(1u, candidates->count());
2152 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2153
2154 // Update the RemoteSessionDescription with a new session description and
2155 // a candidate and check that the new remote session description contains both
2156 // candidates.
2157 SessionDescriptionInterface* offer = CreateRemoteOffer();
2158 cricket::Candidate candidate2;
2159 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2160 candidate2);
2161 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2162 SetRemoteDescriptionWithoutError(offer);
2163
2164 remote_desc = session_->remote_description();
2165 ASSERT_TRUE(remote_desc != NULL);
2166 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2167 candidates = remote_desc->candidates(kMediaContentIndex0);
2168 ASSERT_EQ(2u, candidates->count());
2169 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2170 // Username and password have be updated with the TransportInfo of the
2171 // SessionDescription, won't be equal to the original one.
2172 candidate2.set_username(candidates->at(0)->candidate().username());
2173 candidate2.set_password(candidates->at(0)->candidate().password());
2174 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2175 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2176 // No need to verify the username and password.
2177 candidate1.set_username(candidates->at(1)->candidate().username());
2178 candidate1.set_password(candidates->at(1)->candidate().password());
2179 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2180
2181 // Test that the candidate is ignored if we can add the same candidate again.
2182 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2183}
2184
2185// Test that local candidates are added to the local session description and
2186// that they are retained if the local session description is changed.
2187TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002188 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002189 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002190 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 CreateAndSetRemoteOfferAndLocalAnswer();
2192
2193 const SessionDescriptionInterface* local_desc = session_->local_description();
2194 const IceCandidateCollection* candidates =
2195 local_desc->candidates(kMediaContentIndex0);
2196 ASSERT_TRUE(candidates != NULL);
2197 EXPECT_EQ(0u, candidates->count());
2198
2199 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2200
2201 local_desc = session_->local_description();
2202 candidates = local_desc->candidates(kMediaContentIndex0);
2203 ASSERT_TRUE(candidates != NULL);
2204 EXPECT_LT(0u, candidates->count());
2205 candidates = local_desc->candidates(1);
2206 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002207 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208
2209 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002210 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 CreateAndSetRemoteOfferAndLocalAnswer();
2212
2213 local_desc = session_->local_description();
2214 candidates = local_desc->candidates(kMediaContentIndex0);
2215 ASSERT_TRUE(candidates != NULL);
2216 EXPECT_LT(0u, candidates->count());
2217 candidates = local_desc->candidates(1);
2218 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002219 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220}
2221
2222// Test that we can set a remote session description with remote candidates.
2223TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002224 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225
2226 cricket::Candidate candidate1;
2227 candidate1.set_component(1);
2228 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2229 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002230 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002231 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232
2233 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2234 SetRemoteDescriptionWithoutError(offer);
2235
2236 const SessionDescriptionInterface* remote_desc =
2237 session_->remote_description();
2238 ASSERT_TRUE(remote_desc != NULL);
2239 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2240 const IceCandidateCollection* candidates =
2241 remote_desc->candidates(kMediaContentIndex0);
2242 ASSERT_EQ(1u, candidates->count());
2243 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2244
wu@webrtc.org91053e72013-08-10 07:18:04 +00002245 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 SetLocalDescriptionWithoutError(answer);
2247}
2248
2249// Test that offers and answers contains ice candidates when Ice candidates have
2250// been gathered.
2251TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
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 // Ice is started but candidates are not provided until SetLocalDescription
2256 // is called.
2257 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2258 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2259 CreateAndSetRemoteOfferAndLocalAnswer();
2260 // Wait until at least one local candidate has been collected.
2261 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2262 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002264 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2265
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2267 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268
2269 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2270 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002271 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2273 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 SetLocalDescriptionWithoutError(answer);
2275}
2276
2277// Verifies TransportProxy and media channels are created with content names
2278// present in the SessionDescription.
2279TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002280 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002281 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002282 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283
2284 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002285 // "video". Goal is to modify these content names and verify transport
2286 // channels
2287 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 // present in SDP.
2289 std::string sdp;
2290 EXPECT_TRUE(offer->ToString(&sdp));
2291 const std::string kAudioMid = "a=mid:audio";
2292 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2293 const std::string kVideoMid = "a=mid:video";
2294 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2295
2296 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002297 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 kAudioMidReplaceStr.c_str(),
2299 kAudioMidReplaceStr.length(),
2300 &sdp);
2301 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002302 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 kVideoMidReplaceStr.c_str(),
2304 kVideoMidReplaceStr.length(),
2305 &sdp);
2306
2307 SessionDescriptionInterface* modified_offer =
2308 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2309
2310 SetRemoteDescriptionWithoutError(modified_offer);
2311
2312 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002313 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 SetLocalDescriptionWithoutError(answer);
2315
deadbeefcbecd352015-09-23 11:50:27 -07002316 cricket::TransportChannel* voice_transport_channel =
2317 session_->voice_rtp_transport_channel();
2318 EXPECT_TRUE(voice_transport_channel != NULL);
2319 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2320 cricket::TransportChannel* video_transport_channel =
2321 session_->video_rtp_transport_channel();
2322 EXPECT_TRUE(video_transport_channel != NULL);
2323 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2325 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2326}
2327
2328// Test that an offer contains the correct media content descriptions based on
2329// the send streams when no constraints have been set.
2330TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002331 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002332 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 ASSERT_TRUE(offer != NULL);
2335 const cricket::ContentInfo* content =
2336 cricket::GetFirstAudioContent(offer->description());
2337 EXPECT_TRUE(content != NULL);
2338 content = cricket::GetFirstVideoContent(offer->description());
2339 EXPECT_TRUE(content == NULL);
2340}
2341
2342// Test that an offer contains the correct media content descriptions based on
2343// the send streams when no constraints have been set.
2344TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002345 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002347 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002348 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 const cricket::ContentInfo* content =
2351 cricket::GetFirstAudioContent(offer->description());
2352 EXPECT_TRUE(content != NULL);
2353 content = cricket::GetFirstVideoContent(offer->description());
2354 EXPECT_TRUE(content == NULL);
2355
2356 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002357 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002358 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 content = cricket::GetFirstAudioContent(offer->description());
2360 EXPECT_TRUE(content != NULL);
2361 content = cricket::GetFirstVideoContent(offer->description());
2362 EXPECT_TRUE(content != NULL);
2363}
2364
2365// Test that an offer contains no media content descriptions if
2366// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2367TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002368 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002369 PeerConnectionInterface::RTCOfferAnswerOptions options;
2370 options.offer_to_receive_audio = 0;
2371 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002373 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002374 CreateOffer(options));
2375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 ASSERT_TRUE(offer != NULL);
2377 const cricket::ContentInfo* content =
2378 cricket::GetFirstAudioContent(offer->description());
2379 EXPECT_TRUE(content == NULL);
2380 content = cricket::GetFirstVideoContent(offer->description());
2381 EXPECT_TRUE(content == NULL);
2382}
2383
2384// Test that an offer contains only audio media content descriptions if
2385// kOfferToReceiveAudio constraints are set to true.
2386TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002387 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002388 PeerConnectionInterface::RTCOfferAnswerOptions options;
2389 options.offer_to_receive_audio =
2390 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2391
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002392 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002393 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394
2395 const cricket::ContentInfo* content =
2396 cricket::GetFirstAudioContent(offer->description());
2397 EXPECT_TRUE(content != NULL);
2398 content = cricket::GetFirstVideoContent(offer->description());
2399 EXPECT_TRUE(content == NULL);
2400}
2401
2402// Test that an offer contains audio and video media content descriptions if
2403// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2404TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002405 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002407 PeerConnectionInterface::RTCOfferAnswerOptions options;
2408 options.offer_to_receive_audio =
2409 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2410 options.offer_to_receive_video =
2411 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2412
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002413 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002414 CreateOffer(options));
2415
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 const cricket::ContentInfo* content =
2417 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002418 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002419
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 content = cricket::GetFirstVideoContent(offer->description());
2421 EXPECT_TRUE(content != NULL);
2422
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002423 // Sets constraints to false and verifies that audio/video contents are
2424 // removed.
2425 options.offer_to_receive_audio = 0;
2426 options.offer_to_receive_video = 0;
2427 offer.reset(CreateOffer(options));
2428
2429 content = cricket::GetFirstAudioContent(offer->description());
2430 EXPECT_TRUE(content == NULL);
2431 content = cricket::GetFirstVideoContent(offer->description());
2432 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433}
2434
2435// Test that an answer can not be created if the last remote description is not
2436// an offer.
2437TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002438 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002439 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 SetLocalDescriptionWithoutError(offer);
2441 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2442 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002443 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444}
2445
2446// Test that an answer contains the correct media content descriptions when no
2447// constraints have been set.
2448TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002449 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002451 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002453 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002454 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 const cricket::ContentInfo* content =
2456 cricket::GetFirstAudioContent(answer->description());
2457 ASSERT_TRUE(content != NULL);
2458 EXPECT_FALSE(content->rejected);
2459
2460 content = cricket::GetFirstVideoContent(answer->description());
2461 ASSERT_TRUE(content != NULL);
2462 EXPECT_FALSE(content->rejected);
2463}
2464
2465// Test that an answer contains the correct media content descriptions when no
2466// constraints have been set and the offer only contain audio.
2467TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002468 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 // Create a remote offer with audio only.
2470 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002471
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002472 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 CreateRemoteOffer(options));
2474 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2475 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2476
2477 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002478 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002479 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 const cricket::ContentInfo* content =
2481 cricket::GetFirstAudioContent(answer->description());
2482 ASSERT_TRUE(content != NULL);
2483 EXPECT_FALSE(content->rejected);
2484
2485 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2486}
2487
2488// Test that an answer contains the correct media content descriptions when no
2489// constraints have been set.
2490TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002493 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 SetRemoteDescriptionWithoutError(offer.release());
2495 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002496 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002497 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002498 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 const cricket::ContentInfo* content =
2500 cricket::GetFirstAudioContent(answer->description());
2501 ASSERT_TRUE(content != NULL);
2502 EXPECT_FALSE(content->rejected);
2503
2504 content = cricket::GetFirstVideoContent(answer->description());
2505 ASSERT_TRUE(content != NULL);
2506 EXPECT_FALSE(content->rejected);
2507}
2508
2509// Test that an answer contains the correct media content descriptions when
2510// constraints have been set but no stream is sent.
2511TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002512 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002514 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 SetRemoteDescriptionWithoutError(offer.release());
2516
2517 webrtc::FakeConstraints constraints_no_receive;
2518 constraints_no_receive.SetMandatoryReceiveAudio(false);
2519 constraints_no_receive.SetMandatoryReceiveVideo(false);
2520
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002521 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002522 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 const cricket::ContentInfo* content =
2524 cricket::GetFirstAudioContent(answer->description());
2525 ASSERT_TRUE(content != NULL);
2526 EXPECT_TRUE(content->rejected);
2527
2528 content = cricket::GetFirstVideoContent(answer->description());
2529 ASSERT_TRUE(content != NULL);
2530 EXPECT_TRUE(content->rejected);
2531}
2532
2533// Test that an answer contains the correct media content descriptions when
2534// constraints have been set and streams are sent.
2535TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002536 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002538 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 SetRemoteDescriptionWithoutError(offer.release());
2540
2541 webrtc::FakeConstraints constraints_no_receive;
2542 constraints_no_receive.SetMandatoryReceiveAudio(false);
2543 constraints_no_receive.SetMandatoryReceiveVideo(false);
2544
2545 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002546 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002547 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002548 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549
2550 // TODO(perkj): Should the direction be set to SEND_ONLY?
2551 const cricket::ContentInfo* content =
2552 cricket::GetFirstAudioContent(answer->description());
2553 ASSERT_TRUE(content != NULL);
2554 EXPECT_FALSE(content->rejected);
2555
2556 // TODO(perkj): Should the direction be set to SEND_ONLY?
2557 content = cricket::GetFirstVideoContent(answer->description());
2558 ASSERT_TRUE(content != NULL);
2559 EXPECT_FALSE(content->rejected);
2560}
2561
2562TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2563 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002564 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002565 PeerConnectionInterface::RTCOfferAnswerOptions options;
2566 options.offer_to_receive_audio =
2567 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2568 options.voice_activity_detection = false;
2569
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002570 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002571 CreateOffer(options));
2572
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 const cricket::ContentInfo* content =
2574 cricket::GetFirstAudioContent(offer->description());
2575 EXPECT_TRUE(content != NULL);
2576 EXPECT_TRUE(VerifyNoCNCodecs(content));
2577}
2578
2579TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2580 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002583 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 SetRemoteDescriptionWithoutError(offer.release());
2585
2586 webrtc::FakeConstraints constraints;
2587 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002588 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002589 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 const cricket::ContentInfo* content =
2591 cricket::GetFirstAudioContent(answer->description());
2592 ASSERT_TRUE(content != NULL);
2593 EXPECT_TRUE(VerifyNoCNCodecs(content));
2594}
2595
2596// This test verifies the call setup when remote answer with audio only and
2597// later updates with video.
2598TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002599 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2601 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2602
deadbeefab9b2d12015-10-14 11:33:11 -07002603 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002604 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605
2606 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2608
2609 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2610 // and answer;
2611 SetLocalDescriptionWithoutError(offer);
2612 SetRemoteDescriptionWithoutError(answer);
2613
2614 video_channel_ = media_engine_->GetVideoChannel(0);
2615 voice_channel_ = media_engine_->GetVoiceChannel(0);
2616
2617 ASSERT_TRUE(video_channel_ == NULL);
2618
2619 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2620 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2621 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2622
2623 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002624 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 CreateAndSetRemoteOfferAndLocalAnswer();
2626
2627 video_channel_ = media_engine_->GetVideoChannel(0);
2628 voice_channel_ = media_engine_->GetVoiceChannel(0);
2629
2630 ASSERT_TRUE(video_channel_ != NULL);
2631 ASSERT_TRUE(voice_channel_ != NULL);
2632
2633 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2634 ASSERT_EQ(1u, video_channel_->send_streams().size());
2635 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2636 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2637 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2638 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2639 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2640 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2641
2642 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002643 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 CreateAndSetRemoteOfferAndLocalAnswer();
2645
2646 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2647 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2648 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2649 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2650 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2651}
2652
2653// This test verifies the call setup when remote answer with video only and
2654// later updates with audio.
2655TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002656 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2658 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002659 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002660 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661
2662 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002663 options.recv_audio = false;
2664 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2666 offer, options, cricket::SEC_ENABLED);
2667
2668 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2669 // and answer.
2670 SetLocalDescriptionWithoutError(offer);
2671 SetRemoteDescriptionWithoutError(answer);
2672
2673 video_channel_ = media_engine_->GetVideoChannel(0);
2674 voice_channel_ = media_engine_->GetVoiceChannel(0);
2675
2676 ASSERT_TRUE(voice_channel_ == NULL);
2677 ASSERT_TRUE(video_channel_ != NULL);
2678
2679 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2680 ASSERT_EQ(1u, video_channel_->send_streams().size());
2681 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2682
2683 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002684 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 CreateAndSetRemoteOfferAndLocalAnswer();
2686
2687 voice_channel_ = media_engine_->GetVoiceChannel(0);
2688 ASSERT_TRUE(voice_channel_ != NULL);
2689
2690 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2691 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2692 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2694
2695 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002696 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697 CreateAndSetRemoteOfferAndLocalAnswer();
2698
2699 video_channel_ = media_engine_->GetVideoChannel(0);
2700 voice_channel_ = media_engine_->GetVoiceChannel(0);
2701
2702 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2703 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2704 ASSERT_EQ(1u, video_channel_->send_streams().size());
2705 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2706}
2707
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002709 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002710 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002711 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 VerifyCryptoParams(offer->description());
2713 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002714 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 VerifyCryptoParams(answer->description());
2716}
2717
2718TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002719 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002720 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002721 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002722 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 VerifyNoCryptoParams(offer->description(), false);
2724}
2725
2726TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002727 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 VerifyAnswerFromNonCryptoOffer();
2729}
2730
2731TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002732 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 VerifyAnswerFromCryptoOffer();
2734}
2735
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002736// This test verifies that setLocalDescription fails if
2737// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2738TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002739 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002740 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002741 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2742
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002743 std::string sdp;
2744 RemoveIceUfragPwdLines(offer.get(), &sdp);
2745 SessionDescriptionInterface* modified_offer =
2746 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002747 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002748}
2749
2750// This test verifies that setRemoteDescription fails if
2751// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2752TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002753 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002754 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002755 std::string sdp;
2756 RemoveIceUfragPwdLines(offer.get(), &sdp);
2757 SessionDescriptionInterface* modified_offer =
2758 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002759 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002760}
2761
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002762// This test verifies that setLocalDescription fails if local offer has
2763// too short ice ufrag and pwd strings.
2764TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002765 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002766 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002767 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2768
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002769 std::string sdp;
2770 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2771 // recommended values of 4 and 22 bytes respectively.
2772 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2773 SessionDescriptionInterface* modified_offer =
2774 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2775 std::string error;
2776 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2777
2778 // Test with string greater than 256.
2779 sdp.clear();
2780 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2781 &sdp);
2782 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2783 NULL);
2784 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2785}
2786
2787// This test verifies that setRemoteDescription fails if remote offer has
2788// too short ice ufrag and pwd strings.
2789TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002790 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002791 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002792 std::string sdp;
2793 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2794 // recommended values of 4 and 22 bytes respectively.
2795 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2796 SessionDescriptionInterface* modified_offer =
2797 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2798 std::string error;
2799 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2800
2801 sdp.clear();
2802 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2803 &sdp);
2804 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2805 NULL);
2806 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2807}
2808
Honghai Zhang04e91462015-12-11 14:26:22 -08002809// Test that if the remote offer indicates the peer requested ICE restart (via
2810// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2811TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002812 Init();
2813 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2814
2815 // Create the first offer.
2816 std::string sdp;
2817 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2818 "abcdefghijklmnopqrstuvwx", &sdp);
2819 SessionDescriptionInterface* offer1 =
2820 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2821 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2822 0, "", "", "relay", 0, "");
2823 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2824 candidate1);
2825 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2826 SetRemoteDescriptionWithoutError(offer1);
2827 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2828
2829 // The second offer has the same ufrag and pwd but different address.
2830 sdp.clear();
2831 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2832 "abcdefghijklmnopqrstuvwx", &sdp);
2833 SessionDescriptionInterface* offer2 =
2834 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2835 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2836 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2837 candidate1);
2838 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2839 SetRemoteDescriptionWithoutError(offer2);
2840 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2841
2842 // The third offer has a different ufrag and different address.
2843 sdp.clear();
2844 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2845 "abcdefghijklmnopqrstuvwx", &sdp);
2846 SessionDescriptionInterface* offer3 =
2847 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2848 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2849 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2850 candidate1);
2851 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2852 SetRemoteDescriptionWithoutError(offer3);
2853 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2854
2855 // The fourth offer has no candidate but a different ufrag/pwd.
2856 sdp.clear();
2857 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2858 "abcdefghijklmnopqrstuvyz", &sdp);
2859 SessionDescriptionInterface* offer4 =
2860 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2861 SetRemoteDescriptionWithoutError(offer4);
2862 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2863}
2864
Honghai Zhang04e91462015-12-11 14:26:22 -08002865// Test that if the remote answer indicates the peer requested ICE restart (via
2866// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2867TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2868 Init();
2869 SessionDescriptionInterface* offer = CreateOffer();
2870 SetLocalDescriptionWithoutError(offer);
2871 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2872
2873 // Create the first answer.
2874 std::string sdp;
2875 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2876 "abcdefghijklmnopqrstuvwx", &sdp);
2877 SessionDescriptionInterface* answer1 =
2878 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2879 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2880 0, "", "", "relay", 0, "");
2881 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2882 candidate1);
2883 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2884 SetRemoteDescriptionWithoutError(answer1);
2885 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2886
2887 // The second answer has the same ufrag and pwd but different address.
2888 sdp.clear();
2889 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2890 "abcdefghijklmnopqrstuvwx", &sdp);
2891 SessionDescriptionInterface* answer2 =
2892 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2893 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2894 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2895 candidate1);
2896 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2897 SetRemoteDescriptionWithoutError(answer2);
2898 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2899
2900 // The third answer has a different ufrag and different address.
2901 sdp.clear();
2902 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2903 "abcdefghijklmnopqrstuvwx", &sdp);
2904 SessionDescriptionInterface* answer3 =
2905 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2906 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2907 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2908 candidate1);
2909 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2910 SetRemoteDescriptionWithoutError(answer3);
2911 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2912
2913 // The fourth answer has no candidate but a different ufrag/pwd.
2914 sdp.clear();
2915 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2916 "abcdefghijklmnopqrstuvyz", &sdp);
2917 SessionDescriptionInterface* offer4 =
2918 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2919 SetRemoteDescriptionWithoutError(offer4);
2920 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2921}
2922
Donald Curtisd4f769d2015-05-28 09:48:21 -07002923// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002924// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002925TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2926 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2927
2928 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002929 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002930
2931 PeerConnectionInterface::RTCOfferAnswerOptions options;
2932 options.use_rtp_mux = true;
2933
2934 SessionDescriptionInterface* offer = CreateRemoteOffer();
2935 SetRemoteDescriptionWithoutError(offer);
2936
2937 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2938 SetLocalDescriptionWithoutError(answer);
2939
deadbeefcbecd352015-09-23 11:50:27 -07002940 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2941 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002942
deadbeefcbecd352015-09-23 11:50:27 -07002943 cricket::BaseChannel* voice_channel = session_->voice_channel();
2944 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002945
2946 // Checks if one of the transport channels contains a connection using a given
2947 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002948 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002949 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002950 session_->GetChannelTransportStats(voice_channel, &stats);
2951 for (auto& kv : stats.transport_stats) {
2952 for (auto& chan_stat : kv.second.channel_stats) {
2953 for (auto& conn_info : chan_stat.connection_infos) {
2954 if (conn_info.remote_candidate.address().port() == port) {
2955 return true;
2956 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002957 }
2958 }
2959 }
2960 return false;
2961 };
2962
2963 EXPECT_FALSE(connection_with_remote_port(5000));
2964 EXPECT_FALSE(connection_with_remote_port(5001));
2965 EXPECT_FALSE(connection_with_remote_port(6000));
2966
2967 // The way the *_WAIT checks work is they only wait if the condition fails,
2968 // which does not help in the case where state is not changing. This is
2969 // problematic in this test since we want to verify that adding a video
2970 // candidate does _not_ change state. So we interleave candidates and assume
2971 // that messages are executed in the order they were posted.
2972
2973 // First audio candidate.
2974 cricket::Candidate candidate0;
2975 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2976 candidate0.set_component(1);
2977 candidate0.set_protocol("udp");
2978 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2979 candidate0);
2980 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2981
2982 // Video candidate.
2983 cricket::Candidate candidate1;
2984 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2985 candidate1.set_component(1);
2986 candidate1.set_protocol("udp");
2987 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2988 candidate1);
2989 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2990
2991 // Second audio candidate.
2992 cricket::Candidate candidate2;
2993 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2994 candidate2.set_component(1);
2995 candidate2.set_protocol("udp");
2996 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2997 candidate2);
2998 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2999
3000 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3001 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3002
3003 // No need here for a _WAIT check since we are checking that state hasn't
3004 // changed: if this is false we would be doing waits for nothing and if this
3005 // is true then there will be no messages processed anyways.
3006 EXPECT_FALSE(connection_with_remote_port(6000));
3007}
3008
deadbeefcbecd352015-09-23 11:50:27 -07003009// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003010TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3011 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003012 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003013
3014 PeerConnectionInterface::RTCOfferAnswerOptions options;
3015 options.use_rtp_mux = true;
3016
3017 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003019
deadbeefcbecd352015-09-23 11:50:27 -07003020 EXPECT_NE(session_->voice_rtp_transport_channel(),
3021 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003022
deadbeefab9b2d12015-10-14 11:33:11 -07003023 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003024 SessionDescriptionInterface* answer =
3025 CreateRemoteAnswer(session_->local_description());
3026 SetRemoteDescriptionWithoutError(answer);
3027
deadbeefcbecd352015-09-23 11:50:27 -07003028 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3029 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003030}
3031
deadbeefcbecd352015-09-23 11:50:27 -07003032// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003033TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3034 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003035 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003036
Donald Curtis0e209b02015-03-24 09:29:54 -07003037 PeerConnectionInterface::RTCOfferAnswerOptions options;
3038 options.use_rtp_mux = true;
3039
3040 SessionDescriptionInterface* offer = CreateOffer(options);
3041 SetLocalDescriptionWithoutError(offer);
3042
deadbeefcbecd352015-09-23 11:50:27 -07003043 EXPECT_NE(session_->voice_rtp_transport_channel(),
3044 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003045
deadbeefab9b2d12015-10-14 11:33:11 -07003046 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003047
3048 // Remove BUNDLE from the answer.
3049 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3050 CreateRemoteAnswer(session_->local_description()));
3051 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3052 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3053 JsepSessionDescription* modified_answer =
3054 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3055 modified_answer->Initialize(answer_copy, "1", "1");
3056 SetRemoteDescriptionWithoutError(modified_answer); //
3057
deadbeefcbecd352015-09-23 11:50:27 -07003058 EXPECT_NE(session_->voice_rtp_transport_channel(),
3059 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003060}
3061
3062// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3063TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3064 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003065 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003066
3067 PeerConnectionInterface::RTCOfferAnswerOptions options;
3068 options.use_rtp_mux = true;
3069
3070 SessionDescriptionInterface* offer = CreateOffer(options);
3071 SetLocalDescriptionWithoutError(offer);
3072
deadbeefcbecd352015-09-23 11:50:27 -07003073 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3074 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003075
deadbeefab9b2d12015-10-14 11:33:11 -07003076 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003077 SessionDescriptionInterface* answer =
3078 CreateRemoteAnswer(session_->local_description());
3079 SetRemoteDescriptionWithoutError(answer);
3080
deadbeefcbecd352015-09-23 11:50:27 -07003081 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3082 session_->video_rtp_transport_channel());
3083}
3084
3085// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3086// audio content in the answer.
3087TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3088 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003089 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003090
3091 PeerConnectionInterface::RTCOfferAnswerOptions options;
3092 options.use_rtp_mux = true;
3093
3094 SessionDescriptionInterface* offer = CreateOffer(options);
3095 SetLocalDescriptionWithoutError(offer);
3096
3097 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3098 session_->video_rtp_transport_channel());
3099
deadbeefab9b2d12015-10-14 11:33:11 -07003100 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003101 cricket::MediaSessionOptions recv_options;
3102 recv_options.recv_audio = false;
3103 recv_options.recv_video = true;
3104 SessionDescriptionInterface* answer =
3105 CreateRemoteAnswer(session_->local_description(), recv_options);
3106 SetRemoteDescriptionWithoutError(answer);
3107
deadbeefd59daf82015-10-14 15:02:44 -07003108 EXPECT_TRUE(nullptr == session_->voice_channel());
3109 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003110
deadbeefd59daf82015-10-14 15:02:44 -07003111 session_->Close();
3112 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3113 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3114 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3115 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003116}
3117
3118// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3119TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3120 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003121 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003122
Donald Curtis0e209b02015-03-24 09:29:54 -07003123 PeerConnectionInterface::RTCOfferAnswerOptions options;
3124 options.use_rtp_mux = true;
3125
3126 SessionDescriptionInterface* offer = CreateOffer(options);
3127 SetLocalDescriptionWithoutError(offer);
3128
deadbeefcbecd352015-09-23 11:50:27 -07003129 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3130 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003131
deadbeefab9b2d12015-10-14 11:33:11 -07003132 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003133
3134 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003135 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136 CreateRemoteAnswer(session_->local_description()));
3137 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3138 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3139 JsepSessionDescription* modified_answer =
3140 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3141 modified_answer->Initialize(answer_copy, "1", "1");
3142 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143
deadbeefcbecd352015-09-23 11:50:27 -07003144 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3145 session_->video_rtp_transport_channel());
3146}
3147
3148// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3149TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3150 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003151 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003152
3153 SessionDescriptionInterface* offer = CreateRemoteOffer();
3154 SetRemoteDescriptionWithoutError(offer);
3155
3156 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3157 session_->video_rtp_transport_channel());
3158
deadbeefab9b2d12015-10-14 11:33:11 -07003159 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003160 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3161 SetLocalDescriptionWithoutError(answer);
3162
3163 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3164 session_->video_rtp_transport_channel());
3165}
3166
3167// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3168TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3169 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003170 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003171
3172 // Remove BUNDLE from the offer.
3173 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3174 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3175 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3176 JsepSessionDescription* modified_offer =
3177 new JsepSessionDescription(JsepSessionDescription::kOffer);
3178 modified_offer->Initialize(offer_copy, "1", "1");
3179
3180 // Expect an error when applying the remote description
3181 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3182 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003183}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184
Peter Thatcher4eddf182015-04-30 10:55:59 -07003185// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003186TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3187 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189
Donald Curtis0e209b02015-03-24 09:29:54 -07003190 PeerConnectionInterface::RTCOfferAnswerOptions options;
3191 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192
Donald Curtis0e209b02015-03-24 09:29:54 -07003193 SessionDescriptionInterface* offer = CreateOffer(options);
3194 SetLocalDescriptionWithoutError(offer);
3195
deadbeefcbecd352015-09-23 11:50:27 -07003196 EXPECT_NE(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003198
deadbeefab9b2d12015-10-14 11:33:11 -07003199 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003200 SessionDescriptionInterface* answer =
3201 CreateRemoteAnswer(session_->local_description());
3202 SetRemoteDescriptionWithoutError(answer);
3203
3204 // This should lead to an audio-only call but isn't implemented
3205 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003206 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3207 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003208}
3209
deadbeefcbecd352015-09-23 11:50:27 -07003210// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003211TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3212 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003213 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003214 PeerConnectionInterface::RTCOfferAnswerOptions options;
3215 options.use_rtp_mux = true;
3216
3217 SessionDescriptionInterface* offer = CreateOffer(options);
3218 SetLocalDescriptionWithoutError(offer);
3219
deadbeefcbecd352015-09-23 11:50:27 -07003220 EXPECT_NE(session_->voice_rtp_transport_channel(),
3221 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003222
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003224
3225 // Remove BUNDLE from the answer.
3226 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3227 CreateRemoteAnswer(session_->local_description()));
3228 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3229 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3230 JsepSessionDescription* modified_answer =
3231 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3232 modified_answer->Initialize(answer_copy, "1", "1");
3233 SetRemoteDescriptionWithoutError(modified_answer); //
3234
deadbeefcbecd352015-09-23 11:50:27 -07003235 EXPECT_NE(session_->voice_rtp_transport_channel(),
3236 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237}
3238
Peter Thatcher4eddf182015-04-30 10:55:59 -07003239// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3240TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3241 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003242 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003243
3244 PeerConnectionInterface::RTCOfferAnswerOptions options;
3245 options.use_rtp_mux = true;
3246
3247 SessionDescriptionInterface* offer = CreateOffer(options);
3248 SetRemoteDescriptionWithoutError(offer);
3249
deadbeefcbecd352015-09-23 11:50:27 -07003250 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3251 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003252}
3253
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003254TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3255 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003256 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003257
3258 PeerConnectionInterface::RTCOfferAnswerOptions options;
3259 SessionDescriptionInterface* offer = CreateOffer(options);
3260 SetLocalDescriptionWithoutError(offer);
3261
deadbeefcbecd352015-09-23 11:50:27 -07003262 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3263 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003264
deadbeefab9b2d12015-10-14 11:33:11 -07003265 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003266 SessionDescriptionInterface* answer =
3267 CreateRemoteAnswer(session_->local_description());
3268 SetRemoteDescriptionWithoutError(answer);
3269
deadbeefcbecd352015-09-23 11:50:27 -07003270 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3271 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003272}
3273
3274TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3275 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003276 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003277
3278 PeerConnectionInterface::RTCOfferAnswerOptions options;
3279 SessionDescriptionInterface* offer = CreateOffer(options);
3280 SetLocalDescriptionWithoutError(offer);
3281
deadbeefcbecd352015-09-23 11:50:27 -07003282 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3283 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003284
deadbeefab9b2d12015-10-14 11:33:11 -07003285 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003286 SessionDescriptionInterface* answer =
3287 CreateRemoteAnswer(session_->local_description());
3288 SetRemoteDescriptionWithoutError(answer);
3289
deadbeefcbecd352015-09-23 11:50:27 -07003290 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3291 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003292}
3293
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003294// This test verifies that SetLocalDescription and SetRemoteDescription fails
3295// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3296TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003297 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003299
3300 PeerConnectionInterface::RTCOfferAnswerOptions options;
3301 options.use_rtp_mux = true;
3302
3303 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003304 std::string offer_str;
3305 offer->ToString(&offer_str);
3306 // Disable rtcp-mux
3307 const std::string rtcp_mux = "rtcp-mux";
3308 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003310 xrtcp_mux.c_str(), xrtcp_mux.length(),
3311 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003312 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003313 new JsepSessionDescription(JsepSessionDescription::kOffer);
3314 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003315 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003316 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003317 new JsepSessionDescription(JsepSessionDescription::kOffer);
3318 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003319 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003320 // Trying unmodified SDP.
3321 SetLocalDescriptionWithoutError(offer);
3322}
3323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003325 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003326 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 CreateAndSetRemoteOfferAndLocalAnswer();
3328 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3329 ASSERT_TRUE(channel != NULL);
3330 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003331 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003332 double volume;
3333 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3334 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003335 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003336 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3337 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003338 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003339 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3340 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341}
3342
3343TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003344 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003345 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 CreateAndSetRemoteOfferAndLocalAnswer();
3347 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3348 ASSERT_TRUE(channel != NULL);
3349 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003350 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3352
3353 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003354 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003356 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003357 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003359 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003360 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003361
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003362 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003363 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003365 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003366 EXPECT_TRUE(renderer->sink() == NULL);
3367}
3368
3369TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003370 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003371 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003372 CreateAndSetRemoteOfferAndLocalAnswer();
3373 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3374 ASSERT_TRUE(channel != NULL);
3375 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003376 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003377
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003378 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003379 cricket::AudioOptions options;
3380 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3381 EXPECT_TRUE(renderer->sink() != NULL);
3382
3383 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3384 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3385 // SetSink(NULL) callback afterwards.
3386 renderer.reset();
3387
3388 // This will trigger SetSink(NULL) if no OnClose() callback.
3389 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390}
3391
3392TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003393 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003394 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395 CreateAndSetRemoteOfferAndLocalAnswer();
3396 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3397 ASSERT_TRUE(channel != NULL);
3398 ASSERT_LT(0u, channel->renderers().size());
3399 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3400 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003401 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 cricket::FakeVideoRenderer renderer;
3403 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3404 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3405 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3406 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3407}
3408
3409TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003410 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003411 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 CreateAndSetRemoteOfferAndLocalAnswer();
3413 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3414 ASSERT_TRUE(channel != NULL);
3415 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003416 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3418 cricket::VideoOptions* options = NULL;
3419 session_->SetVideoSend(send_ssrc, false, options);
3420 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3421 session_->SetVideoSend(send_ssrc, true, options);
3422 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3423}
3424
3425TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3426 TestCanInsertDtmf(false);
3427}
3428
3429TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3430 TestCanInsertDtmf(true);
3431}
3432
3433TEST_F(WebRtcSessionTest, InsertDtmf) {
3434 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003435 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 CreateAndSetRemoteOfferAndLocalAnswer();
3438 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3439 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3440
3441 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 const int expected_duration = 90;
3443 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3444 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3445 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3446
3447 // Verify
3448 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003449 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003451 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003453 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003455 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456}
3457
deadbeefd59daf82015-10-14 15:02:44 -07003458// This test verifies the |initial_offerer| flag when session initiates the
3459// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003461 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003462 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003463 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3465 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003466 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003468 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469}
3470
deadbeefd59daf82015-10-14 15:02:44 -07003471// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003473 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003474 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475 SessionDescriptionInterface* offer = CreateRemoteOffer();
3476 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003477 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478
deadbeefd59daf82015-10-14 15:02:44 -07003479 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003481 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482}
3483
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3485TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003486 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003487 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003488 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003490 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 CreateRemoteAnswer(session_->local_description()));
3492
3493 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3494 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003495 JsepSessionDescription* modified_answer =
3496 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497
3498 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3499 answer->session_id(),
3500 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003501 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502
wu@webrtc.org4e393072014-04-07 17:04:35 +00003503 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 std::string sdp;
3505 EXPECT_TRUE(answer->ToString(&sdp));
3506 const std::string kAudioMid = "a=mid:audio";
3507 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003508 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509 kAudioMidReplaceStr.c_str(),
3510 kAudioMidReplaceStr.length(),
3511 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003512 SessionDescriptionInterface* modified_answer1 =
3513 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003514 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515
wu@webrtc.org4e393072014-04-07 17:04:35 +00003516 // Different media types.
3517 EXPECT_TRUE(answer->ToString(&sdp));
3518 const std::string kAudioMline = "m=audio";
3519 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003520 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003521 kAudioMlineReplaceStr.c_str(),
3522 kAudioMlineReplaceStr.length(),
3523 &sdp);
3524 SessionDescriptionInterface* modified_answer2 =
3525 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3526 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3527
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 SetRemoteDescriptionWithoutError(answer.release());
3529}
3530
3531// Verifying remote offer and local answer have matching m-lines as per
3532// RFC 3264.
3533TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003534 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003535 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536 SessionDescriptionInterface* offer = CreateRemoteOffer();
3537 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003538 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539
3540 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3541 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003542 JsepSessionDescription* modified_answer =
3543 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544
3545 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3546 answer->session_id(),
3547 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003548 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 SetLocalDescriptionWithoutError(answer);
3550}
3551
3552// This test verifies that WebRtcSession does not start candidate allocation
3553// before SetLocalDescription is called.
3554TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003555 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003556 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003557 SessionDescriptionInterface* offer = CreateRemoteOffer();
3558 cricket::Candidate candidate;
3559 candidate.set_component(1);
3560 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3561 candidate);
3562 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3563 cricket::Candidate candidate1;
3564 candidate1.set_component(1);
3565 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3566 candidate1);
3567 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3568 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003569 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3570 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571
3572 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003573 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3575 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3576
wu@webrtc.org91053e72013-08-10 07:18:04 +00003577 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3580}
3581
3582// This test verifies that crypto parameter is updated in local session
3583// description as per security policy set in MediaSessionDescriptionFactory.
3584TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003585 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003586 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003587 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588
3589 // Making sure SetLocalDescription correctly sets crypto value in
3590 // SessionDescription object after de-serialization of sdp string. The value
3591 // will be set as per MediaSessionDescriptionFactory.
3592 std::string offer_str;
3593 offer->ToString(&offer_str);
3594 SessionDescriptionInterface* jsep_offer_str =
3595 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3596 SetLocalDescriptionWithoutError(jsep_offer_str);
3597 EXPECT_TRUE(session_->voice_channel()->secure_required());
3598 EXPECT_TRUE(session_->video_channel()->secure_required());
3599}
3600
3601// This test verifies the crypto parameter when security is disabled.
3602TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003603 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003604 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003605 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003606 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607
3608 // Making sure SetLocalDescription correctly sets crypto value in
3609 // SessionDescription object after de-serialization of sdp string. The value
3610 // will be set as per MediaSessionDescriptionFactory.
3611 std::string offer_str;
3612 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003613 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3615 SetLocalDescriptionWithoutError(jsep_offer_str);
3616 EXPECT_FALSE(session_->voice_channel()->secure_required());
3617 EXPECT_FALSE(session_->video_channel()->secure_required());
3618}
3619
3620// This test verifies that an answer contains new ufrag and password if an offer
3621// with new ufrag and password is received.
3622TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003623 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003625 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003626 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003627 CreateRemoteOffer(options));
3628 SetRemoteDescriptionWithoutError(offer.release());
3629
deadbeefab9b2d12015-10-14 11:33:11 -07003630 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003631 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003632 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633 SetLocalDescriptionWithoutError(answer.release());
3634
3635 // Receive an offer with new ufrag and password.
3636 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003637 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003638 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003639 SetRemoteDescriptionWithoutError(updated_offer1.release());
3640
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003641 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003642 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643
3644 CompareIceUfragAndPassword(updated_answer1->description(),
3645 session_->local_description()->description(),
3646 false);
3647
3648 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003649}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650
wu@webrtc.org91053e72013-08-10 07:18:04 +00003651// This test verifies that an answer contains old ufrag and password if an offer
3652// with old ufrag and password is received.
3653TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003654 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003655 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003656 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003657 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003658 CreateRemoteOffer(options));
3659 SetRemoteDescriptionWithoutError(offer.release());
3660
deadbeefab9b2d12015-10-14 11:33:11 -07003661 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003662 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003663 CreateAnswer(NULL));
3664 SetLocalDescriptionWithoutError(answer.release());
3665
3666 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003668 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003669 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 SetRemoteDescriptionWithoutError(updated_offer2.release());
3671
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003672 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003673 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674
3675 CompareIceUfragAndPassword(updated_answer2->description(),
3676 session_->local_description()->description(),
3677 true);
3678
3679 SetLocalDescriptionWithoutError(updated_answer2.release());
3680}
3681
3682TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003683 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003684 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003685 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686 const std::string session_id_orig = offer->session_id();
3687 const std::string session_version_orig = offer->session_version();
3688 SetLocalDescriptionWithoutError(offer);
3689
3690 video_channel_ = media_engine_->GetVideoChannel(0);
3691 video_channel_->set_fail_set_send_codecs(true);
3692
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003693 SessionDescriptionInterface* answer =
3694 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003695 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003696
3697 // Test that after a content error, setting any description will
3698 // result in an error.
3699 video_channel_->set_fail_set_send_codecs(false);
3700 answer = CreateRemoteAnswer(session_->local_description());
3701 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3702 offer = CreateRemoteOffer();
3703 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704}
3705
3706// Runs the loopback call test with BUNDLE and STUN disabled.
3707TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3708 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003709 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003710 cricket::PORTALLOCATOR_DISABLE_STUN |
3711 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712 TestLoopbackCall();
3713}
3714
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003715TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003716 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003717 cricket::PORTALLOCATOR_DISABLE_STUN |
3718 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3719 cricket::PORTALLOCATOR_DISABLE_RELAY);
3720
3721 // best connection is IPv6 since it has higher network preference.
3722 LoopbackNetworkConfiguration config;
3723 config.test_ipv6_network_ = true;
3724 config.best_connection_after_initial_ice_converged_ =
3725 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3726
3727 TestLoopbackCall(config);
3728}
3729
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003730// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003731TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003732 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3733 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003734 TestLoopbackCall();
3735}
3736
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3738 constraints_.reset(new FakeConstraints());
3739 constraints_->AddOptional(
3740 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003741 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742
3743 SetLocalDescriptionWithDataChannel();
3744 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3745}
3746
Henrik Boström87713d02015-08-25 09:53:21 +02003747TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003748 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749
3750 constraints_.reset(new FakeConstraints());
3751 constraints_->AddOptional(
3752 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003753 options_.disable_sctp_data_channels = false;
3754
Henrik Boström87713d02015-08-25 09:53:21 +02003755 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003756
3757 SetLocalDescriptionWithDataChannel();
3758 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3759}
3760
Henrik Boström87713d02015-08-25 09:53:21 +02003761TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003762 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003763
Henrik Boström87713d02015-08-25 09:53:21 +02003764 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003765
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003766 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003767 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003768 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3769}
3770
Henrik Boström87713d02015-08-25 09:53:21 +02003771TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003772 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003773 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003774 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003775
3776 // Create remote offer with SCTP.
3777 cricket::MediaSessionOptions options;
3778 options.data_channel_type = cricket::DCT_SCTP;
3779 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003780 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003781 SetRemoteDescriptionWithoutError(offer);
3782
3783 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003784 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003785 EXPECT_TRUE(answer != NULL);
3786 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3787 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003788}
3789
Henrik Boström87713d02015-08-25 09:53:21 +02003790TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003791 constraints_.reset(new FakeConstraints());
3792 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003793 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003794 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003795
3796 SetLocalDescriptionWithDataChannel();
3797 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3798}
3799
Henrik Boström87713d02015-08-25 09:53:21 +02003800TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003801 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003802
Henrik Boström87713d02015-08-25 09:53:21 +02003803 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003804
3805 SetLocalDescriptionWithDataChannel();
3806 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3807}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003808
Henrik Boström87713d02015-08-25 09:53:21 +02003809TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003810 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003811 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003812 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003813
3814 SetLocalDescriptionWithDataChannel();
3815 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3816}
3817
Henrik Boström87713d02015-08-25 09:53:21 +02003818TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003820 const int new_send_port = 9998;
3821 const int new_recv_port = 7775;
3822
Henrik Boström87713d02015-08-25 09:53:21 +02003823 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003824 SetFactoryDtlsSrtp();
3825
3826 // By default, don't actually add the codecs to desc_factory_; they don't
3827 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3828 // let the session description get parsed. That'll get the proper codecs
3829 // into the stream.
3830 cricket::MediaSessionOptions options;
3831 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3832 "stream1", new_send_port, options);
3833
3834 // SetRemoteDescription will take the ownership of the offer.
3835 SetRemoteDescriptionWithoutError(offer);
3836
3837 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3838 new_recv_port, CreateAnswer(NULL));
3839 ASSERT_TRUE(answer != NULL);
3840
3841 // Now set the local description, which'll take ownership of the answer.
3842 SetLocalDescriptionWithoutError(answer);
3843
3844 // TEST PLAN: Set the port number to something new, set it in the SDP,
3845 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003846 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003847 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003848
3849 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3850 int portnum = -1;
3851 ASSERT_TRUE(ch != NULL);
3852 ASSERT_EQ(1UL, ch->send_codecs().size());
3853 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003854 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003855 ch->send_codecs()[0].name.c_str()));
3856 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3857 &portnum));
3858 EXPECT_EQ(new_send_port, portnum);
3859
3860 ASSERT_EQ(1UL, ch->recv_codecs().size());
3861 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003862 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003863 ch->recv_codecs()[0].name.c_str()));
3864 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3865 &portnum));
3866 EXPECT_EQ(new_recv_port, portnum);
3867}
3868
deadbeefab9b2d12015-10-14 11:33:11 -07003869// Verifies that when a session's DataChannel receives an OPEN message,
3870// WebRtcSession signals the DataChannel creation request with the expected
3871// config.
3872TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3873 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3874
3875 InitWithDtls(GetParam());
3876
3877 SetLocalDescriptionWithDataChannel();
3878 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3879
3880 webrtc::DataChannelInit config;
3881 config.id = 1;
3882 rtc::Buffer payload;
3883 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3884 cricket::ReceiveDataParams params;
3885 params.ssrc = config.id;
3886 params.type = cricket::DMT_CONTROL;
3887
3888 cricket::DataChannel* data_channel = session_->data_channel();
3889 data_channel->SignalDataReceived(data_channel, params, payload);
3890
3891 EXPECT_EQ("a", last_data_channel_label_);
3892 EXPECT_EQ(config.id, last_data_channel_config_.id);
3893 EXPECT_FALSE(last_data_channel_config_.negotiated);
3894 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3895 last_data_channel_config_.open_handshake_role);
3896}
3897
3898TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003899 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3900 FakeDtlsIdentityStore::GenerateCertificate();
3901
3902 PeerConnectionInterface::RTCConfiguration configuration;
3903 configuration.certificates.push_back(certificate);
3904 Init(nullptr, configuration);
3905 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3906
3907 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3908}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003909
Henrik Boström87713d02015-08-25 09:53:21 +02003910// Verifies that CreateOffer succeeds when CreateOffer is called before async
3911// identity generation is finished (even if a certificate is provided this is
3912// an async op).
3913TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3914 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3915 InitWithDtls(GetParam());
3916
Henrik Boströmd8281982015-08-27 10:12:24 +02003917 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003918 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003919 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3920
wu@webrtc.org91053e72013-08-10 07:18:04 +00003921 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003922 VerifyNoCryptoParams(offer->description(), true);
3923 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003924}
3925
3926// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003927// identity generation is finished (even if a certificate is provided this is
3928// an async op).
3929TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003930 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003931 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003932 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003933
3934 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003935 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003936 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003937 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003938 ASSERT_TRUE(offer.get() != NULL);
3939 SetRemoteDescriptionWithoutError(offer.release());
3940
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003941 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003942 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003943 VerifyNoCryptoParams(answer->description(), true);
3944 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003945}
3946
3947// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003948// identity generation is finished (even if a certificate is provided this is
3949// an async op).
3950TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003951 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003952 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003953
Henrik Boströmd8281982015-08-27 10:12:24 +02003954 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003955
3956 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003957 EXPECT_TRUE(offer != NULL);
3958}
3959
3960// Verifies that CreateOffer fails when CreateOffer is called after async
3961// identity generation fails.
3962TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003963 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003964 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003965
Henrik Boströmd8281982015-08-27 10:12:24 +02003966 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003967
3968 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003969 EXPECT_TRUE(offer == NULL);
3970}
3971
3972// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3973// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003974TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003975 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003976 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003977 VerifyMultipleAsyncCreateDescription(GetParam(),
3978 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003979}
3980
3981// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3982// before async identity generation fails.
3983TEST_F(WebRtcSessionTest,
3984 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003985 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003986 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3987 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003988}
3989
3990// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3991// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003992TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003993 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003994 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003995 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003996 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003997}
3998
3999// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4000// before async identity generation fails.
4001TEST_F(WebRtcSessionTest,
4002 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004003 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004004 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4005 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004006}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004007
4008// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4009// offer has no SDES crypto but only DTLS fingerprint.
4010TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4011 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004012 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004013 // Create a remote offer with secured transport disabled.
4014 cricket::MediaSessionOptions options;
4015 JsepSessionDescription* offer(CreateRemoteOffer(
4016 options, cricket::SEC_DISABLED));
4017 // Adds a DTLS fingerprint to the remote offer.
4018 cricket::SessionDescription* sdp = offer->description();
4019 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4020 ASSERT_TRUE(audio != NULL);
4021 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4022 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004023 rtc::SSLFingerprint::CreateFromRfc4572(
4024 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004025 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004026 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004027}
4028
wu@webrtc.orgde305012013-10-31 15:40:38 +00004029// This test verifies DSCP is properly applied on the media channels.
4030TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4031 constraints_.reset(new FakeConstraints());
4032 constraints_->AddOptional(
4033 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004034 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004035 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004036 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004037
4038 SetLocalDescriptionWithoutError(offer);
4039
4040 video_channel_ = media_engine_->GetVideoChannel(0);
4041 voice_channel_ = media_engine_->GetVoiceChannel(0);
4042
4043 ASSERT_TRUE(video_channel_ != NULL);
4044 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004045 const cricket::AudioOptions& audio_options = voice_channel_->options();
4046 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004047 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4048 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004049}
4050
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004051TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4052 constraints_.reset(new FakeConstraints());
4053 constraints_->AddOptional(
4054 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4055 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004057 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004058 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004059
4060 SetLocalDescriptionWithoutError(offer);
4061
4062 video_channel_ = media_engine_->GetVideoChannel(0);
4063
4064 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004065 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004066 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004067}
4068
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004069TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4070 // Number of unsignalled receiving streams should be between 0 and
4071 // kMaxUnsignalledRecvStreams.
4072 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4073 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4074 kMaxUnsignalledRecvStreams);
4075 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4076}
4077
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004078TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4079 constraints_.reset(new FakeConstraints());
4080 constraints_->AddOptional(
4081 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4082 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004083 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004084 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004085 SessionDescriptionInterface* offer = CreateOffer();
4086
4087 SetLocalDescriptionWithoutError(offer);
4088
4089 voice_channel_ = media_engine_->GetVoiceChannel(0);
4090
4091 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004092 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004093 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004094}
4095
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004096// Tests that we can renegotiate new media content with ICE candidates in the
4097// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004098TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004099 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004100 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004101 SetFactoryDtlsSrtp();
4102
deadbeefab9b2d12015-10-14 11:33:11 -07004103 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004104 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004105 SetLocalDescriptionWithoutError(offer);
4106
4107 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4108 SetRemoteDescriptionWithoutError(answer);
4109
4110 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004111 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004112 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4113
4114 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004115 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004116 candidate1.set_component(1);
4117 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4118 candidate1);
4119 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4120 SetRemoteDescriptionWithoutError(offer);
4121
4122 answer = CreateAnswer(NULL);
4123 SetLocalDescriptionWithoutError(answer);
4124}
4125
4126// Tests that we can renegotiate new media content with ICE candidates separated
4127// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004128TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004129 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004130 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004131 SetFactoryDtlsSrtp();
4132
deadbeefab9b2d12015-10-14 11:33:11 -07004133 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004134 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004135 SetLocalDescriptionWithoutError(offer);
4136
4137 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4138 SetRemoteDescriptionWithoutError(answer);
4139
4140 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004141 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004142 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4143 SetRemoteDescriptionWithoutError(offer);
4144
4145 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004146 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004147 candidate1.set_component(1);
4148 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4149 candidate1);
4150 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4151
4152 answer = CreateAnswer(NULL);
4153 SetLocalDescriptionWithoutError(answer);
4154}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004155// Tests that RTX codec is removed from the answer when it isn't supported
4156// by local side.
4157TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4158 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004159 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004160 std::string offer_sdp(kSdpWithRtx);
4161
4162 SessionDescriptionInterface* offer =
4163 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4164 EXPECT_TRUE(offer->ToString(&offer_sdp));
4165
4166 // Offer SDP contains the RTX codec.
4167 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4168 SetRemoteDescriptionWithoutError(offer);
4169
4170 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4171 std::string answer_sdp;
4172 answer->ToString(&answer_sdp);
4173 // Answer SDP removes the unsupported RTX codec.
4174 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4175 SetLocalDescriptionWithoutError(answer);
4176}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004177
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004178// This verifies that the voice channel after bundle has both options from video
4179// and voice channels.
4180TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4181 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004182 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004183
4184 PeerConnectionInterface::RTCOfferAnswerOptions options;
4185 options.use_rtp_mux = true;
4186
4187 SessionDescriptionInterface* offer = CreateOffer(options);
4188 SetLocalDescriptionWithoutError(offer);
4189
4190 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4191 rtc::Socket::Option::OPT_SNDBUF, 4000);
4192
4193 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4194 rtc::Socket::Option::OPT_RCVBUF, 8000);
4195
4196 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004197 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004198 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4199 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004200 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004201 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4202
deadbeefcbecd352015-09-23 11:50:27 -07004203 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004204 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4205 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004206 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004207 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4208
deadbeefcbecd352015-09-23 11:50:27 -07004209 EXPECT_NE(session_->voice_rtp_transport_channel(),
4210 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004211
deadbeefab9b2d12015-10-14 11:33:11 -07004212 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004213 SessionDescriptionInterface* answer =
4214 CreateRemoteAnswer(session_->local_description());
4215 SetRemoteDescriptionWithoutError(answer);
4216
deadbeefcbecd352015-09-23 11:50:27 -07004217 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004218 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4219 EXPECT_EQ(4000, option_val);
4220
deadbeefcbecd352015-09-23 11:50:27 -07004221 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004222 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4223 EXPECT_EQ(8000, option_val);
4224}
4225
tommi0f620f42015-07-09 03:25:02 -07004226// Test creating a session, request multiple offers, destroy the session
4227// and make sure we got success/failure callbacks for all of the requests.
4228// Background: crbug.com/507307
4229TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4230 Init();
4231
4232 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4233 PeerConnectionInterface::RTCOfferAnswerOptions options;
4234 options.offer_to_receive_audio =
4235 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004236 cricket::MediaSessionOptions session_options;
4237 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004238
4239 for (auto& o : observers) {
4240 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004241 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004242 }
4243
4244 session_.reset();
4245
tommi0f620f42015-07-09 03:25:02 -07004246 for (auto& o : observers) {
4247 // We expect to have received a notification now even if the session was
4248 // terminated. The offer creation may or may not have succeeded, but we
4249 // must have received a notification which, so the only invalid state
4250 // is kInit.
4251 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4252 }
4253}
4254
stefanc1aeaf02015-10-15 07:26:07 -07004255TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4256 TestPacketOptions();
4257}
4258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004259// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4260// currently fails because upon disconnection and reconnection OnIceComplete is
4261// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004262
deadbeefcbecd352015-09-23 11:50:27 -07004263INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4264 WebRtcSessionTest,
4265 testing::Values(ALREADY_GENERATED,
4266 DTLS_IDENTITY_STORE));