blob: e81b8b5b545cb57ad7c84f2e56d38fddd2f19ae5 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
kwiberg0eb15ed2015-12-17 03:04:15 -080028#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070029#include <vector>
30
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/app/webrtc/audiotrack.h"
stefanc1aeaf02015-10-15 07:26:07 -070032#include "talk/app/webrtc/fakemediacontroller.h"
jbauchac8869e2015-07-03 01:36:14 -070033#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/jsepicecandidate.h"
35#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070036#include "talk/app/webrtc/peerconnection.h"
deadbeefab9b2d12015-10-14 11:33:11 -070037#include "talk/app/webrtc/sctputils.h"
38#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020041#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000044#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/media/base/fakemediaengine.h"
46#include "talk/media/base/fakevideorenderer.h"
47#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070048#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000049#include "webrtc/p2p/base/stunserver.h"
50#include "webrtc/p2p/base/teststunserver.h"
51#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000052#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000054#include "talk/session/media/channelmanager.h"
55#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056#include "webrtc/base/fakenetwork.h"
57#include "webrtc/base/firewallsocketserver.h"
58#include "webrtc/base/gunit.h"
59#include "webrtc/base/logging.h"
60#include "webrtc/base/network.h"
61#include "webrtc/base/physicalsocketserver.h"
62#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020063#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064#include "webrtc/base/sslstreamadapter.h"
65#include "webrtc/base/stringutils.h"
66#include "webrtc/base/thread.h"
67#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
69#define MAYBE_SKIP_TEST(feature) \
70 if (!(feature())) { \
71 LOG(LS_INFO) << "Feature disabled... skipping"; \
72 return; \
73 }
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070083using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020084using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070086using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070088using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::JsepIceCandidate;
90using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000091using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::PeerConnectionInterface;
93using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070094using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000096using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000097using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kCreateChannelFailed;
99using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000103using webrtc::kSdpWithoutDtlsFingerprint;
104using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000106using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000107using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000109typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
110
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111static const int kClientAddrPort = 0;
112static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000113static const char kClientIPv6AddrHost1[] =
114 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000115static const char kClientAddrHost2[] = "22.22.22.22";
116static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000117static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
118static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000119static const char kTurnUsername[] = "test";
120static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122static const char kSessionVersion[] = "1";
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Media index of candidates belonging to the first media content.
125static const int kMediaContentIndex0 = 0;
126static const char kMediaContentName0[] = "audio";
127
128// Media index of candidates belonging to the second media content.
129static const int kMediaContentIndex1 = 1;
130static const char kMediaContentName1[] = "video";
131
132static const int kIceCandidatesTimeout = 10000;
133
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000134static const char kFakeDtlsFingerprint[] =
135 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
136 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
137
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000138static const char kTooLongIceUfragPwd[] =
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
143
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000144static const char kSdpWithRtx[] =
145 "v=0\r\n"
146 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
149 "a=msid-semantic: WMS stream1\r\n"
150 "m=video 9 RTP/SAVPF 0 96\r\n"
151 "c=IN IP4 0.0.0.0\r\n"
152 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
153 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
154 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
155 "a=mid:video\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
159 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
160 "a=rtpmap:0 fake_video_codec/90000\r\n"
161 "a=rtpmap:96 rtx/90000\r\n"
162 "a=fmtp:96 apt=0\r\n";
163
deadbeefab9b2d12015-10-14 11:33:11 -0700164static const char kStream1[] = "stream1";
165static const char kVideoTrack1[] = "video1";
166static const char kAudioTrack1[] = "audio1";
167
168static const char kStream2[] = "stream2";
169static const char kVideoTrack2[] = "video2";
170static const char kAudioTrack2[] = "audio2";
171
Henrik Boström87713d02015-08-25 09:53:21 +0200172enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174class MockIceObserver : public webrtc::IceObserver {
175 public:
176 MockIceObserver()
177 : oncandidatesready_(false),
178 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
179 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
180 }
181
182 virtual void OnIceConnectionChange(
183 PeerConnectionInterface::IceConnectionState new_state) {
184 ice_connection_state_ = new_state;
185 }
186 virtual void OnIceGatheringChange(
187 PeerConnectionInterface::IceGatheringState new_state) {
188 // We can never transition back to "new".
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
190 ice_gathering_state_ = new_state;
191
192 // oncandidatesready_ really means "ICE gathering is complete".
193 // This if statement ensures that this value remains correct when we
194 // transition from kIceGatheringComplete to kIceGatheringGathering.
195 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
196 oncandidatesready_ = false;
197 }
198 }
199
200 // Found a new candidate.
201 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000202 switch (candidate->sdp_mline_index()) {
203 case kMediaContentIndex0:
204 mline_0_candidates_.push_back(candidate->candidate());
205 break;
206 case kMediaContentIndex1:
207 mline_1_candidates_.push_back(candidate->candidate());
208 break;
209 default:
210 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000212
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 // The ICE gathering state should always be Gathering when a candidate is
214 // received (or possibly Completed in the case of the final candidate).
215 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
216 }
217
218 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
219 virtual void OnIceComplete() {
220 EXPECT_FALSE(oncandidatesready_);
221 oncandidatesready_ = true;
222
223 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
224 // be called approximately simultaneously. For ease of testing, this
225 // check additionally requires that they be called in the above order.
226 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
227 ice_gathering_state_);
228 }
229
230 bool oncandidatesready_;
231 std::vector<cricket::Candidate> mline_0_candidates_;
232 std::vector<cricket::Candidate> mline_1_candidates_;
233 PeerConnectionInterface::IceConnectionState ice_connection_state_;
234 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
235};
236
237class WebRtcSessionForTest : public webrtc::WebRtcSession {
238 public:
stefanc1aeaf02015-10-15 07:26:07 -0700239 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000240 rtc::Thread* signaling_thread,
241 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700243 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700244 : WebRtcSession(media_controller,
245 signaling_thread,
246 worker_thread,
247 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 RegisterIceObserver(ice_observer);
249 }
250 virtual ~WebRtcSessionForTest() {}
251
deadbeefcbecd352015-09-23 11:50:27 -0700252 // Note that these methods are only safe to use if the signaling thread
253 // is the same as the worker thread
254 cricket::TransportChannel* voice_rtp_transport_channel() {
255 return rtp_transport_channel(voice_channel());
256 }
257
258 cricket::TransportChannel* voice_rtcp_transport_channel() {
259 return rtcp_transport_channel(voice_channel());
260 }
261
262 cricket::TransportChannel* video_rtp_transport_channel() {
263 return rtp_transport_channel(video_channel());
264 }
265
266 cricket::TransportChannel* video_rtcp_transport_channel() {
267 return rtcp_transport_channel(video_channel());
268 }
269
270 cricket::TransportChannel* data_rtp_transport_channel() {
271 return rtp_transport_channel(data_channel());
272 }
273
274 cricket::TransportChannel* data_rtcp_transport_channel() {
275 return rtcp_transport_channel(data_channel());
276 }
277
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 using webrtc::WebRtcSession::SetAudioPlayout;
279 using webrtc::WebRtcSession::SetAudioSend;
280 using webrtc::WebRtcSession::SetCaptureDevice;
281 using webrtc::WebRtcSession::SetVideoPlayout;
282 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700283
284 private:
285 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
286 if (!ch) {
287 return nullptr;
288 }
289 return ch->transport_channel();
290 }
291
292 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
293 if (!ch) {
294 return nullptr;
295 }
296 return ch->rtcp_transport_channel();
297 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298};
299
wu@webrtc.org91053e72013-08-10 07:18:04 +0000300class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000301 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 enum State {
304 kInit,
305 kFailed,
306 kSucceeded,
307 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000308 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309
310 // CreateSessionDescriptionObserver implementation.
311 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000312 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000313 state_ = kSucceeded;
314 }
315 virtual void OnFailure(const std::string& error) {
316 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
318
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000319 SessionDescriptionInterface* description() { return description_.get(); }
320
321 SessionDescriptionInterface* ReleaseDescription() {
322 return description_.release();
323 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324
wu@webrtc.org91053e72013-08-10 07:18:04 +0000325 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326
wu@webrtc.org91053e72013-08-10 07:18:04 +0000327 protected:
328 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329
330 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000332 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333};
334
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000335class FakeAudioRenderer : public cricket::AudioRenderer {
336 public:
solenberg98c68862015-10-09 03:27:14 -0700337 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000338 virtual ~FakeAudioRenderer() {
339 if (sink_)
340 sink_->OnClose();
341 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000342
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000343 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000344
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000345 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000346 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000347 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000348};
349
Henrik Boström87713d02015-08-25 09:53:21 +0200350class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700351 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
352 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 protected:
354 // TODO Investigate why ChannelManager crashes, if it's created
355 // after stun_server.
356 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700357 : media_engine_(new cricket::FakeMediaEngine()),
358 data_engine_(new cricket::FakeDataEngine()),
359 channel_manager_(
360 new cricket::ChannelManager(media_engine_,
361 data_engine_,
362 new cricket::CaptureManager(),
363 rtc::Thread::Current())),
364 fake_call_(webrtc::Call::Config()),
365 media_controller_(
366 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
367 channel_manager_.get())),
368 tdesc_factory_(new cricket::TransportDescriptionFactory()),
369 desc_factory_(
370 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
371 tdesc_factory_.get())),
372 pss_(new rtc::PhysicalSocketServer),
373 vss_(new rtc::VirtualSocketServer(pss_.get())),
374 fss_(new rtc::FirewallSocketServer(vss_.get())),
375 ss_scope_(fss_.get()),
376 stun_socket_addr_(
377 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
378 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
379 stun_socket_addr_)),
380 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
381 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000382 cricket::ServerAddresses stun_servers;
383 stun_servers.insert(stun_socket_addr_);
384 allocator_.reset(new cricket::BasicPortAllocator(
385 &network_manager_,
386 stun_servers,
387 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000388 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700389 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 EXPECT_TRUE(channel_manager_->Init());
391 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000392 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 }
394
395 void AddInterface(const SocketAddress& addr) {
396 network_manager_.AddInterface(addr);
397 }
398
Henrik Boström87713d02015-08-25 09:53:21 +0200399 // If |dtls_identity_store| != null or |rtc_configuration| contains
400 // |certificates| then DTLS will be enabled unless explicitly disabled by
401 // |rtc_configuration| options. When DTLS is enabled a certificate will be
402 // used if provided, otherwise one will be generated using the
403 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000404 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200405 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200406 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 ASSERT_TRUE(session_.get() == NULL);
408 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700409 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700410 allocator_.get(), &observer_));
411 session_->SignalDataChannelOpenMessage.connect(
412 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413
414 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
415 observer_.ice_connection_state_);
416 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
417 observer_.ice_gathering_state_);
418
deadbeefcbecd352015-09-23 11:50:27 -0700419 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800420 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700421 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700422 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423 }
424
deadbeefab9b2d12015-10-14 11:33:11 -0700425 void OnDataChannelOpenMessage(const std::string& label,
426 const InternalDataChannelInit& config) {
427 last_data_channel_label_ = label;
428 last_data_channel_config_ = config;
429 }
430
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000431 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200432 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200433 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000434 }
435
436 void InitWithIceTransport(
437 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200438 PeerConnectionInterface::RTCConfiguration configuration;
439 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200440 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000441 }
442
443 void InitWithBundlePolicy(
444 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200445 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200446 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200447 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700448 }
449
450 void InitWithRtcpMuxPolicy(
451 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
452 PeerConnectionInterface::RTCConfiguration configuration;
453 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200454 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000455 }
456
Henrik Boström87713d02015-08-25 09:53:21 +0200457 // Successfully init with DTLS; with a certificate generated and supplied or
458 // with a store that generates it for us.
459 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
460 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
461 PeerConnectionInterface::RTCConfiguration configuration;
462 if (cert_gen_method == ALREADY_GENERATED) {
463 configuration.certificates.push_back(
464 FakeDtlsIdentityStore::GenerateCertificate());
465 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
466 dtls_identity_store.reset(new FakeDtlsIdentityStore());
467 dtls_identity_store->set_should_fail(false);
468 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700469 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200470 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800471 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200472 }
473
474 // Init with DTLS with a store that will fail to generate a certificate.
475 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200476 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
477 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200478 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200479 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800480 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000481 }
482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 void InitWithDtmfCodec() {
484 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000485 const cricket::AudioCodec kTelephoneEventCodec(
486 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 std::vector<cricket::AudioCodec> codecs;
488 codecs.push_back(kTelephoneEventCodec);
489 media_engine_->SetAudioCodecs(codecs);
490 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000491 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 }
493
deadbeefab9b2d12015-10-14 11:33:11 -0700494 void SendAudioVideoStream1() {
495 send_stream_1_ = true;
496 send_stream_2_ = false;
497 send_audio_ = true;
498 send_video_ = true;
499 }
500
501 void SendAudioVideoStream2() {
502 send_stream_1_ = false;
503 send_stream_2_ = true;
504 send_audio_ = true;
505 send_video_ = true;
506 }
507
508 void SendAudioVideoStream1And2() {
509 send_stream_1_ = true;
510 send_stream_2_ = true;
511 send_audio_ = true;
512 send_video_ = true;
513 }
514
515 void SendNothing() {
516 send_stream_1_ = false;
517 send_stream_2_ = false;
518 send_audio_ = false;
519 send_video_ = false;
520 }
521
522 void SendAudioOnlyStream2() {
523 send_stream_1_ = false;
524 send_stream_2_ = true;
525 send_audio_ = true;
526 send_video_ = false;
527 }
528
529 void SendVideoOnlyStream2() {
530 send_stream_1_ = false;
531 send_stream_2_ = true;
532 send_audio_ = false;
533 send_video_ = true;
534 }
535
536 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
537 if (send_stream_1_ && send_audio_) {
538 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
539 kStream1);
540 }
541 if (send_stream_1_ && send_video_) {
542 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
543 kStream1);
544 }
545 if (send_stream_2_ && send_audio_) {
546 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
547 kStream2);
548 }
549 if (send_stream_2_ && send_video_) {
550 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
551 kStream2);
552 }
553 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
554 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
555 data_channel_->label(),
556 data_channel_->label());
557 }
558 }
559
560 void GetOptionsForOffer(
561 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
562 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700563 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
564
deadbeefc80741f2015-10-22 13:14:45 -0700565 AddStreamsToOptions(session_options);
566 if (rtc_options.offer_to_receive_audio ==
567 RTCOfferAnswerOptions::kUndefined) {
568 session_options->recv_audio =
569 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
570 }
571 if (rtc_options.offer_to_receive_video ==
572 RTCOfferAnswerOptions::kUndefined) {
573 session_options->recv_video =
574 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
575 }
576 session_options->bundle_enabled =
577 session_options->bundle_enabled &&
578 (session_options->has_audio() || session_options->has_video() ||
579 session_options->has_data());
580
deadbeefab9b2d12015-10-14 11:33:11 -0700581 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
582 session_options->data_channel_type = cricket::DCT_SCTP;
583 }
584 }
585
586 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
587 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700588 session_options->recv_audio = false;
589 session_options->recv_video = false;
590 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
591
deadbeefc80741f2015-10-22 13:14:45 -0700592 AddStreamsToOptions(session_options);
593 session_options->bundle_enabled =
594 session_options->bundle_enabled &&
595 (session_options->has_audio() || session_options->has_video() ||
596 session_options->has_data());
597
deadbeefab9b2d12015-10-14 11:33:11 -0700598 if (session_->data_channel_type() == cricket::DCT_SCTP) {
599 session_options->data_channel_type = cricket::DCT_SCTP;
600 }
601 }
602
603 // Creates a local offer and applies it. Starts ICE.
604 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 // to decide which streams to create.
606 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000607 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 SetLocalDescriptionWithoutError(offer);
609 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
610 observer_.ice_gathering_state_,
611 kIceCandidatesTimeout);
612 }
613
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000614 SessionDescriptionInterface* CreateOffer() {
615 PeerConnectionInterface::RTCOfferAnswerOptions options;
616 options.offer_to_receive_audio =
617 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
618
619 return CreateOffer(options);
620 }
621
wu@webrtc.org91053e72013-08-10 07:18:04 +0000622 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000623 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000624 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000625 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700626 cricket::MediaSessionOptions session_options;
627 GetOptionsForOffer(options, &session_options);
628 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000629 EXPECT_TRUE_WAIT(
630 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000631 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000632 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 }
634
635 SessionDescriptionInterface* CreateAnswer(
636 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000637 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000638 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700639 cricket::MediaSessionOptions session_options;
640 GetOptionsForAnswer(constraints, &session_options);
641 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000642 EXPECT_TRUE_WAIT(
643 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000644 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000645 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000646 }
647
wu@webrtc.org364f2042013-11-20 21:49:41 +0000648 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 return (session_->voice_channel() != NULL &&
650 session_->video_channel() != NULL);
651 }
652
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
654 ASSERT_TRUE(session_.get() != NULL);
655 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
656 ASSERT_TRUE(content != NULL);
657 const cricket::AudioContentDescription* audio_content =
658 static_cast<const cricket::AudioContentDescription*>(
659 content->description);
660 ASSERT_TRUE(audio_content != NULL);
661 ASSERT_EQ(1U, audio_content->cryptos().size());
662 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
663 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
664 audio_content->cryptos()[0].cipher_suite);
665 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
666 audio_content->protocol());
667
668 content = cricket::GetFirstVideoContent(sdp);
669 ASSERT_TRUE(content != NULL);
670 const cricket::VideoContentDescription* video_content =
671 static_cast<const cricket::VideoContentDescription*>(
672 content->description);
673 ASSERT_TRUE(video_content != NULL);
674 ASSERT_EQ(1U, video_content->cryptos().size());
675 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
676 video_content->cryptos()[0].cipher_suite);
677 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
678 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
679 video_content->protocol());
680 }
681
682 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
683 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
684 ASSERT_TRUE(content != NULL);
685 const cricket::AudioContentDescription* audio_content =
686 static_cast<const cricket::AudioContentDescription*>(
687 content->description);
688 ASSERT_TRUE(audio_content != NULL);
689 ASSERT_EQ(0U, audio_content->cryptos().size());
690
691 content = cricket::GetFirstVideoContent(sdp);
692 ASSERT_TRUE(content != NULL);
693 const cricket::VideoContentDescription* video_content =
694 static_cast<const cricket::VideoContentDescription*>(
695 content->description);
696 ASSERT_TRUE(video_content != NULL);
697 ASSERT_EQ(0U, video_content->cryptos().size());
698
699 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700700 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700702 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 video_content->protocol());
704 } else {
705 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
706 audio_content->protocol());
707 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
708 video_content->protocol());
709 }
710 }
711
712 // Set the internal fake description factories to do DTLS-SRTP.
713 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000714 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000716 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200717 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800718 tdesc_factory_->set_certificate(
719 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
720 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
722 }
723
724 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
725 bool expected) {
726 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
727 ASSERT_TRUE(audio != NULL);
728 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 const TransportInfo* video = sdp->GetTransportInfoByName("video");
730 ASSERT_TRUE(video != NULL);
731 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 }
733
734 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000735 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000737 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000738 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000740 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000742 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
743 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000744 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 // Answer should be NULL as no crypto params in offer.
746 ASSERT_TRUE(answer == NULL);
747 }
748
749 void VerifyAnswerFromCryptoOffer() {
750 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000751 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 options.bundle_enabled = true;
753 scoped_ptr<JsepSessionDescription> offer(
754 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
755 ASSERT_TRUE(offer.get() != NULL);
756 VerifyCryptoParams(offer->description());
757 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000758 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 ASSERT_TRUE(answer.get() != NULL);
760 VerifyCryptoParams(answer->description());
761 }
762
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000763 void SetAndVerifyNumUnsignalledRecvStreams(
764 int value_set, int value_expected) {
765 constraints_.reset(new FakeConstraints());
766 constraints_->AddOptional(
767 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
768 value_set);
769 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000770 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700771 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000772 SessionDescriptionInterface* offer = CreateOffer();
773
774 SetLocalDescriptionWithoutError(offer);
775
776 video_channel_ = media_engine_->GetVideoChannel(0);
777
778 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700779 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000780 EXPECT_EQ(value_expected,
kwiberg102c6a62015-10-30 02:47:38 -0700781 video_options.unsignalled_recv_stream_limit.value_or(-1));
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000782 }
783
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
785 const cricket::SessionDescription* desc2,
786 bool expect_equal) {
787 if (desc1->contents().size() != desc2->contents().size()) {
788 EXPECT_FALSE(expect_equal);
789 return;
790 }
791
792 const cricket::ContentInfos& contents = desc1->contents();
793 cricket::ContentInfos::const_iterator it = contents.begin();
794
795 for (; it != contents.end(); ++it) {
796 const cricket::TransportDescription* transport_desc1 =
797 desc1->GetTransportDescriptionByName(it->name);
798 const cricket::TransportDescription* transport_desc2 =
799 desc2->GetTransportDescriptionByName(it->name);
800 if (!transport_desc1 || !transport_desc2) {
801 EXPECT_FALSE(expect_equal);
802 return;
803 }
804 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
805 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
806 EXPECT_FALSE(expect_equal);
807 return;
808 }
809 }
810 EXPECT_TRUE(expect_equal);
811 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000812
813 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
814 std::string *sdp) {
815 const cricket::SessionDescription* desc = current_desc->description();
816 EXPECT_TRUE(current_desc->ToString(sdp));
817
818 const cricket::ContentInfos& contents = desc->contents();
819 cricket::ContentInfos::const_iterator it = contents.begin();
820 // Replace ufrag and pwd lines with empty strings.
821 for (; it != contents.end(); ++it) {
822 const cricket::TransportDescription* transport_desc =
823 desc->GetTransportDescriptionByName(it->name);
824 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
825 + "\r\n";
826 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
827 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000828 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000829 "", 0,
830 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000831 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000832 "", 0,
833 sdp);
834 }
835 }
836
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000837 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
838 const std::string& modified_ice_ufrag,
839 const std::string& modified_ice_pwd,
840 std::string* sdp) {
841 const cricket::SessionDescription* desc = current_desc->description();
842 EXPECT_TRUE(current_desc->ToString(sdp));
843
844 const cricket::ContentInfos& contents = desc->contents();
845 cricket::ContentInfos::const_iterator it = contents.begin();
846 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
847 // |modified_ice_pwd| strings.
848 for (; it != contents.end(); ++it) {
849 const cricket::TransportDescription* transport_desc =
850 desc->GetTransportDescriptionByName(it->name);
851 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
852 + "\r\n";
853 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
854 + "\r\n";
855 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
856 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000857 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000858 mod_ufrag.c_str(), mod_ufrag.length(),
859 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000860 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000861 mod_pwd.c_str(), mod_pwd.length(),
862 sdp);
863 }
864 }
865
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 // Creates a remote offer and and applies it as a remote description,
867 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700868 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 // to decide which local and remote streams to create.
870 void CreateAndSetRemoteOfferAndLocalAnswer() {
871 SessionDescriptionInterface* offer = CreateRemoteOffer();
872 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000873 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 SetLocalDescriptionWithoutError(answer);
875 }
876 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
877 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700878 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 }
880 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700881 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 SetLocalDescriptionWithoutError(desc);
883 EXPECT_EQ(expected_state, session_->state());
884 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 void SetLocalDescriptionExpectError(const std::string& action,
886 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 SessionDescriptionInterface* desc) {
888 std::string error;
889 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 std::string sdp_type = "local ";
891 sdp_type.append(action);
892 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 EXPECT_NE(std::string::npos, error.find(expected_error));
894 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000895 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
896 SessionDescriptionInterface* desc) {
897 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
898 expected_error, desc);
899 }
900 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
901 SessionDescriptionInterface* desc) {
902 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
903 expected_error, desc);
904 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
906 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
907 }
908 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700909 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 SetRemoteDescriptionWithoutError(desc);
911 EXPECT_EQ(expected_state, session_->state());
912 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000913 void SetRemoteDescriptionExpectError(const std::string& action,
914 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 SessionDescriptionInterface* desc) {
916 std::string error;
917 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000918 std::string sdp_type = "remote ";
919 sdp_type.append(action);
920 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 EXPECT_NE(std::string::npos, error.find(expected_error));
922 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000923 void SetRemoteDescriptionOfferExpectError(
924 const std::string& expected_error, SessionDescriptionInterface* desc) {
925 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
926 expected_error, desc);
927 }
928 void SetRemoteDescriptionPranswerExpectError(
929 const std::string& expected_error, SessionDescriptionInterface* desc) {
930 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
931 expected_error, desc);
932 }
933 void SetRemoteDescriptionAnswerExpectError(
934 const std::string& expected_error, SessionDescriptionInterface* desc) {
935 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
936 expected_error, desc);
937 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
940 SessionDescriptionInterface** nocrypto_answer) {
941 // Create a SDP without Crypto.
942 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000943 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 options.bundle_enabled = true;
945 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
946 ASSERT_TRUE(*offer != NULL);
947 VerifyCryptoParams((*offer)->description());
948
949 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
950 cricket::SEC_DISABLED);
951 EXPECT_TRUE(*nocrypto_answer != NULL);
952 }
953
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000954 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
955 SessionDescriptionInterface** nodtls_answer) {
956 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000957 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000958 options.bundle_enabled = true;
959
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000960 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000961 CreateRemoteOffer(options, cricket::SEC_ENABLED));
962
963 *nodtls_answer =
964 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
965 EXPECT_TRUE(*nodtls_answer != NULL);
966 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
967 VerifyCryptoParams((*nodtls_answer)->description());
968
969 SetFactoryDtlsSrtp();
970 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
971 ASSERT_TRUE(*offer != NULL);
972 VerifyFingerprintStatus((*offer)->description(), true);
973 VerifyCryptoParams((*offer)->description());
974 }
975
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 JsepSessionDescription* CreateRemoteOfferWithVersion(
977 cricket::MediaSessionOptions options,
978 cricket::SecurePolicy secure_policy,
979 const std::string& session_version,
980 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000981 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 const cricket::SessionDescription* cricket_desc = NULL;
983 if (current_desc) {
984 cricket_desc = current_desc->description();
985 session_id = current_desc->session_id();
986 }
987
988 desc_factory_->set_secure(secure_policy);
989 JsepSessionDescription* offer(
990 new JsepSessionDescription(JsepSessionDescription::kOffer));
991 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
992 session_id, session_version)) {
993 delete offer;
994 offer = NULL;
995 }
996 return offer;
997 }
998 JsepSessionDescription* CreateRemoteOffer(
999 cricket::MediaSessionOptions options) {
1000 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1001 kSessionVersion, NULL);
1002 }
1003 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001004 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1005 return CreateRemoteOfferWithVersion(
1006 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 }
1008 JsepSessionDescription* CreateRemoteOffer(
1009 cricket::MediaSessionOptions options,
1010 const SessionDescriptionInterface* current_desc) {
1011 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1012 kSessionVersion, current_desc);
1013 }
1014
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001015 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1016 const char* sctp_stream_name, int new_port,
1017 cricket::MediaSessionOptions options) {
1018 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001019 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1020 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001021 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1022 }
1023
1024 // Takes ownership of offer_basis (and deletes it).
1025 JsepSessionDescription* ChangeSDPSctpPort(
1026 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1027 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1028 // SessionDescription from the mutated string.
1029 const char* default_port_str = "5000";
1030 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001032 std::string offer_str;
1033 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001034 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001035 new_port_str, strlen(new_port_str),
1036 &offer_str);
1037 JsepSessionDescription* offer = new JsepSessionDescription(
1038 offer_basis->type());
1039 delete offer_basis;
1040 offer->Initialize(offer_str, NULL);
1041 return offer;
1042 }
1043
deadbeefab9b2d12015-10-14 11:33:11 -07001044 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 // before this function to decide which streams to create.
1046 JsepSessionDescription* CreateRemoteOffer() {
1047 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001048 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 return CreateRemoteOffer(options, session_->remote_description());
1050 }
1051
1052 JsepSessionDescription* CreateRemoteAnswer(
1053 const SessionDescriptionInterface* offer,
1054 cricket::MediaSessionOptions options,
1055 cricket::SecurePolicy policy) {
1056 desc_factory_->set_secure(policy);
1057 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001058 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 JsepSessionDescription* answer(
1060 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1061 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1062 options, NULL),
1063 session_id, kSessionVersion)) {
1064 delete answer;
1065 answer = NULL;
1066 }
1067 return answer;
1068 }
1069
1070 JsepSessionDescription* CreateRemoteAnswer(
1071 const SessionDescriptionInterface* offer,
1072 cricket::MediaSessionOptions options) {
1073 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1074 }
1075
deadbeefab9b2d12015-10-14 11:33:11 -07001076 // Creates an answer session description.
1077 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 // to decide which streams to create.
1079 JsepSessionDescription* CreateRemoteAnswer(
1080 const SessionDescriptionInterface* offer) {
1081 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001082 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1084 }
1085
1086 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001089 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001090
1091 PeerConnectionInterface::RTCOfferAnswerOptions options;
1092 options.use_rtp_mux = bundle;
1093
1094 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1096 // and answer.
1097 SetLocalDescriptionWithoutError(offer);
1098
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001099 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001100 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 std::string sdp;
1102 EXPECT_TRUE(answer->ToString(&sdp));
1103
1104 size_t expected_candidate_num = 2;
1105 if (!rtcp_mux) {
1106 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1107 // for rtp and rtcp.
1108 expected_candidate_num = 4;
1109 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 const std::string kRtcpMux = "a=rtcp-mux";
1111 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001112 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 kXRtcpMux.c_str(), kXRtcpMux.length(),
1114 &sdp);
1115 }
1116
1117 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1118 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119
1120 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001121 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1123 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001124 if (bundle) {
1125 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1126 } else {
1127 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 }
1129 }
1130 // Tests that we can only send DTMF when the dtmf codec is supported.
1131 void TestCanInsertDtmf(bool can) {
1132 if (can) {
1133 InitWithDtmfCodec();
1134 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001135 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 }
deadbeefab9b2d12015-10-14 11:33:11 -07001137 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 CreateAndSetRemoteOfferAndLocalAnswer();
1139 EXPECT_FALSE(session_->CanInsertDtmf(""));
1140 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1141 }
1142
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001143 // Helper class to configure loopback network and verify Best
1144 // Connection using right IP protocol for TestLoopbackCall
1145 // method. LoopbackNetworkManager applies firewall rules to block
1146 // all ping traffic once ICE completed, and remove them to observe
1147 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1148 // verifies the best connection is using the right IP protocol after
1149 // initial ICE convergences.
1150
1151 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001152 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 LoopbackNetworkConfiguration()
1154 : test_ipv6_network_(false),
1155 test_extra_ipv4_network_(false),
1156 best_connection_after_initial_ice_converged_(1, 0) {}
1157
1158 // Used to track the expected best connection count in each IP protocol.
1159 struct ExpectedBestConnection {
1160 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1161 : ipv4_count_(ipv4_count),
1162 ipv6_count_(ipv6_count) {}
1163
1164 int ipv4_count_;
1165 int ipv6_count_;
1166 };
1167
1168 bool test_ipv6_network_;
1169 bool test_extra_ipv4_network_;
1170 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1171
1172 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001173 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001174 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1175 }
1176
1177 private:
jbauchac8869e2015-07-03 01:36:14 -07001178 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001179 const ExpectedBestConnection& expected) const {
1180 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001181 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1182 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 expected.ipv4_count_);
1184 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001185 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1186 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001187 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001188 // This is used in the loopback call so there is only single host to host
1189 // candidate pair.
1190 EXPECT_EQ(metrics_observer->GetEnumCounter(
1191 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1192 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001193 0);
1194 EXPECT_EQ(metrics_observer->GetEnumCounter(
1195 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1196 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001197 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001198 }
1199 };
1200
1201 class LoopbackNetworkManager {
1202 public:
1203 LoopbackNetworkManager(WebRtcSessionTest* session,
1204 const LoopbackNetworkConfiguration& config)
1205 : config_(config) {
1206 session->AddInterface(
1207 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1208 if (config_.test_extra_ipv4_network_) {
1209 session->AddInterface(
1210 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1211 }
1212 if (config_.test_ipv6_network_) {
1213 session->AddInterface(
1214 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1215 }
1216 }
1217
1218 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1219 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1220 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1221 if (config_.test_extra_ipv4_network_) {
1222 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1223 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1224 }
1225 if (config_.test_ipv6_network_) {
1226 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1227 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1228 }
1229 }
1230
1231 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1232
1233 private:
1234 LoopbackNetworkConfiguration config_;
1235 };
1236
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 // The method sets up a call from the session to itself, in a loopback
1238 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001239 // disconnection, and then a permanent disconnection.
1240 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1242 // While running the call, this method also checks if the session goes through
1243 // the correct sequence of ICE states when a connection is established,
1244 // broken, and re-established.
1245 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001246 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1247 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001249
stefanc1aeaf02015-10-15 07:26:07 -07001250 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001251 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001252 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001253 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
1255 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1256 observer_.ice_gathering_state_);
1257 SetLocalDescriptionWithoutError(offer);
1258 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1259 observer_.ice_connection_state_);
1260 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001261 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1263 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001264 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265
1266 std::string sdp;
1267 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001268 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1269 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 ASSERT_TRUE(desc != NULL);
1271 SetRemoteDescriptionWithoutError(desc);
1272
1273 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001274 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001275
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001276 // The ice connection state is "Connected" too briefly to catch in a test.
1277 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001278 observer_.ice_connection_state_, kIceCandidatesTimeout);
1279 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280
stefanc1aeaf02015-10-15 07:26:07 -07001281 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1282 LoopbackNetworkManager loopback_network_manager(this, config);
1283 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001284 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 // Adding firewall rule to block ping requests, which should cause
1286 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287
1288 loopback_network_manager.ApplyFirewallRules(fss_.get());
1289
1290 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1292 observer_.ice_connection_state_,
1293 kIceCandidatesTimeout);
1294
jbauchac8869e2015-07-03 01:36:14 -07001295 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001296
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001298 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001301 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 observer_.ice_connection_state_,
1303 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304
1305 // Now we block ping requests and wait until the ICE connection transitions
1306 // to the Failed state. This will take at least 30 seconds because it must
1307 // wait for the Port to timeout.
1308 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001309
1310 loopback_network_manager.ApplyFirewallRules(fss_.get());
1311 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001312 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001313 observer_.ice_connection_state_,
1314 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 }
1316
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001317 void TestLoopbackCall() {
1318 LoopbackNetworkConfiguration config;
1319 TestLoopbackCall(config);
1320 }
1321
stefanc1aeaf02015-10-15 07:26:07 -07001322 void TestPacketOptions() {
1323 media_controller_.reset(
1324 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1325 LoopbackNetworkConfiguration config;
1326 LoopbackNetworkManager loopback_network_manager(this, config);
1327
1328 SetupLoopbackCall();
1329
1330 uint8_t test_packet[15] = {0};
1331 rtc::PacketOptions options;
1332 options.packet_id = 10;
1333 media_engine_->GetVideoChannel(0)
1334 ->SendRtp(test_packet, sizeof(test_packet), options);
1335
1336 const int kPacketTimeout = 2000;
1337 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1338 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1339 }
1340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1342 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001343 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1344 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1345
1346 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1348 codecs.push_back(kCNCodec1);
1349 codecs.push_back(kCNCodec2);
1350 media_engine_->SetAudioCodecs(codecs);
1351 desc_factory_->set_audio_codecs(codecs);
1352 }
1353
1354 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1355 const cricket::ContentDescription* description = content->description;
1356 ASSERT(description != NULL);
1357 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001358 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 ASSERT(audio_content_desc != NULL);
1360 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1361 if (audio_content_desc->codecs()[i].name == "CN")
1362 return false;
1363 }
1364 return true;
1365 }
1366
deadbeefab9b2d12015-10-14 11:33:11 -07001367 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001368 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001369 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1370 data_channel_ = DataChannel::Create(
1371 session_.get(), session_->data_channel_type(), "datachannel", dci);
1372 }
1373
1374 void SetLocalDescriptionWithDataChannel() {
1375 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001376 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 SetLocalDescriptionWithoutError(offer);
1378 }
1379
wu@webrtc.org91053e72013-08-10 07:18:04 +00001380 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001381 RTCCertificateGenerationMethod cert_gen_method,
1382 CreateSessionDescriptionRequest::Type type) {
1383 InitWithDtls(cert_gen_method);
1384 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1385 }
1386
1387 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1388 CreateSessionDescriptionRequest::Type type) {
1389 InitWithDtlsIdentityGenFail();
1390 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1391 }
1392
1393 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001394 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001395 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001396 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 if (type == CreateSessionDescriptionRequest::kAnswer) {
1398 cricket::MediaSessionOptions options;
1399 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001400 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001401 ASSERT_TRUE(offer.get() != NULL);
1402 SetRemoteDescriptionWithoutError(offer.release());
1403 }
1404
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001405 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001406 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001407 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001408 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001409 observers[kNumber];
1410 for (int i = 0; i < kNumber; ++i) {
1411 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1412 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001413 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001414 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001415 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001416 }
1417 }
1418
1419 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1420 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1421 WebRtcSessionCreateSDPObserverForTest::kFailed;
1422
1423 for (int i = 0; i < kNumber; ++i) {
1424 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1425 if (success) {
1426 EXPECT_TRUE(observers[i]->description() != NULL);
1427 } else {
1428 EXPECT_TRUE(observers[i]->description() == NULL);
1429 }
1430 }
1431 }
1432
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001433 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001434 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001435 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001436 turn_server.credentials = credentials;
1437 turn_server.ports.push_back(
1438 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1439 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001440 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001441 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001442 }
1443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 cricket::FakeMediaEngine* media_engine_;
1445 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001446 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001447 cricket::FakeCall fake_call_;
1448 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001449 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1451 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1452 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1453 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1454 rtc::SocketServerScope ss_scope_;
1455 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001456 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001457 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001458 rtc::FakeNetworkManager network_manager_;
1459 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001460 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001461 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001462 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 MockIceObserver observer_;
1464 cricket::FakeVideoMediaChannel* video_channel_;
1465 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001466 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001467 // The following flags affect options created for CreateOffer/CreateAnswer.
1468 bool send_stream_1_ = false;
1469 bool send_stream_2_ = false;
1470 bool send_audio_ = false;
1471 bool send_video_ = false;
1472 rtc::scoped_refptr<DataChannel> data_channel_;
1473 // Last values received from data channel creation signal.
1474 std::string last_data_channel_label_;
1475 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476};
1477
Henrik Boström87713d02015-08-25 09:53:21 +02001478TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1479 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001480 // SDES is disabled when DTLS is on.
1481 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482}
1483
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001484TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001485 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001486 // SDES is required if DTLS is off.
1487 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001488}
1489
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1491 TestSessionCandidatesWithBundleRtcpMux(false, false);
1492}
1493
1494// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1495// with rtcp-mux and/or bundle.
1496TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1497 TestSessionCandidatesWithBundleRtcpMux(false, true);
1498}
1499
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1501 TestSessionCandidatesWithBundleRtcpMux(true, true);
1502}
1503
1504TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001505 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1506 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001507 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001508 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 InitiateCall();
1510 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1511 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1512 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1513}
1514
1515TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001516 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1517 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001518 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001519 rtc::FP_UDP,
1520 rtc::FD_ANY,
1521 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001522 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001523 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001525 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1527 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1528 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1529}
1530
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001531// Test session delivers no candidates gathered when constraint set to "none".
1532TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1533 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001534 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001535 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001536 InitiateCall();
1537 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1538 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1539 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1540}
1541
1542// Test session delivers only relay candidates gathered when constaint set to
1543// "relay".
1544TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1545 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1546 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001547 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001548 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001549 InitiateCall();
1550 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1551 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1552 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1553 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1554 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1555 observer_.mline_0_candidates_[i].type());
1556 }
1557 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1558 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1559 observer_.mline_1_candidates_[i].type());
1560 }
1561}
1562
1563// Test session delivers all candidates gathered when constaint set to "all".
1564TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1565 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001566 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001567 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001568 InitiateCall();
1569 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1570 // Host + STUN. By default allocator is disabled to gather relay candidates.
1571 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1572 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1573}
1574
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001575TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001576 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001577 SessionDescriptionInterface* offer = NULL;
1578 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1579 std::string unknown_action;
1580 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1581 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1582}
1583
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584// Test creating offers and receive answers and make sure the
1585// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001586TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001587 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001588 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001589 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 const std::string session_id_orig = offer->session_id();
1591 const std::string session_version_orig = offer->session_version();
1592 SetLocalDescriptionWithoutError(offer);
1593
deadbeefab9b2d12015-10-14 11:33:11 -07001594 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 SessionDescriptionInterface* answer =
1596 CreateRemoteAnswer(session_->local_description());
1597 SetRemoteDescriptionWithoutError(answer);
1598
1599 video_channel_ = media_engine_->GetVideoChannel(0);
1600 voice_channel_ = media_engine_->GetVoiceChannel(0);
1601
1602 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1603 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1604
1605 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1606 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1607
1608 ASSERT_EQ(1u, video_channel_->send_streams().size());
1609 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1610 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1611 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1612
1613 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001614 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001615 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616
1617 // Verify the session id is the same and the session version is
1618 // increased.
1619 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001620 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1621 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622
1623 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001624 EXPECT_EQ(0u, video_channel_->send_streams().size());
1625 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626
deadbeefab9b2d12015-10-14 11:33:11 -07001627 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 answer = CreateRemoteAnswer(session_->local_description());
1629 SetRemoteDescriptionWithoutError(answer);
1630
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 // Make sure the receive streams have not changed.
1632 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1633 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1634 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1635 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1636}
1637
1638// Test receiving offers and creating answers and make sure the
1639// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001640TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001641 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001642 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001643 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001644 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 SetRemoteDescriptionWithoutError(offer);
1646
deadbeefab9b2d12015-10-14 11:33:11 -07001647 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001648 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001649 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 SetLocalDescriptionWithoutError(answer);
1651
1652 const std::string session_id_orig = answer->session_id();
1653 const std::string session_version_orig = answer->session_version();
1654
1655 video_channel_ = media_engine_->GetVideoChannel(0);
1656 voice_channel_ = media_engine_->GetVoiceChannel(0);
1657
1658 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1659 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1660
1661 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1662 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1663
1664 ASSERT_EQ(1u, video_channel_->send_streams().size());
1665 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1666 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1667 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1668
deadbeefab9b2d12015-10-14 11:33:11 -07001669 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001670 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 SetRemoteDescriptionWithoutError(offer);
1672
1673 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001674 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001675 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
1677 // Verify the session id is the same and the session version is
1678 // increased.
1679 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001680 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1681 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 SetLocalDescriptionWithoutError(answer);
1683
1684 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1685 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1686 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1687 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1688 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1689 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1690
1691 // Make sure we have no send streams.
1692 EXPECT_EQ(0u, video_channel_->send_streams().size());
1693 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1694}
1695
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001696TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001697 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001698 media_engine_->set_fail_create_channel(true);
1699
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001700 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001701 ASSERT_TRUE(offer != NULL);
1702 // SetRemoteDescription and SetLocalDescription will take the ownership of
1703 // the offer.
1704 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001705 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001706 ASSERT_TRUE(offer != NULL);
1707 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1708}
1709
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001710//
1711// Tests for creating/setting SDP under different SDES/DTLS polices:
1712//
1713// --DTLS off and SDES on
1714// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1715// set local/remote offer/answer with crypto --> success
1716// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1717// failure
1718// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1719// failure
1720// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1721// failure
1722//
1723// --DTLS on and SDES off
1724// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1725// set local/remote offer/answer with DTLS fingerprint --> success
1726// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1727// fingerprint --> failure
1728// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1729// --> failure
1730// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1731// --> failure
1732//
1733// --Encryption disabled: DTLS off and SDES off
1734// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1735// answer without SDES or DTLS --> success
1736// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1737// answer without SDES or DTLS --> success
1738//
1739
1740// Test that we return a failure when applying a remote/local offer that doesn't
1741// have cryptos enabled when DTLS is off.
1742TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001743 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001745 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 JsepSessionDescription* offer = CreateRemoteOffer(
1747 options, cricket::SEC_DISABLED);
1748 ASSERT_TRUE(offer != NULL);
1749 VerifyNoCryptoParams(offer->description(), false);
1750 // SetRemoteDescription and SetLocalDescription will take the ownership of
1751 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001752 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1754 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001755 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756}
1757
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758// Test that we return a failure when applying a local answer that doesn't have
1759// cryptos enabled when DTLS is off.
1760TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001761 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 SessionDescriptionInterface* offer = NULL;
1763 SessionDescriptionInterface* answer = NULL;
1764 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1765 // SetRemoteDescription and SetLocalDescription will take the ownership of
1766 // the offer.
1767 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769}
1770
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001771// Test we will return fail when apply an remote answer that doesn't have
1772// crypto enabled when DTLS is off.
1773TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 SessionDescriptionInterface* offer = NULL;
1776 SessionDescriptionInterface* answer = NULL;
1777 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1778 // SetRemoteDescription and SetLocalDescription will take the ownership of
1779 // the offer.
1780 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001781 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782}
1783
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1785// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001786TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001787 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001788 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001789 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 SetFactoryDtlsSrtp();
1791 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001792 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001793 JsepSessionDescription* offer =
1794 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 ASSERT_TRUE(offer != NULL);
1796 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001797 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798
1799 // SetRemoteDescription will take the ownership of the offer.
1800 SetRemoteDescriptionWithoutError(offer);
1801
1802 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001803 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 ASSERT_TRUE(answer != NULL);
1805 VerifyFingerprintStatus(answer->description(), true);
1806 // Check that we don't have an a=crypto line in the answer.
1807 VerifyNoCryptoParams(answer->description(), true);
1808
1809 // Now set the local description, which should work, even without a=crypto.
1810 SetLocalDescriptionWithoutError(answer);
1811}
1812
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001813// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1814// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001815TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001816 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001817 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001818 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001819 SetFactoryDtlsSrtp();
1820
1821 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001822 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 ASSERT_TRUE(offer != NULL);
1824 VerifyFingerprintStatus(offer->description(), true);
1825 // Check that we don't have an a=crypto line in the offer.
1826 VerifyNoCryptoParams(offer->description(), true);
1827
1828 // Now set the local description, which should work, even without a=crypto.
1829 SetLocalDescriptionWithoutError(offer);
1830
1831 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001832 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 JsepSessionDescription* answer =
1834 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1835 ASSERT_TRUE(answer != NULL);
1836 VerifyFingerprintStatus(answer->description(), true);
1837 VerifyNoCryptoParams(answer->description(), true);
1838
1839 // SetRemoteDescription will take the ownership of the answer.
1840 SetRemoteDescriptionWithoutError(answer);
1841}
1842
1843// Test that if we support DTLS and the other side didn't offer a fingerprint,
1844// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001845TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001846 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001847 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001849 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 JsepSessionDescription* offer = CreateRemoteOffer(
1852 options, cricket::SEC_REQUIRED);
1853 ASSERT_TRUE(offer != NULL);
1854 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001857 // SetRemoteDescription will take the ownership of the offer.
1858 SetRemoteDescriptionOfferExpectError(
1859 kSdpWithoutDtlsFingerprint, offer);
1860
1861 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1862 // SetLocalDescription will take the ownership of the offer.
1863 SetLocalDescriptionOfferExpectError(
1864 kSdpWithoutDtlsFingerprint, offer);
1865}
1866
1867// Test that we return a failure when applying a local answer that doesn't have
1868// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001869TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001870 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001871 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001872 SessionDescriptionInterface* offer = NULL;
1873 SessionDescriptionInterface* answer = NULL;
1874 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1875
1876 // SetRemoteDescription and SetLocalDescription will take the ownership of
1877 // the offer and answer.
1878 SetRemoteDescriptionWithoutError(offer);
1879 SetLocalDescriptionAnswerExpectError(
1880 kSdpWithoutDtlsFingerprint, answer);
1881}
1882
1883// Test that we return a failure when applying a remote answer that doesn't have
1884// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001885TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001886 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001887 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001888 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001889 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001890 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001891 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1892 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001893 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001894 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895
1896 // SetRemoteDescription and SetLocalDescription will take the ownership of
1897 // the offer and answer.
1898 SetLocalDescriptionWithoutError(offer);
1899 SetRemoteDescriptionAnswerExpectError(
1900 kSdpWithoutDtlsFingerprint, answer);
1901}
1902
1903// Test that we create a local offer without SDES or DTLS and accept a remote
1904// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001905TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001906 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001907 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001908 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909
1910 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001911 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 ASSERT_TRUE(offer != NULL);
1913 VerifyFingerprintStatus(offer->description(), false);
1914 // Check that we don't have an a=crypto line in the offer.
1915 VerifyNoCryptoParams(offer->description(), false);
1916
1917 // Now set the local description, which should work, even without a=crypto.
1918 SetLocalDescriptionWithoutError(offer);
1919
1920 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001921 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 JsepSessionDescription* answer =
1923 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1924 ASSERT_TRUE(answer != NULL);
1925 VerifyFingerprintStatus(answer->description(), false);
1926 VerifyNoCryptoParams(answer->description(), false);
1927
1928 // SetRemoteDescription will take the ownership of the answer.
1929 SetRemoteDescriptionWithoutError(answer);
1930}
1931
1932// Test that we create a local answer without SDES or DTLS and accept a remote
1933// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001934TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001935 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001936 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001937
1938 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001939 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940 JsepSessionDescription* offer =
1941 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1942 ASSERT_TRUE(offer != NULL);
1943 VerifyFingerprintStatus(offer->description(), false);
1944 VerifyNoCryptoParams(offer->description(), false);
1945
1946 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 SetRemoteDescriptionWithoutError(offer);
1948
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001949 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001950 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 ASSERT_TRUE(answer != NULL);
1952 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001953 // Check that we don't have an a=crypto line in the answer.
1954 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001956 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 SetLocalDescriptionWithoutError(answer);
1958}
1959
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001960// Test that we can create and set an answer correctly when different
1961// SSL roles have been negotiated for different transports.
1962// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1963TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1964 SendAudioVideoStream1();
1965 InitWithDtls(GetParam());
1966 SetFactoryDtlsSrtp();
1967
1968 SessionDescriptionInterface* offer = CreateOffer();
1969 SetLocalDescriptionWithoutError(offer);
1970
1971 cricket::MediaSessionOptions options;
1972 options.recv_video = true;
1973
1974 // First, negotiate different SSL roles.
1975 SessionDescriptionInterface* answer =
1976 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1977 TransportInfo* audio_transport_info =
1978 answer->description()->GetTransportInfoByName("audio");
1979 audio_transport_info->description.connection_role =
1980 cricket::CONNECTIONROLE_ACTIVE;
1981 TransportInfo* video_transport_info =
1982 answer->description()->GetTransportInfoByName("video");
1983 video_transport_info->description.connection_role =
1984 cricket::CONNECTIONROLE_PASSIVE;
1985 SetRemoteDescriptionWithoutError(answer);
1986
1987 // Now create an offer in the reverse direction, and ensure the initial
1988 // offerer responds with an answer with correct SSL roles.
1989 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1990 kSessionVersion,
1991 session_->remote_description());
1992 SetRemoteDescriptionWithoutError(offer);
1993
1994 answer = CreateAnswer(nullptr);
1995 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1996 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1997 audio_transport_info->description.connection_role);
1998 video_transport_info = answer->description()->GetTransportInfoByName("video");
1999 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2000 video_transport_info->description.connection_role);
2001 SetLocalDescriptionWithoutError(answer);
2002
2003 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2004 // audio is transferred over to video in the answer that completes the BUNDLE
2005 // negotiation.
2006 options.bundle_enabled = true;
2007 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2008 kSessionVersion,
2009 session_->remote_description());
2010 SetRemoteDescriptionWithoutError(offer);
2011 answer = CreateAnswer(nullptr);
2012 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2013 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2014 audio_transport_info->description.connection_role);
2015 video_transport_info = answer->description()->GetTransportInfoByName("video");
2016 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2017 video_transport_info->description.connection_role);
2018 SetLocalDescriptionWithoutError(answer);
2019}
2020
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002022 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002023 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002025 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 SetLocalDescriptionWithoutError(offer);
2027
2028 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002029 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 SetLocalDescriptionWithoutError(offer2);
2031}
2032
2033TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002034 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002035 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002037 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 SetRemoteDescriptionWithoutError(offer);
2039
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetRemoteDescriptionWithoutError(offer2);
2042}
2043
2044TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002049 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002050 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2051 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052}
2053
2054TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002055 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002057 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002059 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002060 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002061 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062}
2063
2064TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002068 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069
2070 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002071 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002073 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002077 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2079
deadbeefd59daf82015-10-14 15:02:44 -07002080 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081
deadbeefab9b2d12015-10-14 11:33:11 -07002082 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002083 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002084 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085}
2086
2087TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002091 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
2093 JsepSessionDescription* pranswer =
2094 CreateRemoteAnswer(session_->local_description());
2095 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2096
2097 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002098 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 JsepSessionDescription* pranswer2 =
2102 CreateRemoteAnswer(session_->local_description());
2103 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2104
2105 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002106 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
deadbeefab9b2d12015-10-14 11:33:11 -07002108 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 SessionDescriptionInterface* answer =
2110 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002111 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112}
2113
2114TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002115 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002116 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002117 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 SessionDescriptionInterface* answer =
2120 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002121 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2122 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123}
2124
2125TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002126 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002127 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2129
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 SessionDescriptionInterface* answer =
2131 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002132 SetRemoteDescriptionAnswerExpectError(
2133 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134}
2135
2136TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002138 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
2140 cricket::Candidate candidate;
2141 candidate.set_component(1);
2142 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2143
deadbeefd59daf82015-10-14 15:02:44 -07002144 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2146
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002147 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002149
2150 // Fail since we have not set a remote description.
2151 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
2153 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2154 session_->local_description());
2155 SetRemoteDescriptionWithoutError(answer);
2156
deadbeefd59daf82015-10-14 15:02:44 -07002157 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2158 candidate.set_component(2);
2159 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2160 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2161
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 // Verifying the candidates are copied properly from internal vector.
2163 const SessionDescriptionInterface* remote_desc =
2164 session_->remote_description();
2165 ASSERT_TRUE(remote_desc != NULL);
2166 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2167 const IceCandidateCollection* candidates =
2168 remote_desc->candidates(kMediaContentIndex0);
2169 ASSERT_EQ(2u, candidates->count());
2170 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2171 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2172 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2173 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2174
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002175 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2176 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 candidate.set_component(2);
2178 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2179 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002180 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181
2182 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2183 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2184}
2185
2186// Test that a remote candidate is added to the remote session description and
2187// that it is retained if the remote session description is changed.
2188TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002189 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 cricket::Candidate candidate1;
2191 candidate1.set_component(1);
2192 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2193 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002194 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 CreateAndSetRemoteOfferAndLocalAnswer();
2196
2197 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2198 const SessionDescriptionInterface* remote_desc =
2199 session_->remote_description();
2200 ASSERT_TRUE(remote_desc != NULL);
2201 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2202 const IceCandidateCollection* candidates =
2203 remote_desc->candidates(kMediaContentIndex0);
2204 ASSERT_EQ(1u, candidates->count());
2205 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2206
2207 // Update the RemoteSessionDescription with a new session description and
2208 // a candidate and check that the new remote session description contains both
2209 // candidates.
2210 SessionDescriptionInterface* offer = CreateRemoteOffer();
2211 cricket::Candidate candidate2;
2212 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2213 candidate2);
2214 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2215 SetRemoteDescriptionWithoutError(offer);
2216
2217 remote_desc = session_->remote_description();
2218 ASSERT_TRUE(remote_desc != NULL);
2219 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2220 candidates = remote_desc->candidates(kMediaContentIndex0);
2221 ASSERT_EQ(2u, candidates->count());
2222 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2223 // Username and password have be updated with the TransportInfo of the
2224 // SessionDescription, won't be equal to the original one.
2225 candidate2.set_username(candidates->at(0)->candidate().username());
2226 candidate2.set_password(candidates->at(0)->candidate().password());
2227 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2228 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2229 // No need to verify the username and password.
2230 candidate1.set_username(candidates->at(1)->candidate().username());
2231 candidate1.set_password(candidates->at(1)->candidate().password());
2232 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2233
2234 // Test that the candidate is ignored if we can add the same candidate again.
2235 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2236}
2237
2238// Test that local candidates are added to the local session description and
2239// that they are retained if the local session description is changed.
2240TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002241 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002243 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 CreateAndSetRemoteOfferAndLocalAnswer();
2245
2246 const SessionDescriptionInterface* local_desc = session_->local_description();
2247 const IceCandidateCollection* candidates =
2248 local_desc->candidates(kMediaContentIndex0);
2249 ASSERT_TRUE(candidates != NULL);
2250 EXPECT_EQ(0u, candidates->count());
2251
2252 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2253
2254 local_desc = session_->local_description();
2255 candidates = local_desc->candidates(kMediaContentIndex0);
2256 ASSERT_TRUE(candidates != NULL);
2257 EXPECT_LT(0u, candidates->count());
2258 candidates = local_desc->candidates(1);
2259 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002260 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261
2262 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002263 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 CreateAndSetRemoteOfferAndLocalAnswer();
2265
2266 local_desc = session_->local_description();
2267 candidates = local_desc->candidates(kMediaContentIndex0);
2268 ASSERT_TRUE(candidates != NULL);
2269 EXPECT_LT(0u, candidates->count());
2270 candidates = local_desc->candidates(1);
2271 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002272 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273}
2274
2275// Test that we can set a remote session description with remote candidates.
2276TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002277 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278
2279 cricket::Candidate candidate1;
2280 candidate1.set_component(1);
2281 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2282 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002283 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002284 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285
2286 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2287 SetRemoteDescriptionWithoutError(offer);
2288
2289 const SessionDescriptionInterface* remote_desc =
2290 session_->remote_description();
2291 ASSERT_TRUE(remote_desc != NULL);
2292 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2293 const IceCandidateCollection* candidates =
2294 remote_desc->candidates(kMediaContentIndex0);
2295 ASSERT_EQ(1u, candidates->count());
2296 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2297
wu@webrtc.org91053e72013-08-10 07:18:04 +00002298 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 SetLocalDescriptionWithoutError(answer);
2300}
2301
2302// Test that offers and answers contains ice candidates when Ice candidates have
2303// been gathered.
2304TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002305 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002306 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 // Ice is started but candidates are not provided until SetLocalDescription
2309 // is called.
2310 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2311 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2312 CreateAndSetRemoteOfferAndLocalAnswer();
2313 // Wait until at least one local candidate has been collected.
2314 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2315 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002317 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2318
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2320 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321
2322 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2323 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002324 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2326 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 SetLocalDescriptionWithoutError(answer);
2328}
2329
2330// Verifies TransportProxy and media channels are created with content names
2331// present in the SessionDescription.
2332TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002333 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002334 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002335 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336
2337 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002338 // "video". Goal is to modify these content names and verify transport
2339 // channels
2340 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 // present in SDP.
2342 std::string sdp;
2343 EXPECT_TRUE(offer->ToString(&sdp));
2344 const std::string kAudioMid = "a=mid:audio";
2345 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2346 const std::string kVideoMid = "a=mid:video";
2347 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2348
2349 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002350 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 kAudioMidReplaceStr.c_str(),
2352 kAudioMidReplaceStr.length(),
2353 &sdp);
2354 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002355 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 kVideoMidReplaceStr.c_str(),
2357 kVideoMidReplaceStr.length(),
2358 &sdp);
2359
2360 SessionDescriptionInterface* modified_offer =
2361 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2362
2363 SetRemoteDescriptionWithoutError(modified_offer);
2364
2365 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002366 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 SetLocalDescriptionWithoutError(answer);
2368
deadbeefcbecd352015-09-23 11:50:27 -07002369 cricket::TransportChannel* voice_transport_channel =
2370 session_->voice_rtp_transport_channel();
2371 EXPECT_TRUE(voice_transport_channel != NULL);
2372 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2373 cricket::TransportChannel* video_transport_channel =
2374 session_->video_rtp_transport_channel();
2375 EXPECT_TRUE(video_transport_channel != NULL);
2376 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2378 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2379}
2380
2381// Test that an offer contains the correct media content descriptions based on
2382// the send streams when no constraints have been set.
2383TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002384 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002385 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 ASSERT_TRUE(offer != NULL);
2388 const cricket::ContentInfo* content =
2389 cricket::GetFirstAudioContent(offer->description());
2390 EXPECT_TRUE(content != NULL);
2391 content = cricket::GetFirstVideoContent(offer->description());
2392 EXPECT_TRUE(content == NULL);
2393}
2394
2395// Test that an offer contains the correct media content descriptions based on
2396// the send streams when no constraints have been set.
2397TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002398 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002400 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002401 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 const cricket::ContentInfo* content =
2404 cricket::GetFirstAudioContent(offer->description());
2405 EXPECT_TRUE(content != NULL);
2406 content = cricket::GetFirstVideoContent(offer->description());
2407 EXPECT_TRUE(content == NULL);
2408
2409 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002410 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002411 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 content = cricket::GetFirstAudioContent(offer->description());
2413 EXPECT_TRUE(content != NULL);
2414 content = cricket::GetFirstVideoContent(offer->description());
2415 EXPECT_TRUE(content != NULL);
2416}
2417
2418// Test that an offer contains no media content descriptions if
2419// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2420TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002421 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002422 PeerConnectionInterface::RTCOfferAnswerOptions options;
2423 options.offer_to_receive_audio = 0;
2424 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002426 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002427 CreateOffer(options));
2428
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 ASSERT_TRUE(offer != NULL);
2430 const cricket::ContentInfo* content =
2431 cricket::GetFirstAudioContent(offer->description());
2432 EXPECT_TRUE(content == NULL);
2433 content = cricket::GetFirstVideoContent(offer->description());
2434 EXPECT_TRUE(content == NULL);
2435}
2436
2437// Test that an offer contains only audio media content descriptions if
2438// kOfferToReceiveAudio constraints are set to true.
2439TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002440 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002441 PeerConnectionInterface::RTCOfferAnswerOptions options;
2442 options.offer_to_receive_audio =
2443 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2444
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002445 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002446 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447
2448 const cricket::ContentInfo* content =
2449 cricket::GetFirstAudioContent(offer->description());
2450 EXPECT_TRUE(content != NULL);
2451 content = cricket::GetFirstVideoContent(offer->description());
2452 EXPECT_TRUE(content == NULL);
2453}
2454
2455// Test that an offer contains audio and video media content descriptions if
2456// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2457TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002458 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002460 PeerConnectionInterface::RTCOfferAnswerOptions options;
2461 options.offer_to_receive_audio =
2462 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2463 options.offer_to_receive_video =
2464 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2465
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002466 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002467 CreateOffer(options));
2468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 const cricket::ContentInfo* content =
2470 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002471 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002472
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 content = cricket::GetFirstVideoContent(offer->description());
2474 EXPECT_TRUE(content != NULL);
2475
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002476 // Sets constraints to false and verifies that audio/video contents are
2477 // removed.
2478 options.offer_to_receive_audio = 0;
2479 options.offer_to_receive_video = 0;
2480 offer.reset(CreateOffer(options));
2481
2482 content = cricket::GetFirstAudioContent(offer->description());
2483 EXPECT_TRUE(content == NULL);
2484 content = cricket::GetFirstVideoContent(offer->description());
2485 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486}
2487
2488// Test that an answer can not be created if the last remote description is not
2489// an offer.
2490TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002492 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 SetLocalDescriptionWithoutError(offer);
2494 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2495 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002496 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497}
2498
2499// Test that an answer contains the correct media content descriptions when no
2500// constraints have been set.
2501TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002502 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002504 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002506 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002507 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 const cricket::ContentInfo* content =
2509 cricket::GetFirstAudioContent(answer->description());
2510 ASSERT_TRUE(content != NULL);
2511 EXPECT_FALSE(content->rejected);
2512
2513 content = cricket::GetFirstVideoContent(answer->description());
2514 ASSERT_TRUE(content != NULL);
2515 EXPECT_FALSE(content->rejected);
2516}
2517
2518// Test that an answer contains the correct media content descriptions when no
2519// constraints have been set and the offer only contain audio.
2520TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 // Create a remote offer with audio only.
2523 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002524
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002525 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526 CreateRemoteOffer(options));
2527 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2528 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2529
2530 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002531 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002532 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 const cricket::ContentInfo* content =
2534 cricket::GetFirstAudioContent(answer->description());
2535 ASSERT_TRUE(content != NULL);
2536 EXPECT_FALSE(content->rejected);
2537
2538 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2539}
2540
2541// Test that an answer contains the correct media content descriptions when no
2542// constraints have been set.
2543TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002544 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002546 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 SetRemoteDescriptionWithoutError(offer.release());
2548 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002549 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002550 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002551 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 const cricket::ContentInfo* content =
2553 cricket::GetFirstAudioContent(answer->description());
2554 ASSERT_TRUE(content != NULL);
2555 EXPECT_FALSE(content->rejected);
2556
2557 content = cricket::GetFirstVideoContent(answer->description());
2558 ASSERT_TRUE(content != NULL);
2559 EXPECT_FALSE(content->rejected);
2560}
2561
2562// Test that an answer contains the correct media content descriptions when
2563// constraints have been set but no stream is sent.
2564TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002567 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 SetRemoteDescriptionWithoutError(offer.release());
2569
2570 webrtc::FakeConstraints constraints_no_receive;
2571 constraints_no_receive.SetMandatoryReceiveAudio(false);
2572 constraints_no_receive.SetMandatoryReceiveVideo(false);
2573
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002574 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002575 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 const cricket::ContentInfo* content =
2577 cricket::GetFirstAudioContent(answer->description());
2578 ASSERT_TRUE(content != NULL);
2579 EXPECT_TRUE(content->rejected);
2580
2581 content = cricket::GetFirstVideoContent(answer->description());
2582 ASSERT_TRUE(content != NULL);
2583 EXPECT_TRUE(content->rejected);
2584}
2585
2586// Test that an answer contains the correct media content descriptions when
2587// constraints have been set and streams are sent.
2588TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002589 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002591 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 SetRemoteDescriptionWithoutError(offer.release());
2593
2594 webrtc::FakeConstraints constraints_no_receive;
2595 constraints_no_receive.SetMandatoryReceiveAudio(false);
2596 constraints_no_receive.SetMandatoryReceiveVideo(false);
2597
2598 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002599 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002600 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002601 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602
2603 // TODO(perkj): Should the direction be set to SEND_ONLY?
2604 const cricket::ContentInfo* content =
2605 cricket::GetFirstAudioContent(answer->description());
2606 ASSERT_TRUE(content != NULL);
2607 EXPECT_FALSE(content->rejected);
2608
2609 // TODO(perkj): Should the direction be set to SEND_ONLY?
2610 content = cricket::GetFirstVideoContent(answer->description());
2611 ASSERT_TRUE(content != NULL);
2612 EXPECT_FALSE(content->rejected);
2613}
2614
2615TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2616 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002617 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002618 PeerConnectionInterface::RTCOfferAnswerOptions options;
2619 options.offer_to_receive_audio =
2620 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2621 options.voice_activity_detection = false;
2622
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002623 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002624 CreateOffer(options));
2625
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 const cricket::ContentInfo* content =
2627 cricket::GetFirstAudioContent(offer->description());
2628 EXPECT_TRUE(content != NULL);
2629 EXPECT_TRUE(VerifyNoCNCodecs(content));
2630}
2631
2632TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2633 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002634 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002636 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 SetRemoteDescriptionWithoutError(offer.release());
2638
2639 webrtc::FakeConstraints constraints;
2640 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002641 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002642 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 const cricket::ContentInfo* content =
2644 cricket::GetFirstAudioContent(answer->description());
2645 ASSERT_TRUE(content != NULL);
2646 EXPECT_TRUE(VerifyNoCNCodecs(content));
2647}
2648
2649// This test verifies the call setup when remote answer with audio only and
2650// later updates with video.
2651TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002652 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2654 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2655
deadbeefab9b2d12015-10-14 11:33:11 -07002656 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002657 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658
2659 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2661
2662 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2663 // and answer;
2664 SetLocalDescriptionWithoutError(offer);
2665 SetRemoteDescriptionWithoutError(answer);
2666
2667 video_channel_ = media_engine_->GetVideoChannel(0);
2668 voice_channel_ = media_engine_->GetVoiceChannel(0);
2669
2670 ASSERT_TRUE(video_channel_ == NULL);
2671
2672 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2673 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2674 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2675
2676 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002677 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678 CreateAndSetRemoteOfferAndLocalAnswer();
2679
2680 video_channel_ = media_engine_->GetVideoChannel(0);
2681 voice_channel_ = media_engine_->GetVoiceChannel(0);
2682
2683 ASSERT_TRUE(video_channel_ != NULL);
2684 ASSERT_TRUE(voice_channel_ != NULL);
2685
2686 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2687 ASSERT_EQ(1u, video_channel_->send_streams().size());
2688 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2689 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2690 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2691 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2692 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2694
2695 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002696 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697 CreateAndSetRemoteOfferAndLocalAnswer();
2698
2699 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2700 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2701 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2702 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2703 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2704}
2705
2706// This test verifies the call setup when remote answer with video only and
2707// later updates with audio.
2708TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002709 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2711 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002712 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002713 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714
2715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002716 options.recv_audio = false;
2717 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2719 offer, options, cricket::SEC_ENABLED);
2720
2721 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2722 // and answer.
2723 SetLocalDescriptionWithoutError(offer);
2724 SetRemoteDescriptionWithoutError(answer);
2725
2726 video_channel_ = media_engine_->GetVideoChannel(0);
2727 voice_channel_ = media_engine_->GetVoiceChannel(0);
2728
2729 ASSERT_TRUE(voice_channel_ == NULL);
2730 ASSERT_TRUE(video_channel_ != NULL);
2731
2732 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2733 ASSERT_EQ(1u, video_channel_->send_streams().size());
2734 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2735
2736 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002737 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 CreateAndSetRemoteOfferAndLocalAnswer();
2739
2740 voice_channel_ = media_engine_->GetVoiceChannel(0);
2741 ASSERT_TRUE(voice_channel_ != NULL);
2742
2743 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2744 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2745 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2746 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2747
2748 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 CreateAndSetRemoteOfferAndLocalAnswer();
2751
2752 video_channel_ = media_engine_->GetVideoChannel(0);
2753 voice_channel_ = media_engine_->GetVoiceChannel(0);
2754
2755 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2756 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2757 ASSERT_EQ(1u, video_channel_->send_streams().size());
2758 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2759}
2760
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002762 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002763 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002764 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 VerifyCryptoParams(offer->description());
2766 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002767 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 VerifyCryptoParams(answer->description());
2769}
2770
2771TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002772 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002773 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002774 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002775 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 VerifyNoCryptoParams(offer->description(), false);
2777}
2778
2779TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 VerifyAnswerFromNonCryptoOffer();
2782}
2783
2784TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 VerifyAnswerFromCryptoOffer();
2787}
2788
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002789// This test verifies that setLocalDescription fails if
2790// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2791TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002792 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002793 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002794 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2795
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002796 std::string sdp;
2797 RemoveIceUfragPwdLines(offer.get(), &sdp);
2798 SessionDescriptionInterface* modified_offer =
2799 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002800 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002801}
2802
2803// This test verifies that setRemoteDescription fails if
2804// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2805TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002806 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002807 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002808 std::string sdp;
2809 RemoveIceUfragPwdLines(offer.get(), &sdp);
2810 SessionDescriptionInterface* modified_offer =
2811 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002812 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002813}
2814
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002815// This test verifies that setLocalDescription fails if local offer has
2816// too short ice ufrag and pwd strings.
2817TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002818 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002819 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002820 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2821
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002822 std::string sdp;
2823 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2824 // recommended values of 4 and 22 bytes respectively.
2825 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2826 SessionDescriptionInterface* modified_offer =
2827 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2828 std::string error;
2829 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2830
2831 // Test with string greater than 256.
2832 sdp.clear();
2833 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2834 &sdp);
2835 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2836 NULL);
2837 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2838}
2839
2840// This test verifies that setRemoteDescription fails if remote offer has
2841// too short ice ufrag and pwd strings.
2842TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002843 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002844 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002845 std::string sdp;
2846 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2847 // recommended values of 4 and 22 bytes respectively.
2848 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2849 SessionDescriptionInterface* modified_offer =
2850 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2851 std::string error;
2852 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2853
2854 sdp.clear();
2855 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2856 &sdp);
2857 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2858 NULL);
2859 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2860}
2861
Honghai Zhang04e91462015-12-11 14:26:22 -08002862// Test that if the remote offer indicates the peer requested ICE restart (via
2863// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2864TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002865 Init();
2866 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2867
2868 // Create the first offer.
2869 std::string sdp;
2870 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2871 "abcdefghijklmnopqrstuvwx", &sdp);
2872 SessionDescriptionInterface* offer1 =
2873 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2874 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2875 0, "", "", "relay", 0, "");
2876 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2877 candidate1);
2878 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2879 SetRemoteDescriptionWithoutError(offer1);
2880 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2881
2882 // The second offer has the same ufrag and pwd but different address.
2883 sdp.clear();
2884 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2885 "abcdefghijklmnopqrstuvwx", &sdp);
2886 SessionDescriptionInterface* offer2 =
2887 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2888 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2889 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2890 candidate1);
2891 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2892 SetRemoteDescriptionWithoutError(offer2);
2893 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2894
2895 // The third offer has a different ufrag and different address.
2896 sdp.clear();
2897 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2898 "abcdefghijklmnopqrstuvwx", &sdp);
2899 SessionDescriptionInterface* offer3 =
2900 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2901 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2902 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2903 candidate1);
2904 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2905 SetRemoteDescriptionWithoutError(offer3);
2906 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2907
2908 // The fourth offer has no candidate but a different ufrag/pwd.
2909 sdp.clear();
2910 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2911 "abcdefghijklmnopqrstuvyz", &sdp);
2912 SessionDescriptionInterface* offer4 =
2913 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2914 SetRemoteDescriptionWithoutError(offer4);
2915 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2916}
2917
Honghai Zhang04e91462015-12-11 14:26:22 -08002918// Test that if the remote answer indicates the peer requested ICE restart (via
2919// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2920TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2921 Init();
2922 SessionDescriptionInterface* offer = CreateOffer();
2923 SetLocalDescriptionWithoutError(offer);
2924 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2925
2926 // Create the first answer.
2927 std::string sdp;
2928 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2929 "abcdefghijklmnopqrstuvwx", &sdp);
2930 SessionDescriptionInterface* answer1 =
2931 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2932 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2933 0, "", "", "relay", 0, "");
2934 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2935 candidate1);
2936 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2937 SetRemoteDescriptionWithoutError(answer1);
2938 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2939
2940 // The second answer has the same ufrag and pwd but different address.
2941 sdp.clear();
2942 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2943 "abcdefghijklmnopqrstuvwx", &sdp);
2944 SessionDescriptionInterface* answer2 =
2945 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2946 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2947 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2948 candidate1);
2949 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2950 SetRemoteDescriptionWithoutError(answer2);
2951 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2952
2953 // The third answer has a different ufrag and different address.
2954 sdp.clear();
2955 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2956 "abcdefghijklmnopqrstuvwx", &sdp);
2957 SessionDescriptionInterface* answer3 =
2958 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2959 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2960 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2961 candidate1);
2962 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2963 SetRemoteDescriptionWithoutError(answer3);
2964 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2965
2966 // The fourth answer has no candidate but a different ufrag/pwd.
2967 sdp.clear();
2968 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2969 "abcdefghijklmnopqrstuvyz", &sdp);
2970 SessionDescriptionInterface* offer4 =
2971 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2972 SetRemoteDescriptionWithoutError(offer4);
2973 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2974}
2975
Donald Curtisd4f769d2015-05-28 09:48:21 -07002976// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002977// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002978TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2979 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2980
2981 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002982 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002983
2984 PeerConnectionInterface::RTCOfferAnswerOptions options;
2985 options.use_rtp_mux = true;
2986
2987 SessionDescriptionInterface* offer = CreateRemoteOffer();
2988 SetRemoteDescriptionWithoutError(offer);
2989
2990 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2991 SetLocalDescriptionWithoutError(answer);
2992
deadbeefcbecd352015-09-23 11:50:27 -07002993 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2994 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002995
deadbeefcbecd352015-09-23 11:50:27 -07002996 cricket::BaseChannel* voice_channel = session_->voice_channel();
2997 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002998
2999 // Checks if one of the transport channels contains a connection using a given
3000 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003001 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003002 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003003 session_->GetChannelTransportStats(voice_channel, &stats);
3004 for (auto& kv : stats.transport_stats) {
3005 for (auto& chan_stat : kv.second.channel_stats) {
3006 for (auto& conn_info : chan_stat.connection_infos) {
3007 if (conn_info.remote_candidate.address().port() == port) {
3008 return true;
3009 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003010 }
3011 }
3012 }
3013 return false;
3014 };
3015
3016 EXPECT_FALSE(connection_with_remote_port(5000));
3017 EXPECT_FALSE(connection_with_remote_port(5001));
3018 EXPECT_FALSE(connection_with_remote_port(6000));
3019
3020 // The way the *_WAIT checks work is they only wait if the condition fails,
3021 // which does not help in the case where state is not changing. This is
3022 // problematic in this test since we want to verify that adding a video
3023 // candidate does _not_ change state. So we interleave candidates and assume
3024 // that messages are executed in the order they were posted.
3025
3026 // First audio candidate.
3027 cricket::Candidate candidate0;
3028 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3029 candidate0.set_component(1);
3030 candidate0.set_protocol("udp");
3031 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3032 candidate0);
3033 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3034
3035 // Video candidate.
3036 cricket::Candidate candidate1;
3037 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3038 candidate1.set_component(1);
3039 candidate1.set_protocol("udp");
3040 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3041 candidate1);
3042 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3043
3044 // Second audio candidate.
3045 cricket::Candidate candidate2;
3046 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3047 candidate2.set_component(1);
3048 candidate2.set_protocol("udp");
3049 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3050 candidate2);
3051 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3052
3053 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3054 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3055
3056 // No need here for a _WAIT check since we are checking that state hasn't
3057 // changed: if this is false we would be doing waits for nothing and if this
3058 // is true then there will be no messages processed anyways.
3059 EXPECT_FALSE(connection_with_remote_port(6000));
3060}
3061
deadbeefcbecd352015-09-23 11:50:27 -07003062// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003063TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3064 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003065 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003066
3067 PeerConnectionInterface::RTCOfferAnswerOptions options;
3068 options.use_rtp_mux = true;
3069
3070 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003072
deadbeefcbecd352015-09-23 11:50:27 -07003073 EXPECT_NE(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());
Donald Curtis0e209b02015-03-24 09:29:54 -07003083}
3084
deadbeefcbecd352015-09-23 11:50:27 -07003085// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003086TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3087 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003088 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003089
Donald Curtis0e209b02015-03-24 09:29:54 -07003090 PeerConnectionInterface::RTCOfferAnswerOptions options;
3091 options.use_rtp_mux = true;
3092
3093 SessionDescriptionInterface* offer = CreateOffer(options);
3094 SetLocalDescriptionWithoutError(offer);
3095
deadbeefcbecd352015-09-23 11:50:27 -07003096 EXPECT_NE(session_->voice_rtp_transport_channel(),
3097 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003098
deadbeefab9b2d12015-10-14 11:33:11 -07003099 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003100
3101 // Remove BUNDLE from the answer.
3102 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3103 CreateRemoteAnswer(session_->local_description()));
3104 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3105 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3106 JsepSessionDescription* modified_answer =
3107 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3108 modified_answer->Initialize(answer_copy, "1", "1");
3109 SetRemoteDescriptionWithoutError(modified_answer); //
3110
deadbeefcbecd352015-09-23 11:50:27 -07003111 EXPECT_NE(session_->voice_rtp_transport_channel(),
3112 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003113}
3114
3115// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3116TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3117 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003118 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003119
3120 PeerConnectionInterface::RTCOfferAnswerOptions options;
3121 options.use_rtp_mux = true;
3122
3123 SessionDescriptionInterface* offer = CreateOffer(options);
3124 SetLocalDescriptionWithoutError(offer);
3125
deadbeefcbecd352015-09-23 11:50:27 -07003126 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3127 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003128
deadbeefab9b2d12015-10-14 11:33:11 -07003129 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003130 SessionDescriptionInterface* answer =
3131 CreateRemoteAnswer(session_->local_description());
3132 SetRemoteDescriptionWithoutError(answer);
3133
deadbeefcbecd352015-09-23 11:50:27 -07003134 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3135 session_->video_rtp_transport_channel());
3136}
3137
3138// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3139// audio content in the answer.
3140TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3141 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003142 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003143
3144 PeerConnectionInterface::RTCOfferAnswerOptions options;
3145 options.use_rtp_mux = true;
3146
3147 SessionDescriptionInterface* offer = CreateOffer(options);
3148 SetLocalDescriptionWithoutError(offer);
3149
3150 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3151 session_->video_rtp_transport_channel());
3152
deadbeefab9b2d12015-10-14 11:33:11 -07003153 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003154 cricket::MediaSessionOptions recv_options;
3155 recv_options.recv_audio = false;
3156 recv_options.recv_video = true;
3157 SessionDescriptionInterface* answer =
3158 CreateRemoteAnswer(session_->local_description(), recv_options);
3159 SetRemoteDescriptionWithoutError(answer);
3160
deadbeefd59daf82015-10-14 15:02:44 -07003161 EXPECT_TRUE(nullptr == session_->voice_channel());
3162 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003163
deadbeefd59daf82015-10-14 15:02:44 -07003164 session_->Close();
3165 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3166 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3167 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3168 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003169}
3170
3171// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3172TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3173 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003174 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003175
Donald Curtis0e209b02015-03-24 09:29:54 -07003176 PeerConnectionInterface::RTCOfferAnswerOptions options;
3177 options.use_rtp_mux = true;
3178
3179 SessionDescriptionInterface* offer = CreateOffer(options);
3180 SetLocalDescriptionWithoutError(offer);
3181
deadbeefcbecd352015-09-23 11:50:27 -07003182 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3183 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003184
deadbeefab9b2d12015-10-14 11:33:11 -07003185 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003186
3187 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003188 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189 CreateRemoteAnswer(session_->local_description()));
3190 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3191 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3192 JsepSessionDescription* modified_answer =
3193 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3194 modified_answer->Initialize(answer_copy, "1", "1");
3195 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196
deadbeefcbecd352015-09-23 11:50:27 -07003197 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3198 session_->video_rtp_transport_channel());
3199}
3200
3201// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3202TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3203 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003204 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003205
3206 SessionDescriptionInterface* offer = CreateRemoteOffer();
3207 SetRemoteDescriptionWithoutError(offer);
3208
3209 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3210 session_->video_rtp_transport_channel());
3211
deadbeefab9b2d12015-10-14 11:33:11 -07003212 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003213 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3214 SetLocalDescriptionWithoutError(answer);
3215
3216 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3217 session_->video_rtp_transport_channel());
3218}
3219
3220// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3221TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3222 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003224
3225 // Remove BUNDLE from the offer.
3226 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3227 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3228 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3229 JsepSessionDescription* modified_offer =
3230 new JsepSessionDescription(JsepSessionDescription::kOffer);
3231 modified_offer->Initialize(offer_copy, "1", "1");
3232
3233 // Expect an error when applying the remote description
3234 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3235 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003236}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237
Peter Thatcher4eddf182015-04-30 10:55:59 -07003238// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003239TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3240 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003241 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
Donald Curtis0e209b02015-03-24 09:29:54 -07003243 PeerConnectionInterface::RTCOfferAnswerOptions options;
3244 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
Donald Curtis0e209b02015-03-24 09:29:54 -07003246 SessionDescriptionInterface* offer = CreateOffer(options);
3247 SetLocalDescriptionWithoutError(offer);
3248
deadbeefcbecd352015-09-23 11:50:27 -07003249 EXPECT_NE(session_->voice_rtp_transport_channel(),
3250 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003251
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003253 SessionDescriptionInterface* answer =
3254 CreateRemoteAnswer(session_->local_description());
3255 SetRemoteDescriptionWithoutError(answer);
3256
3257 // This should lead to an audio-only call but isn't implemented
3258 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003259 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3260 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003261}
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003264TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3265 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003267 PeerConnectionInterface::RTCOfferAnswerOptions options;
3268 options.use_rtp_mux = true;
3269
3270 SessionDescriptionInterface* offer = CreateOffer(options);
3271 SetLocalDescriptionWithoutError(offer);
3272
deadbeefcbecd352015-09-23 11:50:27 -07003273 EXPECT_NE(session_->voice_rtp_transport_channel(),
3274 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003275
deadbeefab9b2d12015-10-14 11:33:11 -07003276 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003277
3278 // Remove BUNDLE from the answer.
3279 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3280 CreateRemoteAnswer(session_->local_description()));
3281 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3282 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3283 JsepSessionDescription* modified_answer =
3284 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3285 modified_answer->Initialize(answer_copy, "1", "1");
3286 SetRemoteDescriptionWithoutError(modified_answer); //
3287
deadbeefcbecd352015-09-23 11:50:27 -07003288 EXPECT_NE(session_->voice_rtp_transport_channel(),
3289 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290}
3291
Peter Thatcher4eddf182015-04-30 10:55:59 -07003292// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3293TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3294 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003295 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003296
3297 PeerConnectionInterface::RTCOfferAnswerOptions options;
3298 options.use_rtp_mux = true;
3299
3300 SessionDescriptionInterface* offer = CreateOffer(options);
3301 SetRemoteDescriptionWithoutError(offer);
3302
deadbeefcbecd352015-09-23 11:50:27 -07003303 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3304 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003305}
3306
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003307TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3308 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003309 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003310
3311 PeerConnectionInterface::RTCOfferAnswerOptions options;
3312 SessionDescriptionInterface* offer = CreateOffer(options);
3313 SetLocalDescriptionWithoutError(offer);
3314
deadbeefcbecd352015-09-23 11:50:27 -07003315 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3316 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003317
deadbeefab9b2d12015-10-14 11:33:11 -07003318 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003319 SessionDescriptionInterface* answer =
3320 CreateRemoteAnswer(session_->local_description());
3321 SetRemoteDescriptionWithoutError(answer);
3322
deadbeefcbecd352015-09-23 11:50:27 -07003323 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3324 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003325}
3326
3327TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3328 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003329 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003330
3331 PeerConnectionInterface::RTCOfferAnswerOptions options;
3332 SessionDescriptionInterface* offer = CreateOffer(options);
3333 SetLocalDescriptionWithoutError(offer);
3334
deadbeefcbecd352015-09-23 11:50:27 -07003335 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3336 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003337
deadbeefab9b2d12015-10-14 11:33:11 -07003338 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003339 SessionDescriptionInterface* answer =
3340 CreateRemoteAnswer(session_->local_description());
3341 SetRemoteDescriptionWithoutError(answer);
3342
deadbeefcbecd352015-09-23 11:50:27 -07003343 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3344 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003345}
3346
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003347// This test verifies that SetLocalDescription and SetRemoteDescription fails
3348// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3349TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003350 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003351 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003352
3353 PeerConnectionInterface::RTCOfferAnswerOptions options;
3354 options.use_rtp_mux = true;
3355
3356 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003357 std::string offer_str;
3358 offer->ToString(&offer_str);
3359 // Disable rtcp-mux
3360 const std::string rtcp_mux = "rtcp-mux";
3361 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003362 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003363 xrtcp_mux.c_str(), xrtcp_mux.length(),
3364 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003365 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003366 new JsepSessionDescription(JsepSessionDescription::kOffer);
3367 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003368 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003369 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003370 new JsepSessionDescription(JsepSessionDescription::kOffer);
3371 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003372 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003373 // Trying unmodified SDP.
3374 SetLocalDescriptionWithoutError(offer);
3375}
3376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003378 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003379 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380 CreateAndSetRemoteOfferAndLocalAnswer();
3381 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3382 ASSERT_TRUE(channel != NULL);
3383 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003384 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003385 double volume;
3386 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3387 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003388 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003389 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3390 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003391 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003392 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3393 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394}
3395
3396TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003397 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003398 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 CreateAndSetRemoteOfferAndLocalAnswer();
3400 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3401 ASSERT_TRUE(channel != NULL);
3402 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003403 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3405
3406 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003407 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003409 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003410 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003412 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003413 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003415 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003416 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003418 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003419 EXPECT_TRUE(renderer->sink() == NULL);
3420}
3421
3422TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003423 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003424 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003425 CreateAndSetRemoteOfferAndLocalAnswer();
3426 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3427 ASSERT_TRUE(channel != NULL);
3428 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003429 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003430
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003431 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003432 cricket::AudioOptions options;
3433 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3434 EXPECT_TRUE(renderer->sink() != NULL);
3435
3436 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3437 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3438 // SetSink(NULL) callback afterwards.
3439 renderer.reset();
3440
3441 // This will trigger SetSink(NULL) if no OnClose() callback.
3442 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443}
3444
3445TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003446 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003447 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 CreateAndSetRemoteOfferAndLocalAnswer();
3449 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3450 ASSERT_TRUE(channel != NULL);
3451 ASSERT_LT(0u, channel->renderers().size());
3452 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3453 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003454 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 cricket::FakeVideoRenderer renderer;
3456 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3457 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3458 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3459 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3460}
3461
3462TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003463 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003464 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 CreateAndSetRemoteOfferAndLocalAnswer();
3466 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3467 ASSERT_TRUE(channel != NULL);
3468 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003469 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3471 cricket::VideoOptions* options = NULL;
3472 session_->SetVideoSend(send_ssrc, false, options);
3473 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3474 session_->SetVideoSend(send_ssrc, true, options);
3475 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3476}
3477
3478TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3479 TestCanInsertDtmf(false);
3480}
3481
3482TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3483 TestCanInsertDtmf(true);
3484}
3485
3486TEST_F(WebRtcSessionTest, InsertDtmf) {
3487 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003488 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003489 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 CreateAndSetRemoteOfferAndLocalAnswer();
3491 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3492 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3493
3494 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 const int expected_duration = 90;
3496 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3497 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3498 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3499
3500 // Verify
3501 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003502 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003504 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003506 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003508 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509}
3510
deadbeefd59daf82015-10-14 15:02:44 -07003511// This test verifies the |initial_offerer| flag when session initiates the
3512// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003514 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003515 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003516 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3518 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003519 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003521 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522}
3523
deadbeefd59daf82015-10-14 15:02:44 -07003524// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003526 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003527 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 SessionDescriptionInterface* offer = CreateRemoteOffer();
3529 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003530 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531
deadbeefd59daf82015-10-14 15:02:44 -07003532 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003534 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535}
3536
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3538TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003539 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003540 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003541 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003543 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 CreateRemoteAnswer(session_->local_description()));
3545
3546 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3547 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003548 JsepSessionDescription* modified_answer =
3549 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550
3551 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3552 answer->session_id(),
3553 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003554 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555
wu@webrtc.org4e393072014-04-07 17:04:35 +00003556 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003557 std::string sdp;
3558 EXPECT_TRUE(answer->ToString(&sdp));
3559 const std::string kAudioMid = "a=mid:audio";
3560 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003561 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 kAudioMidReplaceStr.c_str(),
3563 kAudioMidReplaceStr.length(),
3564 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003565 SessionDescriptionInterface* modified_answer1 =
3566 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003567 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568
wu@webrtc.org4e393072014-04-07 17:04:35 +00003569 // Different media types.
3570 EXPECT_TRUE(answer->ToString(&sdp));
3571 const std::string kAudioMline = "m=audio";
3572 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003573 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003574 kAudioMlineReplaceStr.c_str(),
3575 kAudioMlineReplaceStr.length(),
3576 &sdp);
3577 SessionDescriptionInterface* modified_answer2 =
3578 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3579 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 SetRemoteDescriptionWithoutError(answer.release());
3582}
3583
3584// Verifying remote offer and local answer have matching m-lines as per
3585// RFC 3264.
3586TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003587 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003588 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 SessionDescriptionInterface* offer = CreateRemoteOffer();
3590 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003591 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592
3593 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3594 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003595 JsepSessionDescription* modified_answer =
3596 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597
3598 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3599 answer->session_id(),
3600 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003601 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 SetLocalDescriptionWithoutError(answer);
3603}
3604
3605// This test verifies that WebRtcSession does not start candidate allocation
3606// before SetLocalDescription is called.
3607TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003608 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003609 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610 SessionDescriptionInterface* offer = CreateRemoteOffer();
3611 cricket::Candidate candidate;
3612 candidate.set_component(1);
3613 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3614 candidate);
3615 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3616 cricket::Candidate candidate1;
3617 candidate1.set_component(1);
3618 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3619 candidate1);
3620 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3621 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003622 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3623 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624
3625 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003626 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003627 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3628 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3629
wu@webrtc.org91053e72013-08-10 07:18:04 +00003630 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3633}
3634
3635// This test verifies that crypto parameter is updated in local session
3636// description as per security policy set in MediaSessionDescriptionFactory.
3637TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003638 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003639 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003640 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641
3642 // Making sure SetLocalDescription correctly sets crypto value in
3643 // SessionDescription object after de-serialization of sdp string. The value
3644 // will be set as per MediaSessionDescriptionFactory.
3645 std::string offer_str;
3646 offer->ToString(&offer_str);
3647 SessionDescriptionInterface* jsep_offer_str =
3648 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3649 SetLocalDescriptionWithoutError(jsep_offer_str);
3650 EXPECT_TRUE(session_->voice_channel()->secure_required());
3651 EXPECT_TRUE(session_->video_channel()->secure_required());
3652}
3653
3654// This test verifies the crypto parameter when security is disabled.
3655TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003656 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003657 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003658 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003659 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003660
3661 // Making sure SetLocalDescription correctly sets crypto value in
3662 // SessionDescription object after de-serialization of sdp string. The value
3663 // will be set as per MediaSessionDescriptionFactory.
3664 std::string offer_str;
3665 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003666 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3668 SetLocalDescriptionWithoutError(jsep_offer_str);
3669 EXPECT_FALSE(session_->voice_channel()->secure_required());
3670 EXPECT_FALSE(session_->video_channel()->secure_required());
3671}
3672
3673// This test verifies that an answer contains new ufrag and password if an offer
3674// with new ufrag and password is received.
3675TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003676 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003678 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003679 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 CreateRemoteOffer(options));
3681 SetRemoteDescriptionWithoutError(offer.release());
3682
deadbeefab9b2d12015-10-14 11:33:11 -07003683 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003684 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003685 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686 SetLocalDescriptionWithoutError(answer.release());
3687
3688 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003689 options.audio_transport_options.ice_restart = true;
3690 options.video_transport_options.ice_restart = true;
3691 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003692 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003693 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003694 SetRemoteDescriptionWithoutError(updated_offer1.release());
3695
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003696 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003697 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003698
3699 CompareIceUfragAndPassword(updated_answer1->description(),
3700 session_->local_description()->description(),
3701 false);
3702
3703 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003704}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003705
wu@webrtc.org91053e72013-08-10 07:18:04 +00003706// This test verifies that an answer contains old ufrag and password if an offer
3707// with old ufrag and password is received.
3708TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003709 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003710 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003711 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003712 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003713 CreateRemoteOffer(options));
3714 SetRemoteDescriptionWithoutError(offer.release());
3715
deadbeefab9b2d12015-10-14 11:33:11 -07003716 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003717 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003718 CreateAnswer(NULL));
3719 SetLocalDescriptionWithoutError(answer.release());
3720
3721 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003722 options.audio_transport_options.ice_restart = false;
3723 options.video_transport_options.ice_restart = false;
3724 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003725 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003726 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003727 SetRemoteDescriptionWithoutError(updated_offer2.release());
3728
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003729 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003730 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003731
3732 CompareIceUfragAndPassword(updated_answer2->description(),
3733 session_->local_description()->description(),
3734 true);
3735
3736 SetLocalDescriptionWithoutError(updated_answer2.release());
3737}
3738
3739TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003740 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003741 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003742 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 const std::string session_id_orig = offer->session_id();
3744 const std::string session_version_orig = offer->session_version();
3745 SetLocalDescriptionWithoutError(offer);
3746
3747 video_channel_ = media_engine_->GetVideoChannel(0);
3748 video_channel_->set_fail_set_send_codecs(true);
3749
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003750 SessionDescriptionInterface* answer =
3751 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003752 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003753
3754 // Test that after a content error, setting any description will
3755 // result in an error.
3756 video_channel_->set_fail_set_send_codecs(false);
3757 answer = CreateRemoteAnswer(session_->local_description());
3758 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3759 offer = CreateRemoteOffer();
3760 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003761}
3762
3763// Runs the loopback call test with BUNDLE and STUN disabled.
3764TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3765 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003766 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003767 cricket::PORTALLOCATOR_DISABLE_STUN |
3768 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003769 TestLoopbackCall();
3770}
3771
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003772TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003773 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003774 cricket::PORTALLOCATOR_DISABLE_STUN |
3775 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3776 cricket::PORTALLOCATOR_DISABLE_RELAY);
3777
3778 // best connection is IPv6 since it has higher network preference.
3779 LoopbackNetworkConfiguration config;
3780 config.test_ipv6_network_ = true;
3781 config.best_connection_after_initial_ice_converged_ =
3782 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3783
3784 TestLoopbackCall(config);
3785}
3786
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003787// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003788TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003789 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3790 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003791 TestLoopbackCall();
3792}
3793
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003794TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3795 constraints_.reset(new FakeConstraints());
3796 constraints_->AddOptional(
3797 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003798 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003799
3800 SetLocalDescriptionWithDataChannel();
3801 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3802}
3803
Henrik Boström87713d02015-08-25 09:53:21 +02003804TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003805 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003806
3807 constraints_.reset(new FakeConstraints());
3808 constraints_->AddOptional(
3809 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003810 options_.disable_sctp_data_channels = false;
3811
Henrik Boström87713d02015-08-25 09:53:21 +02003812 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813
3814 SetLocalDescriptionWithDataChannel();
3815 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3816}
3817
Henrik Boström87713d02015-08-25 09:53:21 +02003818TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003820
Henrik Boström87713d02015-08-25 09:53:21 +02003821 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003822
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003823 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003824 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003825 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3826}
3827
Henrik Boström87713d02015-08-25 09:53:21 +02003828TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003829 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003830 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003831 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003832
3833 // Create remote offer with SCTP.
3834 cricket::MediaSessionOptions options;
3835 options.data_channel_type = cricket::DCT_SCTP;
3836 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003837 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003838 SetRemoteDescriptionWithoutError(offer);
3839
3840 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003841 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003842 EXPECT_TRUE(answer != NULL);
3843 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3844 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003845}
3846
Henrik Boström87713d02015-08-25 09:53:21 +02003847TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003848 constraints_.reset(new FakeConstraints());
3849 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003850 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003851 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003852
3853 SetLocalDescriptionWithDataChannel();
3854 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3855}
3856
Henrik Boström87713d02015-08-25 09:53:21 +02003857TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003858 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003859
Henrik Boström87713d02015-08-25 09:53:21 +02003860 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003861
3862 SetLocalDescriptionWithDataChannel();
3863 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3864}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003865
Henrik Boström87713d02015-08-25 09:53:21 +02003866TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003867 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003868 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003869 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003870
3871 SetLocalDescriptionWithDataChannel();
3872 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3873}
3874
Henrik Boström87713d02015-08-25 09:53:21 +02003875TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003876 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003877 const int new_send_port = 9998;
3878 const int new_recv_port = 7775;
3879
Henrik Boström87713d02015-08-25 09:53:21 +02003880 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003881 SetFactoryDtlsSrtp();
3882
3883 // By default, don't actually add the codecs to desc_factory_; they don't
3884 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3885 // let the session description get parsed. That'll get the proper codecs
3886 // into the stream.
3887 cricket::MediaSessionOptions options;
3888 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3889 "stream1", new_send_port, options);
3890
3891 // SetRemoteDescription will take the ownership of the offer.
3892 SetRemoteDescriptionWithoutError(offer);
3893
3894 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3895 new_recv_port, CreateAnswer(NULL));
3896 ASSERT_TRUE(answer != NULL);
3897
3898 // Now set the local description, which'll take ownership of the answer.
3899 SetLocalDescriptionWithoutError(answer);
3900
3901 // TEST PLAN: Set the port number to something new, set it in the SDP,
3902 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003903 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003904 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003905
3906 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3907 int portnum = -1;
3908 ASSERT_TRUE(ch != NULL);
3909 ASSERT_EQ(1UL, ch->send_codecs().size());
3910 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003911 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003912 ch->send_codecs()[0].name.c_str()));
3913 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3914 &portnum));
3915 EXPECT_EQ(new_send_port, portnum);
3916
3917 ASSERT_EQ(1UL, ch->recv_codecs().size());
3918 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003919 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003920 ch->recv_codecs()[0].name.c_str()));
3921 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3922 &portnum));
3923 EXPECT_EQ(new_recv_port, portnum);
3924}
3925
deadbeefab9b2d12015-10-14 11:33:11 -07003926// Verifies that when a session's DataChannel receives an OPEN message,
3927// WebRtcSession signals the DataChannel creation request with the expected
3928// config.
3929TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3930 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3931
3932 InitWithDtls(GetParam());
3933
3934 SetLocalDescriptionWithDataChannel();
3935 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3936
3937 webrtc::DataChannelInit config;
3938 config.id = 1;
3939 rtc::Buffer payload;
3940 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3941 cricket::ReceiveDataParams params;
3942 params.ssrc = config.id;
3943 params.type = cricket::DMT_CONTROL;
3944
3945 cricket::DataChannel* data_channel = session_->data_channel();
3946 data_channel->SignalDataReceived(data_channel, params, payload);
3947
3948 EXPECT_EQ("a", last_data_channel_label_);
3949 EXPECT_EQ(config.id, last_data_channel_config_.id);
3950 EXPECT_FALSE(last_data_channel_config_.negotiated);
3951 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3952 last_data_channel_config_.open_handshake_role);
3953}
3954
3955TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003956 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3957 FakeDtlsIdentityStore::GenerateCertificate();
3958
3959 PeerConnectionInterface::RTCConfiguration configuration;
3960 configuration.certificates.push_back(certificate);
3961 Init(nullptr, configuration);
3962 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3963
3964 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3965}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003966
Henrik Boström87713d02015-08-25 09:53:21 +02003967// Verifies that CreateOffer succeeds when CreateOffer is called before async
3968// identity generation is finished (even if a certificate is provided this is
3969// an async op).
3970TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3971 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3972 InitWithDtls(GetParam());
3973
Henrik Boströmd8281982015-08-27 10:12:24 +02003974 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003975 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003976 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3977
wu@webrtc.org91053e72013-08-10 07:18:04 +00003978 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003979 VerifyNoCryptoParams(offer->description(), true);
3980 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003981}
3982
3983// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003984// identity generation is finished (even if a certificate is provided this is
3985// an async op).
3986TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003987 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003988 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003989 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003990
3991 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003992 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003993 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003994 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003995 ASSERT_TRUE(offer.get() != NULL);
3996 SetRemoteDescriptionWithoutError(offer.release());
3997
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003998 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003999 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004000 VerifyNoCryptoParams(answer->description(), true);
4001 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004002}
4003
4004// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004005// identity generation is finished (even if a certificate is provided this is
4006// an async op).
4007TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004008 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004009 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004010
Henrik Boströmd8281982015-08-27 10:12:24 +02004011 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004012
4013 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004014 EXPECT_TRUE(offer != NULL);
4015}
4016
4017// Verifies that CreateOffer fails when CreateOffer is called after async
4018// identity generation fails.
4019TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004021 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004022
Henrik Boströmd8281982015-08-27 10:12:24 +02004023 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004024
4025 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004026 EXPECT_TRUE(offer == NULL);
4027}
4028
4029// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4030// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004031TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004032 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004033 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004034 VerifyMultipleAsyncCreateDescription(GetParam(),
4035 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004036}
4037
4038// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4039// before async identity generation fails.
4040TEST_F(WebRtcSessionTest,
4041 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004042 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004043 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4044 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004045}
4046
4047// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4048// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004049TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004050 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004051 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004052 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004053 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004054}
4055
4056// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4057// before async identity generation fails.
4058TEST_F(WebRtcSessionTest,
4059 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004060 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004061 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4062 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004063}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004064
4065// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4066// offer has no SDES crypto but only DTLS fingerprint.
4067TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4068 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004069 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004070 // Create a remote offer with secured transport disabled.
4071 cricket::MediaSessionOptions options;
4072 JsepSessionDescription* offer(CreateRemoteOffer(
4073 options, cricket::SEC_DISABLED));
4074 // Adds a DTLS fingerprint to the remote offer.
4075 cricket::SessionDescription* sdp = offer->description();
4076 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4077 ASSERT_TRUE(audio != NULL);
4078 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4079 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004080 rtc::SSLFingerprint::CreateFromRfc4572(
4081 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004082 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004083 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004084}
4085
wu@webrtc.orgde305012013-10-31 15:40:38 +00004086// This test verifies DSCP is properly applied on the media channels.
4087TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4088 constraints_.reset(new FakeConstraints());
4089 constraints_->AddOptional(
4090 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004092 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004093 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004094
4095 SetLocalDescriptionWithoutError(offer);
4096
4097 video_channel_ = media_engine_->GetVideoChannel(0);
4098 voice_channel_ = media_engine_->GetVoiceChannel(0);
4099
4100 ASSERT_TRUE(video_channel_ != NULL);
4101 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004102 const cricket::AudioOptions& audio_options = voice_channel_->options();
4103 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004104 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4105 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004106}
4107
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004108TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4109 constraints_.reset(new FakeConstraints());
4110 constraints_->AddOptional(
4111 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4112 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004113 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004114 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004115 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004116
4117 SetLocalDescriptionWithoutError(offer);
4118
4119 video_channel_ = media_engine_->GetVideoChannel(0);
4120
4121 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004122 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004123 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004124}
4125
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004126TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4127 // Number of unsignalled receiving streams should be between 0 and
4128 // kMaxUnsignalledRecvStreams.
4129 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4130 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4131 kMaxUnsignalledRecvStreams);
4132 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4133}
4134
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004135TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4136 constraints_.reset(new FakeConstraints());
4137 constraints_->AddOptional(
4138 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4139 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004140 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004141 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004142 SessionDescriptionInterface* offer = CreateOffer();
4143
4144 SetLocalDescriptionWithoutError(offer);
4145
4146 voice_channel_ = media_engine_->GetVoiceChannel(0);
4147
4148 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004149 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004150 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004151}
4152
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004153// Tests that we can renegotiate new media content with ICE candidates in the
4154// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004155TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004156 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004157 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004158 SetFactoryDtlsSrtp();
4159
deadbeefab9b2d12015-10-14 11:33:11 -07004160 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004161 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004162 SetLocalDescriptionWithoutError(offer);
4163
4164 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4165 SetRemoteDescriptionWithoutError(answer);
4166
4167 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004168 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4170
4171 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004172 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004173 candidate1.set_component(1);
4174 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4175 candidate1);
4176 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4177 SetRemoteDescriptionWithoutError(offer);
4178
4179 answer = CreateAnswer(NULL);
4180 SetLocalDescriptionWithoutError(answer);
4181}
4182
4183// Tests that we can renegotiate new media content with ICE candidates separated
4184// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004185TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004186 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004187 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004188 SetFactoryDtlsSrtp();
4189
deadbeefab9b2d12015-10-14 11:33:11 -07004190 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004191 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004192 SetLocalDescriptionWithoutError(offer);
4193
4194 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4195 SetRemoteDescriptionWithoutError(answer);
4196
4197 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004198 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4200 SetRemoteDescriptionWithoutError(offer);
4201
4202 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004203 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004204 candidate1.set_component(1);
4205 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4206 candidate1);
4207 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4208
4209 answer = CreateAnswer(NULL);
4210 SetLocalDescriptionWithoutError(answer);
4211}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004212// Tests that RTX codec is removed from the answer when it isn't supported
4213// by local side.
4214TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4215 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004216 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004217 std::string offer_sdp(kSdpWithRtx);
4218
4219 SessionDescriptionInterface* offer =
4220 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4221 EXPECT_TRUE(offer->ToString(&offer_sdp));
4222
4223 // Offer SDP contains the RTX codec.
4224 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4225 SetRemoteDescriptionWithoutError(offer);
4226
4227 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4228 std::string answer_sdp;
4229 answer->ToString(&answer_sdp);
4230 // Answer SDP removes the unsupported RTX codec.
4231 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4232 SetLocalDescriptionWithoutError(answer);
4233}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004234
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004235// This verifies that the voice channel after bundle has both options from video
4236// and voice channels.
4237TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4238 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004239 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004240
4241 PeerConnectionInterface::RTCOfferAnswerOptions options;
4242 options.use_rtp_mux = true;
4243
4244 SessionDescriptionInterface* offer = CreateOffer(options);
4245 SetLocalDescriptionWithoutError(offer);
4246
4247 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4248 rtc::Socket::Option::OPT_SNDBUF, 4000);
4249
4250 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4251 rtc::Socket::Option::OPT_RCVBUF, 8000);
4252
4253 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004254 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004255 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4256 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004257 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004258 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4259
deadbeefcbecd352015-09-23 11:50:27 -07004260 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004261 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4262 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004263 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004264 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4265
deadbeefcbecd352015-09-23 11:50:27 -07004266 EXPECT_NE(session_->voice_rtp_transport_channel(),
4267 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004268
deadbeefab9b2d12015-10-14 11:33:11 -07004269 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004270 SessionDescriptionInterface* answer =
4271 CreateRemoteAnswer(session_->local_description());
4272 SetRemoteDescriptionWithoutError(answer);
4273
deadbeefcbecd352015-09-23 11:50:27 -07004274 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004275 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4276 EXPECT_EQ(4000, option_val);
4277
deadbeefcbecd352015-09-23 11:50:27 -07004278 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004279 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4280 EXPECT_EQ(8000, option_val);
4281}
4282
tommi0f620f42015-07-09 03:25:02 -07004283// Test creating a session, request multiple offers, destroy the session
4284// and make sure we got success/failure callbacks for all of the requests.
4285// Background: crbug.com/507307
4286TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4287 Init();
4288
4289 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4290 PeerConnectionInterface::RTCOfferAnswerOptions options;
4291 options.offer_to_receive_audio =
4292 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004293 cricket::MediaSessionOptions session_options;
4294 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004295
4296 for (auto& o : observers) {
4297 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004298 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004299 }
4300
4301 session_.reset();
4302
tommi0f620f42015-07-09 03:25:02 -07004303 for (auto& o : observers) {
4304 // We expect to have received a notification now even if the session was
4305 // terminated. The offer creation may or may not have succeeded, but we
4306 // must have received a notification which, so the only invalid state
4307 // is kInit.
4308 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4309 }
4310}
4311
stefanc1aeaf02015-10-15 07:26:07 -07004312TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4313 TestPacketOptions();
4314}
4315
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004316// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4317// currently fails because upon disconnection and reconnection OnIceComplete is
4318// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004319
deadbeefcbecd352015-09-23 11:50:27 -07004320INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4321 WebRtcSessionTest,
4322 testing::Values(ALREADY_GENERATED,
4323 DTLS_IDENTITY_STORE));