blob: bf7fc83d0b910d24631ec22048b3004d0a18c478 [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
1960TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001961 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001962 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001964 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 SetLocalDescriptionWithoutError(offer);
1966
1967 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001968 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969 SetLocalDescriptionWithoutError(offer2);
1970}
1971
1972TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001973 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001974 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001976 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 SetRemoteDescriptionWithoutError(offer);
1978
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001979 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 SetRemoteDescriptionWithoutError(offer2);
1981}
1982
1983TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001984 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001985 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001988 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001989 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
1990 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991}
1992
1993TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001994 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001995 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001996 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001999 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002000 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001}
2002
2003TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002004 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002005 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002007 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008
2009 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002010 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002012 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013
deadbeefab9b2d12015-10-14 11:33:11 -07002014 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002016 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2018
deadbeefd59daf82015-10-14 15:02:44 -07002019 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020
deadbeefab9b2d12015-10-14 11:33:11 -07002021 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002022 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002023 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024}
2025
2026TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002027 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002028 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002029 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002030 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031
2032 JsepSessionDescription* pranswer =
2033 CreateRemoteAnswer(session_->local_description());
2034 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2035
2036 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002037 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 JsepSessionDescription* pranswer2 =
2041 CreateRemoteAnswer(session_->local_description());
2042 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2043
2044 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002045 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
deadbeefab9b2d12015-10-14 11:33:11 -07002047 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 SessionDescriptionInterface* answer =
2049 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002050 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051}
2052
2053TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002054 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2057
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 SessionDescriptionInterface* answer =
2059 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002060 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2061 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062}
2063
2064TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002067 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 SessionDescriptionInterface* answer =
2070 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002071 SetRemoteDescriptionAnswerExpectError(
2072 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
2075TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078
2079 cricket::Candidate candidate;
2080 candidate.set_component(1);
2081 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2082
deadbeefd59daf82015-10-14 15:02:44 -07002083 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2085
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002086 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002088
2089 // Fail since we have not set a remote description.
2090 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091
2092 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2093 session_->local_description());
2094 SetRemoteDescriptionWithoutError(answer);
2095
deadbeefd59daf82015-10-14 15:02:44 -07002096 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2097 candidate.set_component(2);
2098 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2099 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2100
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 // Verifying the candidates are copied properly from internal vector.
2102 const SessionDescriptionInterface* remote_desc =
2103 session_->remote_description();
2104 ASSERT_TRUE(remote_desc != NULL);
2105 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2106 const IceCandidateCollection* candidates =
2107 remote_desc->candidates(kMediaContentIndex0);
2108 ASSERT_EQ(2u, candidates->count());
2109 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2110 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2111 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2112 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2113
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002114 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2115 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 candidate.set_component(2);
2117 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2118 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002119 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2122 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2123}
2124
2125// Test that a remote candidate is added to the remote session description and
2126// that it is retained if the remote session description is changed.
2127TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002128 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 cricket::Candidate candidate1;
2130 candidate1.set_component(1);
2131 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2132 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002133 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 CreateAndSetRemoteOfferAndLocalAnswer();
2135
2136 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2137 const SessionDescriptionInterface* remote_desc =
2138 session_->remote_description();
2139 ASSERT_TRUE(remote_desc != NULL);
2140 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2141 const IceCandidateCollection* candidates =
2142 remote_desc->candidates(kMediaContentIndex0);
2143 ASSERT_EQ(1u, candidates->count());
2144 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2145
2146 // Update the RemoteSessionDescription with a new session description and
2147 // a candidate and check that the new remote session description contains both
2148 // candidates.
2149 SessionDescriptionInterface* offer = CreateRemoteOffer();
2150 cricket::Candidate candidate2;
2151 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2152 candidate2);
2153 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2154 SetRemoteDescriptionWithoutError(offer);
2155
2156 remote_desc = session_->remote_description();
2157 ASSERT_TRUE(remote_desc != NULL);
2158 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2159 candidates = remote_desc->candidates(kMediaContentIndex0);
2160 ASSERT_EQ(2u, candidates->count());
2161 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2162 // Username and password have be updated with the TransportInfo of the
2163 // SessionDescription, won't be equal to the original one.
2164 candidate2.set_username(candidates->at(0)->candidate().username());
2165 candidate2.set_password(candidates->at(0)->candidate().password());
2166 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2167 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2168 // No need to verify the username and password.
2169 candidate1.set_username(candidates->at(1)->candidate().username());
2170 candidate1.set_password(candidates->at(1)->candidate().password());
2171 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2172
2173 // Test that the candidate is ignored if we can add the same candidate again.
2174 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2175}
2176
2177// Test that local candidates are added to the local session description and
2178// that they are retained if the local session description is changed.
2179TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002180 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002181 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002182 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 CreateAndSetRemoteOfferAndLocalAnswer();
2184
2185 const SessionDescriptionInterface* local_desc = session_->local_description();
2186 const IceCandidateCollection* candidates =
2187 local_desc->candidates(kMediaContentIndex0);
2188 ASSERT_TRUE(candidates != NULL);
2189 EXPECT_EQ(0u, candidates->count());
2190
2191 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2192
2193 local_desc = session_->local_description();
2194 candidates = local_desc->candidates(kMediaContentIndex0);
2195 ASSERT_TRUE(candidates != NULL);
2196 EXPECT_LT(0u, candidates->count());
2197 candidates = local_desc->candidates(1);
2198 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002199 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200
2201 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002202 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 CreateAndSetRemoteOfferAndLocalAnswer();
2204
2205 local_desc = session_->local_description();
2206 candidates = local_desc->candidates(kMediaContentIndex0);
2207 ASSERT_TRUE(candidates != NULL);
2208 EXPECT_LT(0u, candidates->count());
2209 candidates = local_desc->candidates(1);
2210 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002211 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212}
2213
2214// Test that we can set a remote session description with remote candidates.
2215TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002216 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
2218 cricket::Candidate candidate1;
2219 candidate1.set_component(1);
2220 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2221 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002222 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002223 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224
2225 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2226 SetRemoteDescriptionWithoutError(offer);
2227
2228 const SessionDescriptionInterface* remote_desc =
2229 session_->remote_description();
2230 ASSERT_TRUE(remote_desc != NULL);
2231 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2232 const IceCandidateCollection* candidates =
2233 remote_desc->candidates(kMediaContentIndex0);
2234 ASSERT_EQ(1u, candidates->count());
2235 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2236
wu@webrtc.org91053e72013-08-10 07:18:04 +00002237 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 SetLocalDescriptionWithoutError(answer);
2239}
2240
2241// Test that offers and answers contains ice candidates when Ice candidates have
2242// been gathered.
2243TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002244 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002245 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002246 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 // Ice is started but candidates are not provided until SetLocalDescription
2248 // is called.
2249 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2250 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2251 CreateAndSetRemoteOfferAndLocalAnswer();
2252 // Wait until at least one local candidate has been collected.
2253 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2254 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002256 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2257
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2259 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260
2261 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2262 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002263 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2265 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 SetLocalDescriptionWithoutError(answer);
2267}
2268
2269// Verifies TransportProxy and media channels are created with content names
2270// present in the SessionDescription.
2271TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002272 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002273 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002274 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275
2276 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002277 // "video". Goal is to modify these content names and verify transport
2278 // channels
2279 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 // present in SDP.
2281 std::string sdp;
2282 EXPECT_TRUE(offer->ToString(&sdp));
2283 const std::string kAudioMid = "a=mid:audio";
2284 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2285 const std::string kVideoMid = "a=mid:video";
2286 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2287
2288 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002289 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 kAudioMidReplaceStr.c_str(),
2291 kAudioMidReplaceStr.length(),
2292 &sdp);
2293 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002294 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 kVideoMidReplaceStr.c_str(),
2296 kVideoMidReplaceStr.length(),
2297 &sdp);
2298
2299 SessionDescriptionInterface* modified_offer =
2300 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2301
2302 SetRemoteDescriptionWithoutError(modified_offer);
2303
2304 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002305 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 SetLocalDescriptionWithoutError(answer);
2307
deadbeefcbecd352015-09-23 11:50:27 -07002308 cricket::TransportChannel* voice_transport_channel =
2309 session_->voice_rtp_transport_channel();
2310 EXPECT_TRUE(voice_transport_channel != NULL);
2311 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2312 cricket::TransportChannel* video_transport_channel =
2313 session_->video_rtp_transport_channel();
2314 EXPECT_TRUE(video_transport_channel != NULL);
2315 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2317 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2318}
2319
2320// Test that an offer contains the correct media content descriptions based on
2321// the send streams when no constraints have been set.
2322TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002323 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002324 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 ASSERT_TRUE(offer != NULL);
2327 const cricket::ContentInfo* content =
2328 cricket::GetFirstAudioContent(offer->description());
2329 EXPECT_TRUE(content != NULL);
2330 content = cricket::GetFirstVideoContent(offer->description());
2331 EXPECT_TRUE(content == NULL);
2332}
2333
2334// Test that an offer contains the correct media content descriptions based on
2335// the send streams when no constraints have been set.
2336TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002337 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002339 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002340 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2341
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 const cricket::ContentInfo* content =
2343 cricket::GetFirstAudioContent(offer->description());
2344 EXPECT_TRUE(content != NULL);
2345 content = cricket::GetFirstVideoContent(offer->description());
2346 EXPECT_TRUE(content == NULL);
2347
2348 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002349 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002350 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 content = cricket::GetFirstAudioContent(offer->description());
2352 EXPECT_TRUE(content != NULL);
2353 content = cricket::GetFirstVideoContent(offer->description());
2354 EXPECT_TRUE(content != NULL);
2355}
2356
2357// Test that an offer contains no media content descriptions if
2358// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2359TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002360 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002361 PeerConnectionInterface::RTCOfferAnswerOptions options;
2362 options.offer_to_receive_audio = 0;
2363 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002365 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002366 CreateOffer(options));
2367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 ASSERT_TRUE(offer != NULL);
2369 const cricket::ContentInfo* content =
2370 cricket::GetFirstAudioContent(offer->description());
2371 EXPECT_TRUE(content == NULL);
2372 content = cricket::GetFirstVideoContent(offer->description());
2373 EXPECT_TRUE(content == NULL);
2374}
2375
2376// Test that an offer contains only audio media content descriptions if
2377// kOfferToReceiveAudio constraints are set to true.
2378TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002379 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002380 PeerConnectionInterface::RTCOfferAnswerOptions options;
2381 options.offer_to_receive_audio =
2382 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2383
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002384 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002385 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386
2387 const cricket::ContentInfo* content =
2388 cricket::GetFirstAudioContent(offer->description());
2389 EXPECT_TRUE(content != NULL);
2390 content = cricket::GetFirstVideoContent(offer->description());
2391 EXPECT_TRUE(content == NULL);
2392}
2393
2394// Test that an offer contains audio and video media content descriptions if
2395// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2396TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002397 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002399 PeerConnectionInterface::RTCOfferAnswerOptions options;
2400 options.offer_to_receive_audio =
2401 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2402 options.offer_to_receive_video =
2403 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2404
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002405 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002406 CreateOffer(options));
2407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 const cricket::ContentInfo* content =
2409 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002410 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002411
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 content = cricket::GetFirstVideoContent(offer->description());
2413 EXPECT_TRUE(content != NULL);
2414
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002415 // Sets constraints to false and verifies that audio/video contents are
2416 // removed.
2417 options.offer_to_receive_audio = 0;
2418 options.offer_to_receive_video = 0;
2419 offer.reset(CreateOffer(options));
2420
2421 content = cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content == NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425}
2426
2427// Test that an answer can not be created if the last remote description is not
2428// an offer.
2429TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002431 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 SetLocalDescriptionWithoutError(offer);
2433 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2434 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002435 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436}
2437
2438// Test that an answer contains the correct media content descriptions when no
2439// constraints have been set.
2440TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002441 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002443 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002445 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002446 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 const cricket::ContentInfo* content =
2448 cricket::GetFirstAudioContent(answer->description());
2449 ASSERT_TRUE(content != NULL);
2450 EXPECT_FALSE(content->rejected);
2451
2452 content = cricket::GetFirstVideoContent(answer->description());
2453 ASSERT_TRUE(content != NULL);
2454 EXPECT_FALSE(content->rejected);
2455}
2456
2457// Test that an answer contains the correct media content descriptions when no
2458// constraints have been set and the offer only contain audio.
2459TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002460 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 // Create a remote offer with audio only.
2462 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002463
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002464 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 CreateRemoteOffer(options));
2466 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2467 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2468
2469 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002470 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002471 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 const cricket::ContentInfo* content =
2473 cricket::GetFirstAudioContent(answer->description());
2474 ASSERT_TRUE(content != NULL);
2475 EXPECT_FALSE(content->rejected);
2476
2477 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2478}
2479
2480// Test that an answer contains the correct media content descriptions when no
2481// constraints have been set.
2482TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002483 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002485 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 SetRemoteDescriptionWithoutError(offer.release());
2487 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002488 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002489 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002490 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 const cricket::ContentInfo* content =
2492 cricket::GetFirstAudioContent(answer->description());
2493 ASSERT_TRUE(content != NULL);
2494 EXPECT_FALSE(content->rejected);
2495
2496 content = cricket::GetFirstVideoContent(answer->description());
2497 ASSERT_TRUE(content != NULL);
2498 EXPECT_FALSE(content->rejected);
2499}
2500
2501// Test that an answer contains the correct media content descriptions when
2502// constraints have been set but no stream is sent.
2503TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002504 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002506 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 SetRemoteDescriptionWithoutError(offer.release());
2508
2509 webrtc::FakeConstraints constraints_no_receive;
2510 constraints_no_receive.SetMandatoryReceiveAudio(false);
2511 constraints_no_receive.SetMandatoryReceiveVideo(false);
2512
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002513 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002514 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 const cricket::ContentInfo* content =
2516 cricket::GetFirstAudioContent(answer->description());
2517 ASSERT_TRUE(content != NULL);
2518 EXPECT_TRUE(content->rejected);
2519
2520 content = cricket::GetFirstVideoContent(answer->description());
2521 ASSERT_TRUE(content != NULL);
2522 EXPECT_TRUE(content->rejected);
2523}
2524
2525// Test that an answer contains the correct media content descriptions when
2526// constraints have been set and streams are sent.
2527TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002528 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002530 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 SetRemoteDescriptionWithoutError(offer.release());
2532
2533 webrtc::FakeConstraints constraints_no_receive;
2534 constraints_no_receive.SetMandatoryReceiveAudio(false);
2535 constraints_no_receive.SetMandatoryReceiveVideo(false);
2536
2537 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002538 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002539 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002540 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541
2542 // TODO(perkj): Should the direction be set to SEND_ONLY?
2543 const cricket::ContentInfo* content =
2544 cricket::GetFirstAudioContent(answer->description());
2545 ASSERT_TRUE(content != NULL);
2546 EXPECT_FALSE(content->rejected);
2547
2548 // TODO(perkj): Should the direction be set to SEND_ONLY?
2549 content = cricket::GetFirstVideoContent(answer->description());
2550 ASSERT_TRUE(content != NULL);
2551 EXPECT_FALSE(content->rejected);
2552}
2553
2554TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2555 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002556 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002557 PeerConnectionInterface::RTCOfferAnswerOptions options;
2558 options.offer_to_receive_audio =
2559 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2560 options.voice_activity_detection = false;
2561
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002562 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002563 CreateOffer(options));
2564
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 const cricket::ContentInfo* content =
2566 cricket::GetFirstAudioContent(offer->description());
2567 EXPECT_TRUE(content != NULL);
2568 EXPECT_TRUE(VerifyNoCNCodecs(content));
2569}
2570
2571TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2572 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002573 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002575 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 SetRemoteDescriptionWithoutError(offer.release());
2577
2578 webrtc::FakeConstraints constraints;
2579 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002581 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 const cricket::ContentInfo* content =
2583 cricket::GetFirstAudioContent(answer->description());
2584 ASSERT_TRUE(content != NULL);
2585 EXPECT_TRUE(VerifyNoCNCodecs(content));
2586}
2587
2588// This test verifies the call setup when remote answer with audio only and
2589// later updates with video.
2590TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002591 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2593 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2594
deadbeefab9b2d12015-10-14 11:33:11 -07002595 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002596 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597
2598 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2600
2601 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2602 // and answer;
2603 SetLocalDescriptionWithoutError(offer);
2604 SetRemoteDescriptionWithoutError(answer);
2605
2606 video_channel_ = media_engine_->GetVideoChannel(0);
2607 voice_channel_ = media_engine_->GetVoiceChannel(0);
2608
2609 ASSERT_TRUE(video_channel_ == NULL);
2610
2611 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2612 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2613 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2614
2615 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002616 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617 CreateAndSetRemoteOfferAndLocalAnswer();
2618
2619 video_channel_ = media_engine_->GetVideoChannel(0);
2620 voice_channel_ = media_engine_->GetVoiceChannel(0);
2621
2622 ASSERT_TRUE(video_channel_ != NULL);
2623 ASSERT_TRUE(voice_channel_ != NULL);
2624
2625 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2626 ASSERT_EQ(1u, video_channel_->send_streams().size());
2627 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2628 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2629 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2630 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2631 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2632 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2633
2634 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002635 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 CreateAndSetRemoteOfferAndLocalAnswer();
2637
2638 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2639 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2640 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2641 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2642 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2643}
2644
2645// This test verifies the call setup when remote answer with video only and
2646// later updates with audio.
2647TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002648 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2650 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002651 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653
2654 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002655 options.recv_audio = false;
2656 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2658 offer, options, cricket::SEC_ENABLED);
2659
2660 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2661 // and answer.
2662 SetLocalDescriptionWithoutError(offer);
2663 SetRemoteDescriptionWithoutError(answer);
2664
2665 video_channel_ = media_engine_->GetVideoChannel(0);
2666 voice_channel_ = media_engine_->GetVoiceChannel(0);
2667
2668 ASSERT_TRUE(voice_channel_ == NULL);
2669 ASSERT_TRUE(video_channel_ != NULL);
2670
2671 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2672 ASSERT_EQ(1u, video_channel_->send_streams().size());
2673 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2674
2675 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002676 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677 CreateAndSetRemoteOfferAndLocalAnswer();
2678
2679 voice_channel_ = media_engine_->GetVoiceChannel(0);
2680 ASSERT_TRUE(voice_channel_ != NULL);
2681
2682 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2683 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2684 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2685 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2686
2687 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002688 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 CreateAndSetRemoteOfferAndLocalAnswer();
2690
2691 video_channel_ = media_engine_->GetVideoChannel(0);
2692 voice_channel_ = media_engine_->GetVoiceChannel(0);
2693
2694 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2695 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2696 ASSERT_EQ(1u, video_channel_->send_streams().size());
2697 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2698}
2699
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002701 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002702 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002703 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 VerifyCryptoParams(offer->description());
2705 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002706 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 VerifyCryptoParams(answer->description());
2708}
2709
2710TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002711 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002712 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002713 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002714 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 VerifyNoCryptoParams(offer->description(), false);
2716}
2717
2718TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002719 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 VerifyAnswerFromNonCryptoOffer();
2721}
2722
2723TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002724 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 VerifyAnswerFromCryptoOffer();
2726}
2727
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002728// This test verifies that setLocalDescription fails if
2729// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2730TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002731 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002732 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002733 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2734
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002735 std::string sdp;
2736 RemoveIceUfragPwdLines(offer.get(), &sdp);
2737 SessionDescriptionInterface* modified_offer =
2738 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002739 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002740}
2741
2742// This test verifies that setRemoteDescription fails if
2743// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2744TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002745 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002746 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002747 std::string sdp;
2748 RemoveIceUfragPwdLines(offer.get(), &sdp);
2749 SessionDescriptionInterface* modified_offer =
2750 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002751 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002752}
2753
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002754// This test verifies that setLocalDescription fails if local offer has
2755// too short ice ufrag and pwd strings.
2756TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002757 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002758 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002759 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2760
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002761 std::string sdp;
2762 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2763 // recommended values of 4 and 22 bytes respectively.
2764 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2765 SessionDescriptionInterface* modified_offer =
2766 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2767 std::string error;
2768 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2769
2770 // Test with string greater than 256.
2771 sdp.clear();
2772 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2773 &sdp);
2774 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2775 NULL);
2776 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2777}
2778
2779// This test verifies that setRemoteDescription fails if remote offer has
2780// too short ice ufrag and pwd strings.
2781TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002782 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002783 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002784 std::string sdp;
2785 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2786 // recommended values of 4 and 22 bytes respectively.
2787 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2788 SessionDescriptionInterface* modified_offer =
2789 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2790 std::string error;
2791 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2792
2793 sdp.clear();
2794 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2795 &sdp);
2796 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2797 NULL);
2798 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2799}
2800
Honghai Zhang04e91462015-12-11 14:26:22 -08002801// Test that if the remote offer indicates the peer requested ICE restart (via
2802// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2803TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002804 Init();
2805 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2806
2807 // Create the first offer.
2808 std::string sdp;
2809 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2810 "abcdefghijklmnopqrstuvwx", &sdp);
2811 SessionDescriptionInterface* offer1 =
2812 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2813 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2814 0, "", "", "relay", 0, "");
2815 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2816 candidate1);
2817 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2818 SetRemoteDescriptionWithoutError(offer1);
2819 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2820
2821 // The second offer has the same ufrag and pwd but different address.
2822 sdp.clear();
2823 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2824 "abcdefghijklmnopqrstuvwx", &sdp);
2825 SessionDescriptionInterface* offer2 =
2826 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2827 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2828 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2829 candidate1);
2830 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2831 SetRemoteDescriptionWithoutError(offer2);
2832 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2833
2834 // The third offer has a different ufrag and different address.
2835 sdp.clear();
2836 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2837 "abcdefghijklmnopqrstuvwx", &sdp);
2838 SessionDescriptionInterface* offer3 =
2839 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2840 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2841 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2842 candidate1);
2843 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2844 SetRemoteDescriptionWithoutError(offer3);
2845 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2846
2847 // The fourth offer has no candidate but a different ufrag/pwd.
2848 sdp.clear();
2849 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2850 "abcdefghijklmnopqrstuvyz", &sdp);
2851 SessionDescriptionInterface* offer4 =
2852 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2853 SetRemoteDescriptionWithoutError(offer4);
2854 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2855}
2856
Honghai Zhang04e91462015-12-11 14:26:22 -08002857// Test that if the remote answer indicates the peer requested ICE restart (via
2858// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2859TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2860 Init();
2861 SessionDescriptionInterface* offer = CreateOffer();
2862 SetLocalDescriptionWithoutError(offer);
2863 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2864
2865 // Create the first answer.
2866 std::string sdp;
2867 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2868 "abcdefghijklmnopqrstuvwx", &sdp);
2869 SessionDescriptionInterface* answer1 =
2870 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2871 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2872 0, "", "", "relay", 0, "");
2873 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2874 candidate1);
2875 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2876 SetRemoteDescriptionWithoutError(answer1);
2877 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2878
2879 // The second answer has the same ufrag and pwd but different address.
2880 sdp.clear();
2881 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2882 "abcdefghijklmnopqrstuvwx", &sdp);
2883 SessionDescriptionInterface* answer2 =
2884 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2885 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2886 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2887 candidate1);
2888 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2889 SetRemoteDescriptionWithoutError(answer2);
2890 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2891
2892 // The third answer has a different ufrag and different address.
2893 sdp.clear();
2894 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2895 "abcdefghijklmnopqrstuvwx", &sdp);
2896 SessionDescriptionInterface* answer3 =
2897 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2898 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2899 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2900 candidate1);
2901 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2902 SetRemoteDescriptionWithoutError(answer3);
2903 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2904
2905 // The fourth answer has no candidate but a different ufrag/pwd.
2906 sdp.clear();
2907 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2908 "abcdefghijklmnopqrstuvyz", &sdp);
2909 SessionDescriptionInterface* offer4 =
2910 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2911 SetRemoteDescriptionWithoutError(offer4);
2912 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2913}
2914
Donald Curtisd4f769d2015-05-28 09:48:21 -07002915// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002916// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002917TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2918 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2919
2920 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002921 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002922
2923 PeerConnectionInterface::RTCOfferAnswerOptions options;
2924 options.use_rtp_mux = true;
2925
2926 SessionDescriptionInterface* offer = CreateRemoteOffer();
2927 SetRemoteDescriptionWithoutError(offer);
2928
2929 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2930 SetLocalDescriptionWithoutError(answer);
2931
deadbeefcbecd352015-09-23 11:50:27 -07002932 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2933 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002934
deadbeefcbecd352015-09-23 11:50:27 -07002935 cricket::BaseChannel* voice_channel = session_->voice_channel();
2936 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002937
2938 // Checks if one of the transport channels contains a connection using a given
2939 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002940 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002941 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002942 session_->GetChannelTransportStats(voice_channel, &stats);
2943 for (auto& kv : stats.transport_stats) {
2944 for (auto& chan_stat : kv.second.channel_stats) {
2945 for (auto& conn_info : chan_stat.connection_infos) {
2946 if (conn_info.remote_candidate.address().port() == port) {
2947 return true;
2948 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002949 }
2950 }
2951 }
2952 return false;
2953 };
2954
2955 EXPECT_FALSE(connection_with_remote_port(5000));
2956 EXPECT_FALSE(connection_with_remote_port(5001));
2957 EXPECT_FALSE(connection_with_remote_port(6000));
2958
2959 // The way the *_WAIT checks work is they only wait if the condition fails,
2960 // which does not help in the case where state is not changing. This is
2961 // problematic in this test since we want to verify that adding a video
2962 // candidate does _not_ change state. So we interleave candidates and assume
2963 // that messages are executed in the order they were posted.
2964
2965 // First audio candidate.
2966 cricket::Candidate candidate0;
2967 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2968 candidate0.set_component(1);
2969 candidate0.set_protocol("udp");
2970 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2971 candidate0);
2972 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2973
2974 // Video candidate.
2975 cricket::Candidate candidate1;
2976 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2977 candidate1.set_component(1);
2978 candidate1.set_protocol("udp");
2979 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2980 candidate1);
2981 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2982
2983 // Second audio candidate.
2984 cricket::Candidate candidate2;
2985 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2986 candidate2.set_component(1);
2987 candidate2.set_protocol("udp");
2988 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2989 candidate2);
2990 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2991
2992 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2993 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2994
2995 // No need here for a _WAIT check since we are checking that state hasn't
2996 // changed: if this is false we would be doing waits for nothing and if this
2997 // is true then there will be no messages processed anyways.
2998 EXPECT_FALSE(connection_with_remote_port(6000));
2999}
3000
deadbeefcbecd352015-09-23 11:50:27 -07003001// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003002TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3003 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003004 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003005
3006 PeerConnectionInterface::RTCOfferAnswerOptions options;
3007 options.use_rtp_mux = true;
3008
3009 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003011
deadbeefcbecd352015-09-23 11:50:27 -07003012 EXPECT_NE(session_->voice_rtp_transport_channel(),
3013 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003014
deadbeefab9b2d12015-10-14 11:33:11 -07003015 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003016 SessionDescriptionInterface* answer =
3017 CreateRemoteAnswer(session_->local_description());
3018 SetRemoteDescriptionWithoutError(answer);
3019
deadbeefcbecd352015-09-23 11:50:27 -07003020 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3021 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003022}
3023
deadbeefcbecd352015-09-23 11:50:27 -07003024// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003025TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3026 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003027 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003028
Donald Curtis0e209b02015-03-24 09:29:54 -07003029 PeerConnectionInterface::RTCOfferAnswerOptions options;
3030 options.use_rtp_mux = true;
3031
3032 SessionDescriptionInterface* offer = CreateOffer(options);
3033 SetLocalDescriptionWithoutError(offer);
3034
deadbeefcbecd352015-09-23 11:50:27 -07003035 EXPECT_NE(session_->voice_rtp_transport_channel(),
3036 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003037
deadbeefab9b2d12015-10-14 11:33:11 -07003038 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003039
3040 // Remove BUNDLE from the answer.
3041 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3042 CreateRemoteAnswer(session_->local_description()));
3043 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3044 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3045 JsepSessionDescription* modified_answer =
3046 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3047 modified_answer->Initialize(answer_copy, "1", "1");
3048 SetRemoteDescriptionWithoutError(modified_answer); //
3049
deadbeefcbecd352015-09-23 11:50:27 -07003050 EXPECT_NE(session_->voice_rtp_transport_channel(),
3051 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003052}
3053
3054// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3055TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3056 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003057 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003058
3059 PeerConnectionInterface::RTCOfferAnswerOptions options;
3060 options.use_rtp_mux = true;
3061
3062 SessionDescriptionInterface* offer = CreateOffer(options);
3063 SetLocalDescriptionWithoutError(offer);
3064
deadbeefcbecd352015-09-23 11:50:27 -07003065 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3066 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003067
deadbeefab9b2d12015-10-14 11:33:11 -07003068 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003069 SessionDescriptionInterface* answer =
3070 CreateRemoteAnswer(session_->local_description());
3071 SetRemoteDescriptionWithoutError(answer);
3072
deadbeefcbecd352015-09-23 11:50:27 -07003073 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3074 session_->video_rtp_transport_channel());
3075}
3076
3077// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3078// audio content in the answer.
3079TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3080 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003081 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003082
3083 PeerConnectionInterface::RTCOfferAnswerOptions options;
3084 options.use_rtp_mux = true;
3085
3086 SessionDescriptionInterface* offer = CreateOffer(options);
3087 SetLocalDescriptionWithoutError(offer);
3088
3089 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3090 session_->video_rtp_transport_channel());
3091
deadbeefab9b2d12015-10-14 11:33:11 -07003092 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003093 cricket::MediaSessionOptions recv_options;
3094 recv_options.recv_audio = false;
3095 recv_options.recv_video = true;
3096 SessionDescriptionInterface* answer =
3097 CreateRemoteAnswer(session_->local_description(), recv_options);
3098 SetRemoteDescriptionWithoutError(answer);
3099
deadbeefd59daf82015-10-14 15:02:44 -07003100 EXPECT_TRUE(nullptr == session_->voice_channel());
3101 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003102
deadbeefd59daf82015-10-14 15:02:44 -07003103 session_->Close();
3104 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3105 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3106 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3107 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003108}
3109
3110// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3111TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3112 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003113 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003114
Donald Curtis0e209b02015-03-24 09:29:54 -07003115 PeerConnectionInterface::RTCOfferAnswerOptions options;
3116 options.use_rtp_mux = true;
3117
3118 SessionDescriptionInterface* offer = CreateOffer(options);
3119 SetLocalDescriptionWithoutError(offer);
3120
deadbeefcbecd352015-09-23 11:50:27 -07003121 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3122 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003123
deadbeefab9b2d12015-10-14 11:33:11 -07003124 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003125
3126 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003127 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128 CreateRemoteAnswer(session_->local_description()));
3129 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3130 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3131 JsepSessionDescription* modified_answer =
3132 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3133 modified_answer->Initialize(answer_copy, "1", "1");
3134 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135
deadbeefcbecd352015-09-23 11:50:27 -07003136 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3137 session_->video_rtp_transport_channel());
3138}
3139
3140// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3141TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3142 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003143 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003144
3145 SessionDescriptionInterface* offer = CreateRemoteOffer();
3146 SetRemoteDescriptionWithoutError(offer);
3147
3148 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3149 session_->video_rtp_transport_channel());
3150
deadbeefab9b2d12015-10-14 11:33:11 -07003151 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003152 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3153 SetLocalDescriptionWithoutError(answer);
3154
3155 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3156 session_->video_rtp_transport_channel());
3157}
3158
3159// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3160TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3161 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003162 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003163
3164 // Remove BUNDLE from the offer.
3165 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3166 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3167 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3168 JsepSessionDescription* modified_offer =
3169 new JsepSessionDescription(JsepSessionDescription::kOffer);
3170 modified_offer->Initialize(offer_copy, "1", "1");
3171
3172 // Expect an error when applying the remote description
3173 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3174 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003175}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176
Peter Thatcher4eddf182015-04-30 10:55:59 -07003177// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003178TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3179 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003180 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181
Donald Curtis0e209b02015-03-24 09:29:54 -07003182 PeerConnectionInterface::RTCOfferAnswerOptions options;
3183 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184
Donald Curtis0e209b02015-03-24 09:29:54 -07003185 SessionDescriptionInterface* offer = CreateOffer(options);
3186 SetLocalDescriptionWithoutError(offer);
3187
deadbeefcbecd352015-09-23 11:50:27 -07003188 EXPECT_NE(session_->voice_rtp_transport_channel(),
3189 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003190
deadbeefab9b2d12015-10-14 11:33:11 -07003191 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003192 SessionDescriptionInterface* answer =
3193 CreateRemoteAnswer(session_->local_description());
3194 SetRemoteDescriptionWithoutError(answer);
3195
3196 // This should lead to an audio-only call but isn't implemented
3197 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003198 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3199 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003200}
3201
deadbeefcbecd352015-09-23 11:50:27 -07003202// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003203TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3204 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003205 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003206 PeerConnectionInterface::RTCOfferAnswerOptions options;
3207 options.use_rtp_mux = true;
3208
3209 SessionDescriptionInterface* offer = CreateOffer(options);
3210 SetLocalDescriptionWithoutError(offer);
3211
deadbeefcbecd352015-09-23 11:50:27 -07003212 EXPECT_NE(session_->voice_rtp_transport_channel(),
3213 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003214
deadbeefab9b2d12015-10-14 11:33:11 -07003215 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003216
3217 // Remove BUNDLE from the answer.
3218 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3219 CreateRemoteAnswer(session_->local_description()));
3220 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3221 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3222 JsepSessionDescription* modified_answer =
3223 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3224 modified_answer->Initialize(answer_copy, "1", "1");
3225 SetRemoteDescriptionWithoutError(modified_answer); //
3226
deadbeefcbecd352015-09-23 11:50:27 -07003227 EXPECT_NE(session_->voice_rtp_transport_channel(),
3228 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229}
3230
Peter Thatcher4eddf182015-04-30 10:55:59 -07003231// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3232TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3233 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003235
3236 PeerConnectionInterface::RTCOfferAnswerOptions options;
3237 options.use_rtp_mux = true;
3238
3239 SessionDescriptionInterface* offer = CreateOffer(options);
3240 SetRemoteDescriptionWithoutError(offer);
3241
deadbeefcbecd352015-09-23 11:50:27 -07003242 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3243 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003244}
3245
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003246TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3247 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003248 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003249
3250 PeerConnectionInterface::RTCOfferAnswerOptions options;
3251 SessionDescriptionInterface* offer = CreateOffer(options);
3252 SetLocalDescriptionWithoutError(offer);
3253
deadbeefcbecd352015-09-23 11:50:27 -07003254 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3255 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003256
deadbeefab9b2d12015-10-14 11:33:11 -07003257 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003258 SessionDescriptionInterface* answer =
3259 CreateRemoteAnswer(session_->local_description());
3260 SetRemoteDescriptionWithoutError(answer);
3261
deadbeefcbecd352015-09-23 11:50:27 -07003262 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3263 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003264}
3265
3266TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3267 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003268 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003269
3270 PeerConnectionInterface::RTCOfferAnswerOptions options;
3271 SessionDescriptionInterface* offer = CreateOffer(options);
3272 SetLocalDescriptionWithoutError(offer);
3273
deadbeefcbecd352015-09-23 11:50:27 -07003274 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3275 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003276
deadbeefab9b2d12015-10-14 11:33:11 -07003277 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003278 SessionDescriptionInterface* answer =
3279 CreateRemoteAnswer(session_->local_description());
3280 SetRemoteDescriptionWithoutError(answer);
3281
deadbeefcbecd352015-09-23 11:50:27 -07003282 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3283 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003284}
3285
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003286// This test verifies that SetLocalDescription and SetRemoteDescription fails
3287// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3288TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003289 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003291
3292 PeerConnectionInterface::RTCOfferAnswerOptions options;
3293 options.use_rtp_mux = true;
3294
3295 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003296 std::string offer_str;
3297 offer->ToString(&offer_str);
3298 // Disable rtcp-mux
3299 const std::string rtcp_mux = "rtcp-mux";
3300 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003301 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003302 xrtcp_mux.c_str(), xrtcp_mux.length(),
3303 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003304 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003305 new JsepSessionDescription(JsepSessionDescription::kOffer);
3306 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003307 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003308 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003309 new JsepSessionDescription(JsepSessionDescription::kOffer);
3310 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003311 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003312 // Trying unmodified SDP.
3313 SetLocalDescriptionWithoutError(offer);
3314}
3315
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003316TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003317 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003318 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319 CreateAndSetRemoteOfferAndLocalAnswer();
3320 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3321 ASSERT_TRUE(channel != NULL);
3322 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003323 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003324 double volume;
3325 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3326 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003327 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003328 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3329 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003330 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003331 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3332 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333}
3334
3335TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003336 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003337 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 CreateAndSetRemoteOfferAndLocalAnswer();
3339 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3340 ASSERT_TRUE(channel != NULL);
3341 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003342 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3344
3345 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003346 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003348 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003349 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003351 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003352 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003354 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003355 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003357 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003358 EXPECT_TRUE(renderer->sink() == NULL);
3359}
3360
3361TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003362 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003363 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003364 CreateAndSetRemoteOfferAndLocalAnswer();
3365 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3366 ASSERT_TRUE(channel != NULL);
3367 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003368 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003369
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003370 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003371 cricket::AudioOptions options;
3372 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3373 EXPECT_TRUE(renderer->sink() != NULL);
3374
3375 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3376 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3377 // SetSink(NULL) callback afterwards.
3378 renderer.reset();
3379
3380 // This will trigger SetSink(NULL) if no OnClose() callback.
3381 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382}
3383
3384TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003385 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003386 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 CreateAndSetRemoteOfferAndLocalAnswer();
3388 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3389 ASSERT_TRUE(channel != NULL);
3390 ASSERT_LT(0u, channel->renderers().size());
3391 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3392 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003393 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 cricket::FakeVideoRenderer renderer;
3395 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3396 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3397 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3398 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3399}
3400
3401TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003402 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003403 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 CreateAndSetRemoteOfferAndLocalAnswer();
3405 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3406 ASSERT_TRUE(channel != NULL);
3407 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003408 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3410 cricket::VideoOptions* options = NULL;
3411 session_->SetVideoSend(send_ssrc, false, options);
3412 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3413 session_->SetVideoSend(send_ssrc, true, options);
3414 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3415}
3416
3417TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3418 TestCanInsertDtmf(false);
3419}
3420
3421TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3422 TestCanInsertDtmf(true);
3423}
3424
3425TEST_F(WebRtcSessionTest, InsertDtmf) {
3426 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003427 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003428 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 CreateAndSetRemoteOfferAndLocalAnswer();
3430 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3431 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3432
3433 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 const int expected_duration = 90;
3435 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3436 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3437 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3438
3439 // Verify
3440 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003441 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003443 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003445 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003447 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448}
3449
deadbeefd59daf82015-10-14 15:02:44 -07003450// This test verifies the |initial_offerer| flag when session initiates the
3451// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003453 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003454 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003455 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3457 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003458 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003460 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461}
3462
deadbeefd59daf82015-10-14 15:02:44 -07003463// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003465 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003466 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467 SessionDescriptionInterface* offer = CreateRemoteOffer();
3468 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003469 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470
deadbeefd59daf82015-10-14 15:02:44 -07003471 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003473 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474}
3475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3477TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003478 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003479 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003480 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003482 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483 CreateRemoteAnswer(session_->local_description()));
3484
3485 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3486 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003487 JsepSessionDescription* modified_answer =
3488 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489
3490 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3491 answer->session_id(),
3492 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003493 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494
wu@webrtc.org4e393072014-04-07 17:04:35 +00003495 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496 std::string sdp;
3497 EXPECT_TRUE(answer->ToString(&sdp));
3498 const std::string kAudioMid = "a=mid:audio";
3499 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003500 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 kAudioMidReplaceStr.c_str(),
3502 kAudioMidReplaceStr.length(),
3503 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003504 SessionDescriptionInterface* modified_answer1 =
3505 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003506 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507
wu@webrtc.org4e393072014-04-07 17:04:35 +00003508 // Different media types.
3509 EXPECT_TRUE(answer->ToString(&sdp));
3510 const std::string kAudioMline = "m=audio";
3511 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003512 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003513 kAudioMlineReplaceStr.c_str(),
3514 kAudioMlineReplaceStr.length(),
3515 &sdp);
3516 SessionDescriptionInterface* modified_answer2 =
3517 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3518 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3519
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 SetRemoteDescriptionWithoutError(answer.release());
3521}
3522
3523// Verifying remote offer and local answer have matching m-lines as per
3524// RFC 3264.
3525TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003526 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003527 SendAudioVideoStream1();
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
3532 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3533 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003534 JsepSessionDescription* modified_answer =
3535 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536
3537 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3538 answer->session_id(),
3539 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003540 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541 SetLocalDescriptionWithoutError(answer);
3542}
3543
3544// This test verifies that WebRtcSession does not start candidate allocation
3545// before SetLocalDescription is called.
3546TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003547 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003548 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 SessionDescriptionInterface* offer = CreateRemoteOffer();
3550 cricket::Candidate candidate;
3551 candidate.set_component(1);
3552 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3553 candidate);
3554 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3555 cricket::Candidate candidate1;
3556 candidate1.set_component(1);
3557 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3558 candidate1);
3559 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3560 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003561 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3562 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563
3564 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003565 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3567 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3568
wu@webrtc.org91053e72013-08-10 07:18:04 +00003569 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3572}
3573
3574// This test verifies that crypto parameter is updated in local session
3575// description as per security policy set in MediaSessionDescriptionFactory.
3576TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003577 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003578 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003579 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
3581 // Making sure SetLocalDescription correctly sets crypto value in
3582 // SessionDescription object after de-serialization of sdp string. The value
3583 // will be set as per MediaSessionDescriptionFactory.
3584 std::string offer_str;
3585 offer->ToString(&offer_str);
3586 SessionDescriptionInterface* jsep_offer_str =
3587 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3588 SetLocalDescriptionWithoutError(jsep_offer_str);
3589 EXPECT_TRUE(session_->voice_channel()->secure_required());
3590 EXPECT_TRUE(session_->video_channel()->secure_required());
3591}
3592
3593// This test verifies the crypto parameter when security is disabled.
3594TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003595 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003596 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003597 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003598 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599
3600 // Making sure SetLocalDescription correctly sets crypto value in
3601 // SessionDescription object after de-serialization of sdp string. The value
3602 // will be set as per MediaSessionDescriptionFactory.
3603 std::string offer_str;
3604 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003605 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3607 SetLocalDescriptionWithoutError(jsep_offer_str);
3608 EXPECT_FALSE(session_->voice_channel()->secure_required());
3609 EXPECT_FALSE(session_->video_channel()->secure_required());
3610}
3611
3612// This test verifies that an answer contains new ufrag and password if an offer
3613// with new ufrag and password is received.
3614TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003615 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003617 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003618 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619 CreateRemoteOffer(options));
3620 SetRemoteDescriptionWithoutError(offer.release());
3621
deadbeefab9b2d12015-10-14 11:33:11 -07003622 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003623 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003624 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 SetLocalDescriptionWithoutError(answer.release());
3626
3627 // Receive an offer with new ufrag and password.
3628 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003629 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003630 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631 SetRemoteDescriptionWithoutError(updated_offer1.release());
3632
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003633 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003634 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635
3636 CompareIceUfragAndPassword(updated_answer1->description(),
3637 session_->local_description()->description(),
3638 false);
3639
3640 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003641}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642
wu@webrtc.org91053e72013-08-10 07:18:04 +00003643// This test verifies that an answer contains old ufrag and password if an offer
3644// with old ufrag and password is received.
3645TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003646 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003647 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003648 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003649 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003650 CreateRemoteOffer(options));
3651 SetRemoteDescriptionWithoutError(offer.release());
3652
deadbeefab9b2d12015-10-14 11:33:11 -07003653 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003654 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003655 CreateAnswer(NULL));
3656 SetLocalDescriptionWithoutError(answer.release());
3657
3658 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003660 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003661 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003662 SetRemoteDescriptionWithoutError(updated_offer2.release());
3663
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003664 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003665 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666
3667 CompareIceUfragAndPassword(updated_answer2->description(),
3668 session_->local_description()->description(),
3669 true);
3670
3671 SetLocalDescriptionWithoutError(updated_answer2.release());
3672}
3673
3674TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003675 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003676 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003677 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003678 const std::string session_id_orig = offer->session_id();
3679 const std::string session_version_orig = offer->session_version();
3680 SetLocalDescriptionWithoutError(offer);
3681
3682 video_channel_ = media_engine_->GetVideoChannel(0);
3683 video_channel_->set_fail_set_send_codecs(true);
3684
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003685 SessionDescriptionInterface* answer =
3686 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003687 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003688
3689 // Test that after a content error, setting any description will
3690 // result in an error.
3691 video_channel_->set_fail_set_send_codecs(false);
3692 answer = CreateRemoteAnswer(session_->local_description());
3693 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3694 offer = CreateRemoteOffer();
3695 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003696}
3697
3698// Runs the loopback call test with BUNDLE and STUN disabled.
3699TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3700 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003701 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003702 cricket::PORTALLOCATOR_DISABLE_STUN |
3703 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704 TestLoopbackCall();
3705}
3706
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003707TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003708 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003709 cricket::PORTALLOCATOR_DISABLE_STUN |
3710 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3711 cricket::PORTALLOCATOR_DISABLE_RELAY);
3712
3713 // best connection is IPv6 since it has higher network preference.
3714 LoopbackNetworkConfiguration config;
3715 config.test_ipv6_network_ = true;
3716 config.best_connection_after_initial_ice_converged_ =
3717 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3718
3719 TestLoopbackCall(config);
3720}
3721
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003722// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003723TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003724 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3725 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003726 TestLoopbackCall();
3727}
3728
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003729TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3730 constraints_.reset(new FakeConstraints());
3731 constraints_->AddOptional(
3732 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003733 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734
3735 SetLocalDescriptionWithDataChannel();
3736 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3737}
3738
Henrik Boström87713d02015-08-25 09:53:21 +02003739TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003740 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003741
3742 constraints_.reset(new FakeConstraints());
3743 constraints_->AddOptional(
3744 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003745 options_.disable_sctp_data_channels = false;
3746
Henrik Boström87713d02015-08-25 09:53:21 +02003747 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003748
3749 SetLocalDescriptionWithDataChannel();
3750 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3751}
3752
Henrik Boström87713d02015-08-25 09:53:21 +02003753TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003754 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003755
Henrik Boström87713d02015-08-25 09:53:21 +02003756 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003757
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003758 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003759 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003760 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3761}
3762
Henrik Boström87713d02015-08-25 09:53:21 +02003763TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003764 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003765 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003766 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003767
3768 // Create remote offer with SCTP.
3769 cricket::MediaSessionOptions options;
3770 options.data_channel_type = cricket::DCT_SCTP;
3771 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003772 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003773 SetRemoteDescriptionWithoutError(offer);
3774
3775 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003776 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003777 EXPECT_TRUE(answer != NULL);
3778 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3779 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003780}
3781
Henrik Boström87713d02015-08-25 09:53:21 +02003782TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003783 constraints_.reset(new FakeConstraints());
3784 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003785 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003786 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003787
3788 SetLocalDescriptionWithDataChannel();
3789 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3790}
3791
Henrik Boström87713d02015-08-25 09:53:21 +02003792TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003793 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003794
Henrik Boström87713d02015-08-25 09:53:21 +02003795 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
3797 SetLocalDescriptionWithDataChannel();
3798 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3799}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003800
Henrik Boström87713d02015-08-25 09:53:21 +02003801TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003803 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003804 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003805
3806 SetLocalDescriptionWithDataChannel();
3807 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3808}
3809
Henrik Boström87713d02015-08-25 09:53:21 +02003810TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003811 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003812 const int new_send_port = 9998;
3813 const int new_recv_port = 7775;
3814
Henrik Boström87713d02015-08-25 09:53:21 +02003815 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003816 SetFactoryDtlsSrtp();
3817
3818 // By default, don't actually add the codecs to desc_factory_; they don't
3819 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3820 // let the session description get parsed. That'll get the proper codecs
3821 // into the stream.
3822 cricket::MediaSessionOptions options;
3823 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3824 "stream1", new_send_port, options);
3825
3826 // SetRemoteDescription will take the ownership of the offer.
3827 SetRemoteDescriptionWithoutError(offer);
3828
3829 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3830 new_recv_port, CreateAnswer(NULL));
3831 ASSERT_TRUE(answer != NULL);
3832
3833 // Now set the local description, which'll take ownership of the answer.
3834 SetLocalDescriptionWithoutError(answer);
3835
3836 // TEST PLAN: Set the port number to something new, set it in the SDP,
3837 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003838 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003839 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003840
3841 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3842 int portnum = -1;
3843 ASSERT_TRUE(ch != NULL);
3844 ASSERT_EQ(1UL, ch->send_codecs().size());
3845 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003846 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003847 ch->send_codecs()[0].name.c_str()));
3848 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3849 &portnum));
3850 EXPECT_EQ(new_send_port, portnum);
3851
3852 ASSERT_EQ(1UL, ch->recv_codecs().size());
3853 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003854 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003855 ch->recv_codecs()[0].name.c_str()));
3856 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3857 &portnum));
3858 EXPECT_EQ(new_recv_port, portnum);
3859}
3860
deadbeefab9b2d12015-10-14 11:33:11 -07003861// Verifies that when a session's DataChannel receives an OPEN message,
3862// WebRtcSession signals the DataChannel creation request with the expected
3863// config.
3864TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3865 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3866
3867 InitWithDtls(GetParam());
3868
3869 SetLocalDescriptionWithDataChannel();
3870 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3871
3872 webrtc::DataChannelInit config;
3873 config.id = 1;
3874 rtc::Buffer payload;
3875 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3876 cricket::ReceiveDataParams params;
3877 params.ssrc = config.id;
3878 params.type = cricket::DMT_CONTROL;
3879
3880 cricket::DataChannel* data_channel = session_->data_channel();
3881 data_channel->SignalDataReceived(data_channel, params, payload);
3882
3883 EXPECT_EQ("a", last_data_channel_label_);
3884 EXPECT_EQ(config.id, last_data_channel_config_.id);
3885 EXPECT_FALSE(last_data_channel_config_.negotiated);
3886 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3887 last_data_channel_config_.open_handshake_role);
3888}
3889
3890TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003891 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3892 FakeDtlsIdentityStore::GenerateCertificate();
3893
3894 PeerConnectionInterface::RTCConfiguration configuration;
3895 configuration.certificates.push_back(certificate);
3896 Init(nullptr, configuration);
3897 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3898
3899 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3900}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003901
Henrik Boström87713d02015-08-25 09:53:21 +02003902// Verifies that CreateOffer succeeds when CreateOffer is called before async
3903// identity generation is finished (even if a certificate is provided this is
3904// an async op).
3905TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3906 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3907 InitWithDtls(GetParam());
3908
Henrik Boströmd8281982015-08-27 10:12:24 +02003909 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003910 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003911 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3912
wu@webrtc.org91053e72013-08-10 07:18:04 +00003913 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003914 VerifyNoCryptoParams(offer->description(), true);
3915 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003916}
3917
3918// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003919// identity generation is finished (even if a certificate is provided this is
3920// an async op).
3921TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003922 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003923 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003924 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003925
3926 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003927 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003928 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003929 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003930 ASSERT_TRUE(offer.get() != NULL);
3931 SetRemoteDescriptionWithoutError(offer.release());
3932
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003933 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003934 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003935 VerifyNoCryptoParams(answer->description(), true);
3936 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003937}
3938
3939// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003940// identity generation is finished (even if a certificate is provided this is
3941// an async op).
3942TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003944 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003945
Henrik Boströmd8281982015-08-27 10:12:24 +02003946 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003947
3948 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003949 EXPECT_TRUE(offer != NULL);
3950}
3951
3952// Verifies that CreateOffer fails when CreateOffer is called after async
3953// identity generation fails.
3954TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003955 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003956 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003957
Henrik Boströmd8281982015-08-27 10:12:24 +02003958 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003959
3960 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003961 EXPECT_TRUE(offer == NULL);
3962}
3963
3964// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3965// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003966TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003967 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003968 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003969 VerifyMultipleAsyncCreateDescription(GetParam(),
3970 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003971}
3972
3973// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3974// before async identity generation fails.
3975TEST_F(WebRtcSessionTest,
3976 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003978 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3979 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003980}
3981
3982// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3983// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003984TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003985 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003986 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003987 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003988 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989}
3990
3991// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3992// before async identity generation fails.
3993TEST_F(WebRtcSessionTest,
3994 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003995 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003996 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3997 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003998}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003999
4000// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4001// offer has no SDES crypto but only DTLS fingerprint.
4002TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4003 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004004 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004005 // Create a remote offer with secured transport disabled.
4006 cricket::MediaSessionOptions options;
4007 JsepSessionDescription* offer(CreateRemoteOffer(
4008 options, cricket::SEC_DISABLED));
4009 // Adds a DTLS fingerprint to the remote offer.
4010 cricket::SessionDescription* sdp = offer->description();
4011 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4012 ASSERT_TRUE(audio != NULL);
4013 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4014 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004015 rtc::SSLFingerprint::CreateFromRfc4572(
4016 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004017 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004018 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004019}
4020
wu@webrtc.orgde305012013-10-31 15:40:38 +00004021// This test verifies DSCP is properly applied on the media channels.
4022TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4023 constraints_.reset(new FakeConstraints());
4024 constraints_->AddOptional(
4025 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004026 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004027 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004028 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004029
4030 SetLocalDescriptionWithoutError(offer);
4031
4032 video_channel_ = media_engine_->GetVideoChannel(0);
4033 voice_channel_ = media_engine_->GetVoiceChannel(0);
4034
4035 ASSERT_TRUE(video_channel_ != NULL);
4036 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004037 const cricket::AudioOptions& audio_options = voice_channel_->options();
4038 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004039 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4040 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004041}
4042
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004043TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4044 constraints_.reset(new FakeConstraints());
4045 constraints_->AddOptional(
4046 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4047 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004049 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004050 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004051
4052 SetLocalDescriptionWithoutError(offer);
4053
4054 video_channel_ = media_engine_->GetVideoChannel(0);
4055
4056 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004057 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004058 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004059}
4060
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004061TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4062 // Number of unsignalled receiving streams should be between 0 and
4063 // kMaxUnsignalledRecvStreams.
4064 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4065 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4066 kMaxUnsignalledRecvStreams);
4067 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4068}
4069
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004070TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4071 constraints_.reset(new FakeConstraints());
4072 constraints_->AddOptional(
4073 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4074 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004075 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004076 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004077 SessionDescriptionInterface* offer = CreateOffer();
4078
4079 SetLocalDescriptionWithoutError(offer);
4080
4081 voice_channel_ = media_engine_->GetVoiceChannel(0);
4082
4083 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004084 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004085 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004086}
4087
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004088// Tests that we can renegotiate new media content with ICE candidates in the
4089// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004090TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004091 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004092 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004093 SetFactoryDtlsSrtp();
4094
deadbeefab9b2d12015-10-14 11:33:11 -07004095 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004096 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004097 SetLocalDescriptionWithoutError(offer);
4098
4099 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4100 SetRemoteDescriptionWithoutError(answer);
4101
4102 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004103 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004104 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4105
4106 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004107 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004108 candidate1.set_component(1);
4109 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4110 candidate1);
4111 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4112 SetRemoteDescriptionWithoutError(offer);
4113
4114 answer = CreateAnswer(NULL);
4115 SetLocalDescriptionWithoutError(answer);
4116}
4117
4118// Tests that we can renegotiate new media content with ICE candidates separated
4119// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004120TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004121 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004122 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004123 SetFactoryDtlsSrtp();
4124
deadbeefab9b2d12015-10-14 11:33:11 -07004125 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004126 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004127 SetLocalDescriptionWithoutError(offer);
4128
4129 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4130 SetRemoteDescriptionWithoutError(answer);
4131
4132 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004133 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004134 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4135 SetRemoteDescriptionWithoutError(offer);
4136
4137 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004138 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004139 candidate1.set_component(1);
4140 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4141 candidate1);
4142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4143
4144 answer = CreateAnswer(NULL);
4145 SetLocalDescriptionWithoutError(answer);
4146}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004147// Tests that RTX codec is removed from the answer when it isn't supported
4148// by local side.
4149TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4150 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004151 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004152 std::string offer_sdp(kSdpWithRtx);
4153
4154 SessionDescriptionInterface* offer =
4155 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4156 EXPECT_TRUE(offer->ToString(&offer_sdp));
4157
4158 // Offer SDP contains the RTX codec.
4159 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4160 SetRemoteDescriptionWithoutError(offer);
4161
4162 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4163 std::string answer_sdp;
4164 answer->ToString(&answer_sdp);
4165 // Answer SDP removes the unsupported RTX codec.
4166 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4167 SetLocalDescriptionWithoutError(answer);
4168}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004170// This verifies that the voice channel after bundle has both options from video
4171// and voice channels.
4172TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4173 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004174 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004175
4176 PeerConnectionInterface::RTCOfferAnswerOptions options;
4177 options.use_rtp_mux = true;
4178
4179 SessionDescriptionInterface* offer = CreateOffer(options);
4180 SetLocalDescriptionWithoutError(offer);
4181
4182 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4183 rtc::Socket::Option::OPT_SNDBUF, 4000);
4184
4185 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4186 rtc::Socket::Option::OPT_RCVBUF, 8000);
4187
4188 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004189 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004190 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4191 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004192 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004193 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4194
deadbeefcbecd352015-09-23 11:50:27 -07004195 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004196 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4197 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004198 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004199 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4200
deadbeefcbecd352015-09-23 11:50:27 -07004201 EXPECT_NE(session_->voice_rtp_transport_channel(),
4202 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004203
deadbeefab9b2d12015-10-14 11:33:11 -07004204 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004205 SessionDescriptionInterface* answer =
4206 CreateRemoteAnswer(session_->local_description());
4207 SetRemoteDescriptionWithoutError(answer);
4208
deadbeefcbecd352015-09-23 11:50:27 -07004209 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004210 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4211 EXPECT_EQ(4000, option_val);
4212
deadbeefcbecd352015-09-23 11:50:27 -07004213 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004214 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4215 EXPECT_EQ(8000, option_val);
4216}
4217
tommi0f620f42015-07-09 03:25:02 -07004218// Test creating a session, request multiple offers, destroy the session
4219// and make sure we got success/failure callbacks for all of the requests.
4220// Background: crbug.com/507307
4221TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4222 Init();
4223
4224 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4225 PeerConnectionInterface::RTCOfferAnswerOptions options;
4226 options.offer_to_receive_audio =
4227 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004228 cricket::MediaSessionOptions session_options;
4229 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004230
4231 for (auto& o : observers) {
4232 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004233 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004234 }
4235
4236 session_.reset();
4237
tommi0f620f42015-07-09 03:25:02 -07004238 for (auto& o : observers) {
4239 // We expect to have received a notification now even if the session was
4240 // terminated. The offer creation may or may not have succeeded, but we
4241 // must have received a notification which, so the only invalid state
4242 // is kInit.
4243 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4244 }
4245}
4246
stefanc1aeaf02015-10-15 07:26:07 -07004247TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4248 TestPacketOptions();
4249}
4250
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004251// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4252// currently fails because upon disconnection and reconnection OnIceComplete is
4253// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004254
deadbeefcbecd352015-09-23 11:50:27 -07004255INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4256 WebRtcSessionTest,
4257 testing::Values(ALREADY_GENERATED,
4258 DTLS_IDENTITY_STORE));