blob: 3ddbf876be817613c504db5db39443e50b785f85 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
deadbeefcbecd352015-09-23 11:50:27 -070028#include <vector>
29
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/audiotrack.h"
stefanc1aeaf02015-10-15 07:26:07 -070031#include "talk/app/webrtc/fakemediacontroller.h"
jbauchac8869e2015-07-03 01:36:14 -070032#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/jsepicecandidate.h"
34#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070035#include "talk/app/webrtc/peerconnection.h"
deadbeefab9b2d12015-10-14 11:33:11 -070036#include "talk/app/webrtc/sctputils.h"
37#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020040#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000041#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000043#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000044#include "talk/media/base/fakemediaengine.h"
45#include "talk/media/base/fakevideorenderer.h"
46#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070047#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/base/stunserver.h"
49#include "webrtc/p2p/base/teststunserver.h"
50#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000051#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000052#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000053#include "talk/session/media/channelmanager.h"
54#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055#include "webrtc/base/fakenetwork.h"
56#include "webrtc/base/firewallsocketserver.h"
57#include "webrtc/base/gunit.h"
58#include "webrtc/base/logging.h"
59#include "webrtc/base/network.h"
60#include "webrtc/base/physicalsocketserver.h"
61#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020062#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063#include "webrtc/base/sslstreamadapter.h"
64#include "webrtc/base/stringutils.h"
65#include "webrtc/base/thread.h"
66#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
68#define MAYBE_SKIP_TEST(feature) \
69 if (!(feature())) { \
70 LOG(LS_INFO) << "Feature disabled... skipping"; \
71 return; \
72 }
73
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using cricket::DF_PLAY;
75using cricket::DF_SEND;
76using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000078using rtc::SocketAddress;
79using rtc::scoped_ptr;
80using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000082using webrtc::CreateSessionDescriptionObserver;
83using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070084using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020085using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070087using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070089using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::JsepIceCandidate;
91using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000092using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093using webrtc::PeerConnectionInterface;
94using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070095using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000097using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000098using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000099using webrtc::kCreateChannelFailed;
100using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000102using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000103using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000104using webrtc::kSdpWithoutDtlsFingerprint;
105using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000107using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000108using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000110typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
111
wu@webrtc.org364f2042013-11-20 21:49:41 +0000112static const int kClientAddrPort = 0;
113static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000114static const char kClientIPv6AddrHost1[] =
115 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000116static const char kClientAddrHost2[] = "22.22.22.22";
117static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000118static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
119static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000120static const char kTurnUsername[] = "test";
121static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122
123static const char kSessionVersion[] = "1";
124
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125// Media index of candidates belonging to the first media content.
126static const int kMediaContentIndex0 = 0;
127static const char kMediaContentName0[] = "audio";
128
129// Media index of candidates belonging to the second media content.
130static const int kMediaContentIndex1 = 1;
131static const char kMediaContentName1[] = "video";
132
133static const int kIceCandidatesTimeout = 10000;
134
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000135static const char kFakeDtlsFingerprint[] =
136 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
137 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
138
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000139static const char kTooLongIceUfragPwd[] =
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
143 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
144
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000145static const char kSdpWithRtx[] =
146 "v=0\r\n"
147 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
148 "s=-\r\n"
149 "t=0 0\r\n"
150 "a=msid-semantic: WMS stream1\r\n"
151 "m=video 9 RTP/SAVPF 0 96\r\n"
152 "c=IN IP4 0.0.0.0\r\n"
153 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
154 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
155 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
156 "a=mid:video\r\n"
157 "a=sendrecv\r\n"
158 "a=rtcp-mux\r\n"
159 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
160 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
161 "a=rtpmap:0 fake_video_codec/90000\r\n"
162 "a=rtpmap:96 rtx/90000\r\n"
163 "a=fmtp:96 apt=0\r\n";
164
deadbeefab9b2d12015-10-14 11:33:11 -0700165static const char kStream1[] = "stream1";
166static const char kVideoTrack1[] = "video1";
167static const char kAudioTrack1[] = "audio1";
168
169static const char kStream2[] = "stream2";
170static const char kVideoTrack2[] = "video2";
171static const char kAudioTrack2[] = "audio2";
172
Henrik Boström87713d02015-08-25 09:53:21 +0200173enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175// Add some extra |newlines| to the |message| after |line|.
176static void InjectAfter(const std::string& line,
177 const std::string& newlines,
178 std::string* message) {
179 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700180 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
181 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182}
183
184class MockIceObserver : public webrtc::IceObserver {
185 public:
186 MockIceObserver()
187 : oncandidatesready_(false),
188 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
189 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
190 }
191
192 virtual void OnIceConnectionChange(
193 PeerConnectionInterface::IceConnectionState new_state) {
194 ice_connection_state_ = new_state;
195 }
196 virtual void OnIceGatheringChange(
197 PeerConnectionInterface::IceGatheringState new_state) {
198 // We can never transition back to "new".
199 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
200 ice_gathering_state_ = new_state;
201
202 // oncandidatesready_ really means "ICE gathering is complete".
203 // This if statement ensures that this value remains correct when we
204 // transition from kIceGatheringComplete to kIceGatheringGathering.
205 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
206 oncandidatesready_ = false;
207 }
208 }
209
210 // Found a new candidate.
211 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000212 switch (candidate->sdp_mline_index()) {
213 case kMediaContentIndex0:
214 mline_0_candidates_.push_back(candidate->candidate());
215 break;
216 case kMediaContentIndex1:
217 mline_1_candidates_.push_back(candidate->candidate());
218 break;
219 default:
220 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000222
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 // The ICE gathering state should always be Gathering when a candidate is
224 // received (or possibly Completed in the case of the final candidate).
225 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
226 }
227
228 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
229 virtual void OnIceComplete() {
230 EXPECT_FALSE(oncandidatesready_);
231 oncandidatesready_ = true;
232
233 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
234 // be called approximately simultaneously. For ease of testing, this
235 // check additionally requires that they be called in the above order.
236 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
237 ice_gathering_state_);
238 }
239
240 bool oncandidatesready_;
241 std::vector<cricket::Candidate> mline_0_candidates_;
242 std::vector<cricket::Candidate> mline_1_candidates_;
243 PeerConnectionInterface::IceConnectionState ice_connection_state_;
244 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
245};
246
247class WebRtcSessionForTest : public webrtc::WebRtcSession {
248 public:
stefanc1aeaf02015-10-15 07:26:07 -0700249 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000250 rtc::Thread* signaling_thread,
251 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700253 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700254 : WebRtcSession(media_controller,
255 signaling_thread,
256 worker_thread,
257 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 RegisterIceObserver(ice_observer);
259 }
260 virtual ~WebRtcSessionForTest() {}
261
deadbeefcbecd352015-09-23 11:50:27 -0700262 // Note that these methods are only safe to use if the signaling thread
263 // is the same as the worker thread
264 cricket::TransportChannel* voice_rtp_transport_channel() {
265 return rtp_transport_channel(voice_channel());
266 }
267
268 cricket::TransportChannel* voice_rtcp_transport_channel() {
269 return rtcp_transport_channel(voice_channel());
270 }
271
272 cricket::TransportChannel* video_rtp_transport_channel() {
273 return rtp_transport_channel(video_channel());
274 }
275
276 cricket::TransportChannel* video_rtcp_transport_channel() {
277 return rtcp_transport_channel(video_channel());
278 }
279
280 cricket::TransportChannel* data_rtp_transport_channel() {
281 return rtp_transport_channel(data_channel());
282 }
283
284 cricket::TransportChannel* data_rtcp_transport_channel() {
285 return rtcp_transport_channel(data_channel());
286 }
287
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 using webrtc::WebRtcSession::SetAudioPlayout;
289 using webrtc::WebRtcSession::SetAudioSend;
290 using webrtc::WebRtcSession::SetCaptureDevice;
291 using webrtc::WebRtcSession::SetVideoPlayout;
292 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700293
294 private:
295 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
296 if (!ch) {
297 return nullptr;
298 }
299 return ch->transport_channel();
300 }
301
302 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
303 if (!ch) {
304 return nullptr;
305 }
306 return ch->rtcp_transport_channel();
307 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308};
309
wu@webrtc.org91053e72013-08-10 07:18:04 +0000310class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000311 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000313 enum State {
314 kInit,
315 kFailed,
316 kSucceeded,
317 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000318 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000319
320 // CreateSessionDescriptionObserver implementation.
321 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000322 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000323 state_ = kSucceeded;
324 }
325 virtual void OnFailure(const std::string& error) {
326 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000329 SessionDescriptionInterface* description() { return description_.get(); }
330
331 SessionDescriptionInterface* ReleaseDescription() {
332 return description_.release();
333 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
wu@webrtc.org91053e72013-08-10 07:18:04 +0000335 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336
wu@webrtc.org91053e72013-08-10 07:18:04 +0000337 protected:
338 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339
340 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000341 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000342 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343};
344
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000345class FakeAudioRenderer : public cricket::AudioRenderer {
346 public:
solenberg98c68862015-10-09 03:27:14 -0700347 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000348 virtual ~FakeAudioRenderer() {
349 if (sink_)
350 sink_->OnClose();
351 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000352
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000353 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000354
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000355 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000357 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000358};
359
Henrik Boström87713d02015-08-25 09:53:21 +0200360class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700361 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
362 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 protected:
364 // TODO Investigate why ChannelManager crashes, if it's created
365 // after stun_server.
366 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700367 : media_engine_(new cricket::FakeMediaEngine()),
368 data_engine_(new cricket::FakeDataEngine()),
369 channel_manager_(
370 new cricket::ChannelManager(media_engine_,
371 data_engine_,
372 new cricket::CaptureManager(),
373 rtc::Thread::Current())),
374 fake_call_(webrtc::Call::Config()),
375 media_controller_(
376 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
377 channel_manager_.get())),
378 tdesc_factory_(new cricket::TransportDescriptionFactory()),
379 desc_factory_(
380 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
381 tdesc_factory_.get())),
382 pss_(new rtc::PhysicalSocketServer),
383 vss_(new rtc::VirtualSocketServer(pss_.get())),
384 fss_(new rtc::FirewallSocketServer(vss_.get())),
385 ss_scope_(fss_.get()),
386 stun_socket_addr_(
387 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
388 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
389 stun_socket_addr_)),
390 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
391 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000392 cricket::ServerAddresses stun_servers;
393 stun_servers.insert(stun_socket_addr_);
394 allocator_.reset(new cricket::BasicPortAllocator(
395 &network_manager_,
396 stun_servers,
397 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000398 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700399 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 EXPECT_TRUE(channel_manager_->Init());
401 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000402 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 }
404
405 void AddInterface(const SocketAddress& addr) {
406 network_manager_.AddInterface(addr);
407 }
408
Henrik Boström87713d02015-08-25 09:53:21 +0200409 // If |dtls_identity_store| != null or |rtc_configuration| contains
410 // |certificates| then DTLS will be enabled unless explicitly disabled by
411 // |rtc_configuration| options. When DTLS is enabled a certificate will be
412 // used if provided, otherwise one will be generated using the
413 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200415 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200416 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 ASSERT_TRUE(session_.get() == NULL);
418 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700419 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700420 allocator_.get(), &observer_));
421 session_->SignalDataChannelOpenMessage.connect(
422 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
424 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
425 observer_.ice_connection_state_);
426 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
427 observer_.ice_gathering_state_);
428
deadbeefcbecd352015-09-23 11:50:27 -0700429 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
430 dtls_identity_store.Pass(),
431 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700432 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 }
434
deadbeefab9b2d12015-10-14 11:33:11 -0700435 void OnDataChannelOpenMessage(const std::string& label,
436 const InternalDataChannelInit& config) {
437 last_data_channel_label_ = label;
438 last_data_channel_config_ = config;
439 }
440
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000441 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200442 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200443 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000444 }
445
446 void InitWithIceTransport(
447 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200448 PeerConnectionInterface::RTCConfiguration configuration;
449 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200450 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000451 }
452
453 void InitWithBundlePolicy(
454 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200455 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200456 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200457 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700458 }
459
460 void InitWithRtcpMuxPolicy(
461 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
462 PeerConnectionInterface::RTCConfiguration configuration;
463 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200464 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000465 }
466
Henrik Boström87713d02015-08-25 09:53:21 +0200467 // Successfully init with DTLS; with a certificate generated and supplied or
468 // with a store that generates it for us.
469 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
470 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
471 PeerConnectionInterface::RTCConfiguration configuration;
472 if (cert_gen_method == ALREADY_GENERATED) {
473 configuration.certificates.push_back(
474 FakeDtlsIdentityStore::GenerateCertificate());
475 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
476 dtls_identity_store.reset(new FakeDtlsIdentityStore());
477 dtls_identity_store->set_should_fail(false);
478 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700479 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200480 }
481 Init(dtls_identity_store.Pass(), configuration);
482 }
483
484 // Init with DTLS with a store that will fail to generate a certificate.
485 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200486 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
487 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200488 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200489 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200490 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000491 }
492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 void InitWithDtmfCodec() {
494 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000495 const cricket::AudioCodec kTelephoneEventCodec(
496 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 std::vector<cricket::AudioCodec> codecs;
498 codecs.push_back(kTelephoneEventCodec);
499 media_engine_->SetAudioCodecs(codecs);
500 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000501 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 }
503
deadbeefab9b2d12015-10-14 11:33:11 -0700504 void SendAudioVideoStream1() {
505 send_stream_1_ = true;
506 send_stream_2_ = false;
507 send_audio_ = true;
508 send_video_ = true;
509 }
510
511 void SendAudioVideoStream2() {
512 send_stream_1_ = false;
513 send_stream_2_ = true;
514 send_audio_ = true;
515 send_video_ = true;
516 }
517
518 void SendAudioVideoStream1And2() {
519 send_stream_1_ = true;
520 send_stream_2_ = true;
521 send_audio_ = true;
522 send_video_ = true;
523 }
524
525 void SendNothing() {
526 send_stream_1_ = false;
527 send_stream_2_ = false;
528 send_audio_ = false;
529 send_video_ = false;
530 }
531
532 void SendAudioOnlyStream2() {
533 send_stream_1_ = false;
534 send_stream_2_ = true;
535 send_audio_ = true;
536 send_video_ = false;
537 }
538
539 void SendVideoOnlyStream2() {
540 send_stream_1_ = false;
541 send_stream_2_ = true;
542 send_audio_ = false;
543 send_video_ = true;
544 }
545
546 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
547 if (send_stream_1_ && send_audio_) {
548 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
549 kStream1);
550 }
551 if (send_stream_1_ && send_video_) {
552 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
553 kStream1);
554 }
555 if (send_stream_2_ && send_audio_) {
556 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
557 kStream2);
558 }
559 if (send_stream_2_ && send_video_) {
560 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
561 kStream2);
562 }
563 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
564 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
565 data_channel_->label(),
566 data_channel_->label());
567 }
568 }
569
570 void GetOptionsForOffer(
571 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
572 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700573 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
574
deadbeefc80741f2015-10-22 13:14:45 -0700575 AddStreamsToOptions(session_options);
576 if (rtc_options.offer_to_receive_audio ==
577 RTCOfferAnswerOptions::kUndefined) {
578 session_options->recv_audio =
579 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
580 }
581 if (rtc_options.offer_to_receive_video ==
582 RTCOfferAnswerOptions::kUndefined) {
583 session_options->recv_video =
584 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
585 }
586 session_options->bundle_enabled =
587 session_options->bundle_enabled &&
588 (session_options->has_audio() || session_options->has_video() ||
589 session_options->has_data());
590
deadbeefab9b2d12015-10-14 11:33:11 -0700591 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
592 session_options->data_channel_type = cricket::DCT_SCTP;
593 }
594 }
595
596 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
597 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700598 session_options->recv_audio = false;
599 session_options->recv_video = false;
600 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
601
deadbeefc80741f2015-10-22 13:14:45 -0700602 AddStreamsToOptions(session_options);
603 session_options->bundle_enabled =
604 session_options->bundle_enabled &&
605 (session_options->has_audio() || session_options->has_video() ||
606 session_options->has_data());
607
deadbeefab9b2d12015-10-14 11:33:11 -0700608 if (session_->data_channel_type() == cricket::DCT_SCTP) {
609 session_options->data_channel_type = cricket::DCT_SCTP;
610 }
611 }
612
613 // Creates a local offer and applies it. Starts ICE.
614 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 // to decide which streams to create.
616 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000617 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 SetLocalDescriptionWithoutError(offer);
619 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
620 observer_.ice_gathering_state_,
621 kIceCandidatesTimeout);
622 }
623
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000624 SessionDescriptionInterface* CreateOffer() {
625 PeerConnectionInterface::RTCOfferAnswerOptions options;
626 options.offer_to_receive_audio =
627 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
628
629 return CreateOffer(options);
630 }
631
wu@webrtc.org91053e72013-08-10 07:18:04 +0000632 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000633 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000634 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000635 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700636 cricket::MediaSessionOptions session_options;
637 GetOptionsForOffer(options, &session_options);
638 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000639 EXPECT_TRUE_WAIT(
640 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000641 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000642 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000643 }
644
645 SessionDescriptionInterface* CreateAnswer(
646 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000647 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000648 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700649 cricket::MediaSessionOptions session_options;
650 GetOptionsForAnswer(constraints, &session_options);
651 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000652 EXPECT_TRUE_WAIT(
653 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000654 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000655 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000656 }
657
wu@webrtc.org364f2042013-11-20 21:49:41 +0000658 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659 return (session_->voice_channel() != NULL &&
660 session_->video_channel() != NULL);
661 }
662
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
664 ASSERT_TRUE(session_.get() != NULL);
665 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
666 ASSERT_TRUE(content != NULL);
667 const cricket::AudioContentDescription* audio_content =
668 static_cast<const cricket::AudioContentDescription*>(
669 content->description);
670 ASSERT_TRUE(audio_content != NULL);
671 ASSERT_EQ(1U, audio_content->cryptos().size());
672 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
673 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
674 audio_content->cryptos()[0].cipher_suite);
675 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
676 audio_content->protocol());
677
678 content = cricket::GetFirstVideoContent(sdp);
679 ASSERT_TRUE(content != NULL);
680 const cricket::VideoContentDescription* video_content =
681 static_cast<const cricket::VideoContentDescription*>(
682 content->description);
683 ASSERT_TRUE(video_content != NULL);
684 ASSERT_EQ(1U, video_content->cryptos().size());
685 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
686 video_content->cryptos()[0].cipher_suite);
687 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
688 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
689 video_content->protocol());
690 }
691
692 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
693 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
694 ASSERT_TRUE(content != NULL);
695 const cricket::AudioContentDescription* audio_content =
696 static_cast<const cricket::AudioContentDescription*>(
697 content->description);
698 ASSERT_TRUE(audio_content != NULL);
699 ASSERT_EQ(0U, audio_content->cryptos().size());
700
701 content = cricket::GetFirstVideoContent(sdp);
702 ASSERT_TRUE(content != NULL);
703 const cricket::VideoContentDescription* video_content =
704 static_cast<const cricket::VideoContentDescription*>(
705 content->description);
706 ASSERT_TRUE(video_content != NULL);
707 ASSERT_EQ(0U, video_content->cryptos().size());
708
709 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700710 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700712 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 video_content->protocol());
714 } else {
715 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
716 audio_content->protocol());
717 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
718 video_content->protocol());
719 }
720 }
721
722 // Set the internal fake description factories to do DTLS-SRTP.
723 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000724 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000726 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200727 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200728 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700729 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
730 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
732 }
733
734 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
735 bool expected) {
736 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
737 ASSERT_TRUE(audio != NULL);
738 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 const TransportInfo* video = sdp->GetTransportInfoByName("video");
740 ASSERT_TRUE(video != NULL);
741 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 }
743
744 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000745 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000747 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000748 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000750 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000752 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
753 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000754 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 // Answer should be NULL as no crypto params in offer.
756 ASSERT_TRUE(answer == NULL);
757 }
758
759 void VerifyAnswerFromCryptoOffer() {
760 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000761 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 options.bundle_enabled = true;
763 scoped_ptr<JsepSessionDescription> offer(
764 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
765 ASSERT_TRUE(offer.get() != NULL);
766 VerifyCryptoParams(offer->description());
767 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000768 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 ASSERT_TRUE(answer.get() != NULL);
770 VerifyCryptoParams(answer->description());
771 }
772
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000773 void SetAndVerifyNumUnsignalledRecvStreams(
774 int value_set, int value_expected) {
775 constraints_.reset(new FakeConstraints());
776 constraints_->AddOptional(
777 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
778 value_set);
779 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000780 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700781 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000782 SessionDescriptionInterface* offer = CreateOffer();
783
784 SetLocalDescriptionWithoutError(offer);
785
786 video_channel_ = media_engine_->GetVideoChannel(0);
787
788 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700789 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000790 EXPECT_EQ(value_expected,
kwiberg102c6a62015-10-30 02:47:38 -0700791 video_options.unsignalled_recv_stream_limit.value_or(-1));
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000792 }
793
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
795 const cricket::SessionDescription* desc2,
796 bool expect_equal) {
797 if (desc1->contents().size() != desc2->contents().size()) {
798 EXPECT_FALSE(expect_equal);
799 return;
800 }
801
802 const cricket::ContentInfos& contents = desc1->contents();
803 cricket::ContentInfos::const_iterator it = contents.begin();
804
805 for (; it != contents.end(); ++it) {
806 const cricket::TransportDescription* transport_desc1 =
807 desc1->GetTransportDescriptionByName(it->name);
808 const cricket::TransportDescription* transport_desc2 =
809 desc2->GetTransportDescriptionByName(it->name);
810 if (!transport_desc1 || !transport_desc2) {
811 EXPECT_FALSE(expect_equal);
812 return;
813 }
814 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
815 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
816 EXPECT_FALSE(expect_equal);
817 return;
818 }
819 }
820 EXPECT_TRUE(expect_equal);
821 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000822
823 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
824 std::string *sdp) {
825 const cricket::SessionDescription* desc = current_desc->description();
826 EXPECT_TRUE(current_desc->ToString(sdp));
827
828 const cricket::ContentInfos& contents = desc->contents();
829 cricket::ContentInfos::const_iterator it = contents.begin();
830 // Replace ufrag and pwd lines with empty strings.
831 for (; it != contents.end(); ++it) {
832 const cricket::TransportDescription* transport_desc =
833 desc->GetTransportDescriptionByName(it->name);
834 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
835 + "\r\n";
836 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
837 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000838 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000839 "", 0,
840 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000841 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000842 "", 0,
843 sdp);
844 }
845 }
846
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000847 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
848 const std::string& modified_ice_ufrag,
849 const std::string& modified_ice_pwd,
850 std::string* sdp) {
851 const cricket::SessionDescription* desc = current_desc->description();
852 EXPECT_TRUE(current_desc->ToString(sdp));
853
854 const cricket::ContentInfos& contents = desc->contents();
855 cricket::ContentInfos::const_iterator it = contents.begin();
856 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
857 // |modified_ice_pwd| strings.
858 for (; it != contents.end(); ++it) {
859 const cricket::TransportDescription* transport_desc =
860 desc->GetTransportDescriptionByName(it->name);
861 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
862 + "\r\n";
863 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
864 + "\r\n";
865 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
866 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000867 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000868 mod_ufrag.c_str(), mod_ufrag.length(),
869 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000870 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000871 mod_pwd.c_str(), mod_pwd.length(),
872 sdp);
873 }
874 }
875
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 // Creates a remote offer and and applies it as a remote description,
877 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700878 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 // to decide which local and remote streams to create.
880 void CreateAndSetRemoteOfferAndLocalAnswer() {
881 SessionDescriptionInterface* offer = CreateRemoteOffer();
882 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000883 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 SetLocalDescriptionWithoutError(answer);
885 }
886 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
887 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700888 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
890 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700891 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 SetLocalDescriptionWithoutError(desc);
893 EXPECT_EQ(expected_state, session_->state());
894 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000895 void SetLocalDescriptionExpectError(const std::string& action,
896 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 SessionDescriptionInterface* desc) {
898 std::string error;
899 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000900 std::string sdp_type = "local ";
901 sdp_type.append(action);
902 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 EXPECT_NE(std::string::npos, error.find(expected_error));
904 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000905 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
906 SessionDescriptionInterface* desc) {
907 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
908 expected_error, desc);
909 }
910 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
911 SessionDescriptionInterface* desc) {
912 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
913 expected_error, desc);
914 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
916 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
917 }
918 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700919 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 SetRemoteDescriptionWithoutError(desc);
921 EXPECT_EQ(expected_state, session_->state());
922 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000923 void SetRemoteDescriptionExpectError(const std::string& action,
924 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 SessionDescriptionInterface* desc) {
926 std::string error;
927 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000928 std::string sdp_type = "remote ";
929 sdp_type.append(action);
930 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 EXPECT_NE(std::string::npos, error.find(expected_error));
932 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000933 void SetRemoteDescriptionOfferExpectError(
934 const std::string& expected_error, SessionDescriptionInterface* desc) {
935 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
936 expected_error, desc);
937 }
938 void SetRemoteDescriptionPranswerExpectError(
939 const std::string& expected_error, SessionDescriptionInterface* desc) {
940 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
941 expected_error, desc);
942 }
943 void SetRemoteDescriptionAnswerExpectError(
944 const std::string& expected_error, SessionDescriptionInterface* desc) {
945 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
946 expected_error, desc);
947 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948
949 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
950 SessionDescriptionInterface** nocrypto_answer) {
951 // Create a SDP without Crypto.
952 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000953 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 options.bundle_enabled = true;
955 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
956 ASSERT_TRUE(*offer != NULL);
957 VerifyCryptoParams((*offer)->description());
958
959 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
960 cricket::SEC_DISABLED);
961 EXPECT_TRUE(*nocrypto_answer != NULL);
962 }
963
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000964 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
965 SessionDescriptionInterface** nodtls_answer) {
966 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000967 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000968 options.bundle_enabled = true;
969
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000970 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000971 CreateRemoteOffer(options, cricket::SEC_ENABLED));
972
973 *nodtls_answer =
974 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
975 EXPECT_TRUE(*nodtls_answer != NULL);
976 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
977 VerifyCryptoParams((*nodtls_answer)->description());
978
979 SetFactoryDtlsSrtp();
980 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
981 ASSERT_TRUE(*offer != NULL);
982 VerifyFingerprintStatus((*offer)->description(), true);
983 VerifyCryptoParams((*offer)->description());
984 }
985
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 JsepSessionDescription* CreateRemoteOfferWithVersion(
987 cricket::MediaSessionOptions options,
988 cricket::SecurePolicy secure_policy,
989 const std::string& session_version,
990 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000991 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 const cricket::SessionDescription* cricket_desc = NULL;
993 if (current_desc) {
994 cricket_desc = current_desc->description();
995 session_id = current_desc->session_id();
996 }
997
998 desc_factory_->set_secure(secure_policy);
999 JsepSessionDescription* offer(
1000 new JsepSessionDescription(JsepSessionDescription::kOffer));
1001 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1002 session_id, session_version)) {
1003 delete offer;
1004 offer = NULL;
1005 }
1006 return offer;
1007 }
1008 JsepSessionDescription* CreateRemoteOffer(
1009 cricket::MediaSessionOptions options) {
1010 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1011 kSessionVersion, NULL);
1012 }
1013 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001014 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1015 return CreateRemoteOfferWithVersion(
1016 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 }
1018 JsepSessionDescription* CreateRemoteOffer(
1019 cricket::MediaSessionOptions options,
1020 const SessionDescriptionInterface* current_desc) {
1021 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1022 kSessionVersion, current_desc);
1023 }
1024
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001025 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1026 const char* sctp_stream_name, int new_port,
1027 cricket::MediaSessionOptions options) {
1028 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001029 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1030 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001031 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1032 }
1033
1034 // Takes ownership of offer_basis (and deletes it).
1035 JsepSessionDescription* ChangeSDPSctpPort(
1036 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1037 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1038 // SessionDescription from the mutated string.
1039 const char* default_port_str = "5000";
1040 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001041 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001042 std::string offer_str;
1043 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001044 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001045 new_port_str, strlen(new_port_str),
1046 &offer_str);
1047 JsepSessionDescription* offer = new JsepSessionDescription(
1048 offer_basis->type());
1049 delete offer_basis;
1050 offer->Initialize(offer_str, NULL);
1051 return offer;
1052 }
1053
deadbeefab9b2d12015-10-14 11:33:11 -07001054 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 // before this function to decide which streams to create.
1056 JsepSessionDescription* CreateRemoteOffer() {
1057 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001058 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 return CreateRemoteOffer(options, session_->remote_description());
1060 }
1061
1062 JsepSessionDescription* CreateRemoteAnswer(
1063 const SessionDescriptionInterface* offer,
1064 cricket::MediaSessionOptions options,
1065 cricket::SecurePolicy policy) {
1066 desc_factory_->set_secure(policy);
1067 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001068 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 JsepSessionDescription* answer(
1070 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1071 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1072 options, NULL),
1073 session_id, kSessionVersion)) {
1074 delete answer;
1075 answer = NULL;
1076 }
1077 return answer;
1078 }
1079
1080 JsepSessionDescription* CreateRemoteAnswer(
1081 const SessionDescriptionInterface* offer,
1082 cricket::MediaSessionOptions options) {
1083 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1084 }
1085
deadbeefab9b2d12015-10-14 11:33:11 -07001086 // Creates an answer session description.
1087 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 // to decide which streams to create.
1089 JsepSessionDescription* CreateRemoteAnswer(
1090 const SessionDescriptionInterface* offer) {
1091 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001092 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1094 }
1095
1096 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001097 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001099 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001100
1101 PeerConnectionInterface::RTCOfferAnswerOptions options;
1102 options.use_rtp_mux = bundle;
1103
1104 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1106 // and answer.
1107 SetLocalDescriptionWithoutError(offer);
1108
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001109 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001110 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 std::string sdp;
1112 EXPECT_TRUE(answer->ToString(&sdp));
1113
1114 size_t expected_candidate_num = 2;
1115 if (!rtcp_mux) {
1116 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1117 // for rtp and rtcp.
1118 expected_candidate_num = 4;
1119 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 const std::string kRtcpMux = "a=rtcp-mux";
1121 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001122 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 kXRtcpMux.c_str(), kXRtcpMux.length(),
1124 &sdp);
1125 }
1126
1127 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1128 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129
1130 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001131 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1133 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001134 if (bundle) {
1135 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1136 } else {
1137 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 }
1139 }
1140 // Tests that we can only send DTMF when the dtmf codec is supported.
1141 void TestCanInsertDtmf(bool can) {
1142 if (can) {
1143 InitWithDtmfCodec();
1144 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001145 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 }
deadbeefab9b2d12015-10-14 11:33:11 -07001147 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 CreateAndSetRemoteOfferAndLocalAnswer();
1149 EXPECT_FALSE(session_->CanInsertDtmf(""));
1150 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1151 }
1152
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 // Helper class to configure loopback network and verify Best
1154 // Connection using right IP protocol for TestLoopbackCall
1155 // method. LoopbackNetworkManager applies firewall rules to block
1156 // all ping traffic once ICE completed, and remove them to observe
1157 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1158 // verifies the best connection is using the right IP protocol after
1159 // initial ICE convergences.
1160
1161 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001162 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001163 LoopbackNetworkConfiguration()
1164 : test_ipv6_network_(false),
1165 test_extra_ipv4_network_(false),
1166 best_connection_after_initial_ice_converged_(1, 0) {}
1167
1168 // Used to track the expected best connection count in each IP protocol.
1169 struct ExpectedBestConnection {
1170 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1171 : ipv4_count_(ipv4_count),
1172 ipv6_count_(ipv6_count) {}
1173
1174 int ipv4_count_;
1175 int ipv6_count_;
1176 };
1177
1178 bool test_ipv6_network_;
1179 bool test_extra_ipv4_network_;
1180 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1181
1182 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001183 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001184 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1185 }
1186
1187 private:
jbauchac8869e2015-07-03 01:36:14 -07001188 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001189 const ExpectedBestConnection& expected) const {
1190 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001191 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1192 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001193 expected.ipv4_count_);
1194 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001195 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1196 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001197 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001198 // This is used in the loopback call so there is only single host to host
1199 // candidate pair.
1200 EXPECT_EQ(metrics_observer->GetEnumCounter(
1201 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1202 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001203 0);
1204 EXPECT_EQ(metrics_observer->GetEnumCounter(
1205 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1206 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001207 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001208 }
1209 };
1210
1211 class LoopbackNetworkManager {
1212 public:
1213 LoopbackNetworkManager(WebRtcSessionTest* session,
1214 const LoopbackNetworkConfiguration& config)
1215 : config_(config) {
1216 session->AddInterface(
1217 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1218 if (config_.test_extra_ipv4_network_) {
1219 session->AddInterface(
1220 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1221 }
1222 if (config_.test_ipv6_network_) {
1223 session->AddInterface(
1224 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1225 }
1226 }
1227
1228 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1229 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1230 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1231 if (config_.test_extra_ipv4_network_) {
1232 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1233 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1234 }
1235 if (config_.test_ipv6_network_) {
1236 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1237 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1238 }
1239 }
1240
1241 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1242
1243 private:
1244 LoopbackNetworkConfiguration config_;
1245 };
1246
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 // The method sets up a call from the session to itself, in a loopback
1248 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001249 // disconnection, and then a permanent disconnection.
1250 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1252 // While running the call, this method also checks if the session goes through
1253 // the correct sequence of ICE states when a connection is established,
1254 // broken, and re-established.
1255 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001256 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1257 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001259
stefanc1aeaf02015-10-15 07:26:07 -07001260 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001261 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001262 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001263 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264
1265 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1266 observer_.ice_gathering_state_);
1267 SetLocalDescriptionWithoutError(offer);
1268 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1269 observer_.ice_connection_state_);
1270 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001271 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1273 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001274 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275
1276 std::string sdp;
1277 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001278 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1279 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 ASSERT_TRUE(desc != NULL);
1281 SetRemoteDescriptionWithoutError(desc);
1282
1283 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001284 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001285
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001286 // The ice connection state is "Connected" too briefly to catch in a test.
1287 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001288 observer_.ice_connection_state_, kIceCandidatesTimeout);
1289 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290
stefanc1aeaf02015-10-15 07:26:07 -07001291 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1292 LoopbackNetworkManager loopback_network_manager(this, config);
1293 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001294 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 // Adding firewall rule to block ping requests, which should cause
1296 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001297
1298 loopback_network_manager.ApplyFirewallRules(fss_.get());
1299
1300 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1302 observer_.ice_connection_state_,
1303 kIceCandidatesTimeout);
1304
jbauchac8869e2015-07-03 01:36:14 -07001305 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001306
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001310 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001311 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 observer_.ice_connection_state_,
1313 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001314
1315 // Now we block ping requests and wait until the ICE connection transitions
1316 // to the Failed state. This will take at least 30 seconds because it must
1317 // wait for the Port to timeout.
1318 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001319
1320 loopback_network_manager.ApplyFirewallRules(fss_.get());
1321 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001322 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001323 observer_.ice_connection_state_,
1324 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 }
1326
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001327 void TestLoopbackCall() {
1328 LoopbackNetworkConfiguration config;
1329 TestLoopbackCall(config);
1330 }
1331
stefanc1aeaf02015-10-15 07:26:07 -07001332 void TestPacketOptions() {
1333 media_controller_.reset(
1334 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1335 LoopbackNetworkConfiguration config;
1336 LoopbackNetworkManager loopback_network_manager(this, config);
1337
1338 SetupLoopbackCall();
1339
1340 uint8_t test_packet[15] = {0};
1341 rtc::PacketOptions options;
1342 options.packet_id = 10;
1343 media_engine_->GetVideoChannel(0)
1344 ->SendRtp(test_packet, sizeof(test_packet), options);
1345
1346 const int kPacketTimeout = 2000;
1347 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1348 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1349 }
1350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1352 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001353 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1354 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1355
1356 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1358 codecs.push_back(kCNCodec1);
1359 codecs.push_back(kCNCodec2);
1360 media_engine_->SetAudioCodecs(codecs);
1361 desc_factory_->set_audio_codecs(codecs);
1362 }
1363
1364 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1365 const cricket::ContentDescription* description = content->description;
1366 ASSERT(description != NULL);
1367 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001368 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 ASSERT(audio_content_desc != NULL);
1370 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1371 if (audio_content_desc->codecs()[i].name == "CN")
1372 return false;
1373 }
1374 return true;
1375 }
1376
deadbeefab9b2d12015-10-14 11:33:11 -07001377 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001378 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001379 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1380 data_channel_ = DataChannel::Create(
1381 session_.get(), session_->data_channel_type(), "datachannel", dci);
1382 }
1383
1384 void SetLocalDescriptionWithDataChannel() {
1385 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001386 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 SetLocalDescriptionWithoutError(offer);
1388 }
1389
wu@webrtc.org91053e72013-08-10 07:18:04 +00001390 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001391 RTCCertificateGenerationMethod cert_gen_method,
1392 CreateSessionDescriptionRequest::Type type) {
1393 InitWithDtls(cert_gen_method);
1394 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1395 }
1396
1397 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1398 CreateSessionDescriptionRequest::Type type) {
1399 InitWithDtlsIdentityGenFail();
1400 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1401 }
1402
1403 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001405 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001406 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001407 if (type == CreateSessionDescriptionRequest::kAnswer) {
1408 cricket::MediaSessionOptions options;
1409 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001410 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001411 ASSERT_TRUE(offer.get() != NULL);
1412 SetRemoteDescriptionWithoutError(offer.release());
1413 }
1414
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001415 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001416 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001417 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001418 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001419 observers[kNumber];
1420 for (int i = 0; i < kNumber; ++i) {
1421 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1422 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001423 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001424 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001425 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001426 }
1427 }
1428
1429 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1430 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1431 WebRtcSessionCreateSDPObserverForTest::kFailed;
1432
1433 for (int i = 0; i < kNumber; ++i) {
1434 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1435 if (success) {
1436 EXPECT_TRUE(observers[i]->description() != NULL);
1437 } else {
1438 EXPECT_TRUE(observers[i]->description() == NULL);
1439 }
1440 }
1441 }
1442
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001443 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001444 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001445 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001446 turn_server.credentials = credentials;
1447 turn_server.ports.push_back(
1448 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1449 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001450 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001451 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001452 }
1453
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 cricket::FakeMediaEngine* media_engine_;
1455 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001456 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001457 cricket::FakeCall fake_call_;
1458 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001459 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001460 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1461 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1462 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1463 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1464 rtc::SocketServerScope ss_scope_;
1465 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001466 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001467 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001468 rtc::FakeNetworkManager network_manager_;
1469 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001470 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001471 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 MockIceObserver observer_;
1474 cricket::FakeVideoMediaChannel* video_channel_;
1475 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001476 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001477 // The following flags affect options created for CreateOffer/CreateAnswer.
1478 bool send_stream_1_ = false;
1479 bool send_stream_2_ = false;
1480 bool send_audio_ = false;
1481 bool send_video_ = false;
1482 rtc::scoped_refptr<DataChannel> data_channel_;
1483 // Last values received from data channel creation signal.
1484 std::string last_data_channel_label_;
1485 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486};
1487
Henrik Boström87713d02015-08-25 09:53:21 +02001488TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1489 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001490 // SDES is disabled when DTLS is on.
1491 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492}
1493
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001494TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001495 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001496 // SDES is required if DTLS is off.
1497 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001498}
1499
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1501 TestSessionCandidatesWithBundleRtcpMux(false, false);
1502}
1503
1504// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1505// with rtcp-mux and/or bundle.
1506TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1507 TestSessionCandidatesWithBundleRtcpMux(false, true);
1508}
1509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1511 TestSessionCandidatesWithBundleRtcpMux(true, true);
1512}
1513
1514TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001515 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1516 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001517 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001518 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 InitiateCall();
1520 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1521 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1522 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1523}
1524
1525TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001526 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1527 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001528 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001529 rtc::FP_UDP,
1530 rtc::FD_ANY,
1531 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001532 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001533 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001535 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1537 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1538 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1539}
1540
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001541// Test session delivers no candidates gathered when constraint set to "none".
1542TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1543 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001545 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001546 InitiateCall();
1547 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1548 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1549 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1550}
1551
1552// Test session delivers only relay candidates gathered when constaint set to
1553// "relay".
1554TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1555 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1556 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001558 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001559 InitiateCall();
1560 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1561 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1562 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1563 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1564 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1565 observer_.mline_0_candidates_[i].type());
1566 }
1567 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1568 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1569 observer_.mline_1_candidates_[i].type());
1570 }
1571}
1572
1573// Test session delivers all candidates gathered when constaint set to "all".
1574TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1575 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001576 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001577 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001578 InitiateCall();
1579 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1580 // Host + STUN. By default allocator is disabled to gather relay candidates.
1581 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1582 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1583}
1584
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001585TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001586 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001587 SessionDescriptionInterface* offer = NULL;
1588 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1589 std::string unknown_action;
1590 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1591 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1592}
1593
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594// Test creating offers and receive answers and make sure the
1595// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001597 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001598 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001599 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 const std::string session_id_orig = offer->session_id();
1601 const std::string session_version_orig = offer->session_version();
1602 SetLocalDescriptionWithoutError(offer);
1603
deadbeefab9b2d12015-10-14 11:33:11 -07001604 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 SessionDescriptionInterface* answer =
1606 CreateRemoteAnswer(session_->local_description());
1607 SetRemoteDescriptionWithoutError(answer);
1608
1609 video_channel_ = media_engine_->GetVideoChannel(0);
1610 voice_channel_ = media_engine_->GetVoiceChannel(0);
1611
1612 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1613 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1614
1615 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1616 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1617
1618 ASSERT_EQ(1u, video_channel_->send_streams().size());
1619 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1620 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1621 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1622
1623 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001624 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001625 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626
1627 // Verify the session id is the same and the session version is
1628 // increased.
1629 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001630 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1631 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632
1633 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001634 EXPECT_EQ(0u, video_channel_->send_streams().size());
1635 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636
deadbeefab9b2d12015-10-14 11:33:11 -07001637 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 answer = CreateRemoteAnswer(session_->local_description());
1639 SetRemoteDescriptionWithoutError(answer);
1640
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 // Make sure the receive streams have not changed.
1642 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1643 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1644 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1645 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1646}
1647
1648// Test receiving offers and creating answers and make sure the
1649// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001650TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001651 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001654 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 SetRemoteDescriptionWithoutError(offer);
1656
deadbeefab9b2d12015-10-14 11:33:11 -07001657 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001658 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001659 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 SetLocalDescriptionWithoutError(answer);
1661
1662 const std::string session_id_orig = answer->session_id();
1663 const std::string session_version_orig = answer->session_version();
1664
1665 video_channel_ = media_engine_->GetVideoChannel(0);
1666 voice_channel_ = media_engine_->GetVoiceChannel(0);
1667
1668 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1669 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1670
1671 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1672 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1673
1674 ASSERT_EQ(1u, video_channel_->send_streams().size());
1675 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1676 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1677 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1678
deadbeefab9b2d12015-10-14 11:33:11 -07001679 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001680 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 SetRemoteDescriptionWithoutError(offer);
1682
1683 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001684 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001685 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686
1687 // Verify the session id is the same and the session version is
1688 // increased.
1689 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001690 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1691 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 SetLocalDescriptionWithoutError(answer);
1693
1694 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1695 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1696 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1697 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1698 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1699 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1700
1701 // Make sure we have no send streams.
1702 EXPECT_EQ(0u, video_channel_->send_streams().size());
1703 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1704}
1705
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001706TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001707 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001708 media_engine_->set_fail_create_channel(true);
1709
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001710 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001711 ASSERT_TRUE(offer != NULL);
1712 // SetRemoteDescription and SetLocalDescription will take the ownership of
1713 // the offer.
1714 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001715 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001716 ASSERT_TRUE(offer != NULL);
1717 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1718}
1719
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720//
1721// Tests for creating/setting SDP under different SDES/DTLS polices:
1722//
1723// --DTLS off and SDES on
1724// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1725// set local/remote offer/answer with crypto --> success
1726// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1727// failure
1728// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1729// failure
1730// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1731// failure
1732//
1733// --DTLS on and SDES off
1734// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1735// set local/remote offer/answer with DTLS fingerprint --> success
1736// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1737// fingerprint --> failure
1738// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1739// --> failure
1740// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1741// --> failure
1742//
1743// --Encryption disabled: DTLS off and SDES off
1744// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1745// answer without SDES or DTLS --> success
1746// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1747// answer without SDES or DTLS --> success
1748//
1749
1750// Test that we return a failure when applying a remote/local offer that doesn't
1751// have cryptos enabled when DTLS is off.
1752TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001755 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 JsepSessionDescription* offer = CreateRemoteOffer(
1757 options, cricket::SEC_DISABLED);
1758 ASSERT_TRUE(offer != NULL);
1759 VerifyNoCryptoParams(offer->description(), false);
1760 // SetRemoteDescription and SetLocalDescription will take the ownership of
1761 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001762 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1764 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766}
1767
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768// Test that we return a failure when applying a local answer that doesn't have
1769// cryptos enabled when DTLS is off.
1770TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001771 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 SessionDescriptionInterface* offer = NULL;
1773 SessionDescriptionInterface* answer = NULL;
1774 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1775 // SetRemoteDescription and SetLocalDescription will take the ownership of
1776 // the offer.
1777 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779}
1780
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001781// Test we will return fail when apply an remote answer that doesn't have
1782// crypto enabled when DTLS is off.
1783TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 SessionDescriptionInterface* offer = NULL;
1786 SessionDescriptionInterface* answer = NULL;
1787 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1788 // SetRemoteDescription and SetLocalDescription will take the ownership of
1789 // the offer.
1790 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792}
1793
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1795// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001796TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001797 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001798 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001799 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 SetFactoryDtlsSrtp();
1801 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001802 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803 JsepSessionDescription* offer =
1804 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 ASSERT_TRUE(offer != NULL);
1806 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808
1809 // SetRemoteDescription will take the ownership of the offer.
1810 SetRemoteDescriptionWithoutError(offer);
1811
1812 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001813 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 ASSERT_TRUE(answer != NULL);
1815 VerifyFingerprintStatus(answer->description(), true);
1816 // Check that we don't have an a=crypto line in the answer.
1817 VerifyNoCryptoParams(answer->description(), true);
1818
1819 // Now set the local description, which should work, even without a=crypto.
1820 SetLocalDescriptionWithoutError(answer);
1821}
1822
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1824// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001825TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001826 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001827 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001828 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001829 SetFactoryDtlsSrtp();
1830
1831 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001832 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 ASSERT_TRUE(offer != NULL);
1834 VerifyFingerprintStatus(offer->description(), true);
1835 // Check that we don't have an a=crypto line in the offer.
1836 VerifyNoCryptoParams(offer->description(), true);
1837
1838 // Now set the local description, which should work, even without a=crypto.
1839 SetLocalDescriptionWithoutError(offer);
1840
1841 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001842 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001843 JsepSessionDescription* answer =
1844 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1845 ASSERT_TRUE(answer != NULL);
1846 VerifyFingerprintStatus(answer->description(), true);
1847 VerifyNoCryptoParams(answer->description(), true);
1848
1849 // SetRemoteDescription will take the ownership of the answer.
1850 SetRemoteDescriptionWithoutError(answer);
1851}
1852
1853// Test that if we support DTLS and the other side didn't offer a fingerprint,
1854// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001855TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001856 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001857 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001859 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 JsepSessionDescription* offer = CreateRemoteOffer(
1862 options, cricket::SEC_REQUIRED);
1863 ASSERT_TRUE(offer != NULL);
1864 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867 // SetRemoteDescription will take the ownership of the offer.
1868 SetRemoteDescriptionOfferExpectError(
1869 kSdpWithoutDtlsFingerprint, offer);
1870
1871 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1872 // SetLocalDescription will take the ownership of the offer.
1873 SetLocalDescriptionOfferExpectError(
1874 kSdpWithoutDtlsFingerprint, offer);
1875}
1876
1877// Test that we return a failure when applying a local answer that doesn't have
1878// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001879TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001880 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001881 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 SessionDescriptionInterface* offer = NULL;
1883 SessionDescriptionInterface* answer = NULL;
1884 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1885
1886 // SetRemoteDescription and SetLocalDescription will take the ownership of
1887 // the offer and answer.
1888 SetRemoteDescriptionWithoutError(offer);
1889 SetLocalDescriptionAnswerExpectError(
1890 kSdpWithoutDtlsFingerprint, answer);
1891}
1892
1893// Test that we return a failure when applying a remote answer that doesn't have
1894// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001895TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001896 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001897 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001898 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001900 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001901 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1902 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001904 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905
1906 // SetRemoteDescription and SetLocalDescription will take the ownership of
1907 // the offer and answer.
1908 SetLocalDescriptionWithoutError(offer);
1909 SetRemoteDescriptionAnswerExpectError(
1910 kSdpWithoutDtlsFingerprint, answer);
1911}
1912
1913// Test that we create a local offer without SDES or DTLS and accept a remote
1914// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001915TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001916 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001918 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919
1920 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001921 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 ASSERT_TRUE(offer != NULL);
1923 VerifyFingerprintStatus(offer->description(), false);
1924 // Check that we don't have an a=crypto line in the offer.
1925 VerifyNoCryptoParams(offer->description(), false);
1926
1927 // Now set the local description, which should work, even without a=crypto.
1928 SetLocalDescriptionWithoutError(offer);
1929
1930 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001931 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001932 JsepSessionDescription* answer =
1933 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1934 ASSERT_TRUE(answer != NULL);
1935 VerifyFingerprintStatus(answer->description(), false);
1936 VerifyNoCryptoParams(answer->description(), false);
1937
1938 // SetRemoteDescription will take the ownership of the answer.
1939 SetRemoteDescriptionWithoutError(answer);
1940}
1941
1942// Test that we create a local answer without SDES or DTLS and accept a remote
1943// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001944TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001946 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001947
1948 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001949 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001950 JsepSessionDescription* offer =
1951 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1952 ASSERT_TRUE(offer != NULL);
1953 VerifyFingerprintStatus(offer->description(), false);
1954 VerifyNoCryptoParams(offer->description(), false);
1955
1956 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 SetRemoteDescriptionWithoutError(offer);
1958
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001959 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001960 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 ASSERT_TRUE(answer != NULL);
1962 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963 // Check that we don't have an a=crypto line in the answer.
1964 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 SetLocalDescriptionWithoutError(answer);
1968}
1969
1970TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001971 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001972 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001974 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 SetLocalDescriptionWithoutError(offer);
1976
1977 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001978 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 SetLocalDescriptionWithoutError(offer2);
1980}
1981
1982TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001983 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001984 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 SetRemoteDescriptionWithoutError(offer);
1988
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001989 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 SetRemoteDescriptionWithoutError(offer2);
1991}
1992
1993TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
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 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001999 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2000 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001}
2002
2003TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002004 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002005 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002006 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002008 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002009 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002010 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011}
2012
2013TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002014 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002015 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002017 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018
2019 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002020 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002022 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023
deadbeefab9b2d12015-10-14 11:33:11 -07002024 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002026 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2028
deadbeefd59daf82015-10-14 15:02:44 -07002029 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030
deadbeefab9b2d12015-10-14 11:33:11 -07002031 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002032 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002033 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034}
2035
2036TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002037 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002039 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
2042 JsepSessionDescription* pranswer =
2043 CreateRemoteAnswer(session_->local_description());
2044 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2045
2046 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002047 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 JsepSessionDescription* pranswer2 =
2051 CreateRemoteAnswer(session_->local_description());
2052 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2053
2054 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002055 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 SessionDescriptionInterface* answer =
2059 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002060 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061}
2062
2063TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002064 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2067
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 SessionDescriptionInterface* answer =
2069 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002070 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2071 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
2074TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002075 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002076 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002077 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2078
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 SessionDescriptionInterface* answer =
2080 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002081 SetRemoteDescriptionAnswerExpectError(
2082 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083}
2084
2085TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002086 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002087 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088
2089 cricket::Candidate candidate;
2090 candidate.set_component(1);
2091 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2092
deadbeefd59daf82015-10-14 15:02:44 -07002093 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2095
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002096 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002098
2099 // Fail since we have not set a remote description.
2100 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
2102 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2103 session_->local_description());
2104 SetRemoteDescriptionWithoutError(answer);
2105
deadbeefd59daf82015-10-14 15:02:44 -07002106 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2107 candidate.set_component(2);
2108 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2109 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2110
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 // Verifying the candidates are copied properly from internal vector.
2112 const SessionDescriptionInterface* remote_desc =
2113 session_->remote_description();
2114 ASSERT_TRUE(remote_desc != NULL);
2115 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2116 const IceCandidateCollection* candidates =
2117 remote_desc->candidates(kMediaContentIndex0);
2118 ASSERT_EQ(2u, candidates->count());
2119 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2120 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2121 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2122 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2123
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002124 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2125 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 candidate.set_component(2);
2127 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2128 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002129 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2132 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2133}
2134
2135// Test that a remote candidate is added to the remote session description and
2136// that it is retained if the remote session description is changed.
2137TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002138 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 cricket::Candidate candidate1;
2140 candidate1.set_component(1);
2141 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2142 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002143 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 CreateAndSetRemoteOfferAndLocalAnswer();
2145
2146 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2147 const SessionDescriptionInterface* remote_desc =
2148 session_->remote_description();
2149 ASSERT_TRUE(remote_desc != NULL);
2150 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2151 const IceCandidateCollection* candidates =
2152 remote_desc->candidates(kMediaContentIndex0);
2153 ASSERT_EQ(1u, candidates->count());
2154 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2155
2156 // Update the RemoteSessionDescription with a new session description and
2157 // a candidate and check that the new remote session description contains both
2158 // candidates.
2159 SessionDescriptionInterface* offer = CreateRemoteOffer();
2160 cricket::Candidate candidate2;
2161 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2162 candidate2);
2163 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2164 SetRemoteDescriptionWithoutError(offer);
2165
2166 remote_desc = session_->remote_description();
2167 ASSERT_TRUE(remote_desc != NULL);
2168 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2169 candidates = remote_desc->candidates(kMediaContentIndex0);
2170 ASSERT_EQ(2u, candidates->count());
2171 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2172 // Username and password have be updated with the TransportInfo of the
2173 // SessionDescription, won't be equal to the original one.
2174 candidate2.set_username(candidates->at(0)->candidate().username());
2175 candidate2.set_password(candidates->at(0)->candidate().password());
2176 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2177 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2178 // No need to verify the username and password.
2179 candidate1.set_username(candidates->at(1)->candidate().username());
2180 candidate1.set_password(candidates->at(1)->candidate().password());
2181 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2182
2183 // Test that the candidate is ignored if we can add the same candidate again.
2184 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2185}
2186
2187// Test that local candidates are added to the local session description and
2188// that they are retained if the local session description is changed.
2189TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002190 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002191 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002192 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 CreateAndSetRemoteOfferAndLocalAnswer();
2194
2195 const SessionDescriptionInterface* local_desc = session_->local_description();
2196 const IceCandidateCollection* candidates =
2197 local_desc->candidates(kMediaContentIndex0);
2198 ASSERT_TRUE(candidates != NULL);
2199 EXPECT_EQ(0u, candidates->count());
2200
2201 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2202
2203 local_desc = session_->local_description();
2204 candidates = local_desc->candidates(kMediaContentIndex0);
2205 ASSERT_TRUE(candidates != NULL);
2206 EXPECT_LT(0u, candidates->count());
2207 candidates = local_desc->candidates(1);
2208 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002209 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210
2211 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002212 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 CreateAndSetRemoteOfferAndLocalAnswer();
2214
2215 local_desc = session_->local_description();
2216 candidates = local_desc->candidates(kMediaContentIndex0);
2217 ASSERT_TRUE(candidates != NULL);
2218 EXPECT_LT(0u, candidates->count());
2219 candidates = local_desc->candidates(1);
2220 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002221 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222}
2223
2224// Test that we can set a remote session description with remote candidates.
2225TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002226 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227
2228 cricket::Candidate candidate1;
2229 candidate1.set_component(1);
2230 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2231 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002232 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002233 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234
2235 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2236 SetRemoteDescriptionWithoutError(offer);
2237
2238 const SessionDescriptionInterface* remote_desc =
2239 session_->remote_description();
2240 ASSERT_TRUE(remote_desc != NULL);
2241 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2242 const IceCandidateCollection* candidates =
2243 remote_desc->candidates(kMediaContentIndex0);
2244 ASSERT_EQ(1u, candidates->count());
2245 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2246
wu@webrtc.org91053e72013-08-10 07:18:04 +00002247 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 SetLocalDescriptionWithoutError(answer);
2249}
2250
2251// Test that offers and answers contains ice candidates when Ice candidates have
2252// been gathered.
2253TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002254 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002255 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002256 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 // Ice is started but candidates are not provided until SetLocalDescription
2258 // is called.
2259 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2260 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2261 CreateAndSetRemoteOfferAndLocalAnswer();
2262 // Wait until at least one local candidate has been collected.
2263 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2264 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002266 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2267
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2269 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270
2271 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2272 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002273 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2275 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 SetLocalDescriptionWithoutError(answer);
2277}
2278
2279// Verifies TransportProxy and media channels are created with content names
2280// present in the SessionDescription.
2281TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002282 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002283 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002284 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285
2286 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002287 // "video". Goal is to modify these content names and verify transport
2288 // channels
2289 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 // present in SDP.
2291 std::string sdp;
2292 EXPECT_TRUE(offer->ToString(&sdp));
2293 const std::string kAudioMid = "a=mid:audio";
2294 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2295 const std::string kVideoMid = "a=mid:video";
2296 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2297
2298 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002299 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 kAudioMidReplaceStr.c_str(),
2301 kAudioMidReplaceStr.length(),
2302 &sdp);
2303 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002304 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 kVideoMidReplaceStr.c_str(),
2306 kVideoMidReplaceStr.length(),
2307 &sdp);
2308
2309 SessionDescriptionInterface* modified_offer =
2310 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2311
2312 SetRemoteDescriptionWithoutError(modified_offer);
2313
2314 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002315 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 SetLocalDescriptionWithoutError(answer);
2317
deadbeefcbecd352015-09-23 11:50:27 -07002318 cricket::TransportChannel* voice_transport_channel =
2319 session_->voice_rtp_transport_channel();
2320 EXPECT_TRUE(voice_transport_channel != NULL);
2321 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2322 cricket::TransportChannel* video_transport_channel =
2323 session_->video_rtp_transport_channel();
2324 EXPECT_TRUE(video_transport_channel != NULL);
2325 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2327 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2328}
2329
2330// Test that an offer contains the correct media content descriptions based on
2331// the send streams when no constraints have been set.
2332TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002333 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002334 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 ASSERT_TRUE(offer != NULL);
2337 const cricket::ContentInfo* content =
2338 cricket::GetFirstAudioContent(offer->description());
2339 EXPECT_TRUE(content != NULL);
2340 content = cricket::GetFirstVideoContent(offer->description());
2341 EXPECT_TRUE(content == NULL);
2342}
2343
2344// Test that an offer contains the correct media content descriptions based on
2345// the send streams when no constraints have been set.
2346TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002347 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002349 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002350 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2351
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 const cricket::ContentInfo* content =
2353 cricket::GetFirstAudioContent(offer->description());
2354 EXPECT_TRUE(content != NULL);
2355 content = cricket::GetFirstVideoContent(offer->description());
2356 EXPECT_TRUE(content == NULL);
2357
2358 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002359 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002360 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 content = cricket::GetFirstAudioContent(offer->description());
2362 EXPECT_TRUE(content != NULL);
2363 content = cricket::GetFirstVideoContent(offer->description());
2364 EXPECT_TRUE(content != NULL);
2365}
2366
2367// Test that an offer contains no media content descriptions if
2368// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2369TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002370 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002371 PeerConnectionInterface::RTCOfferAnswerOptions options;
2372 options.offer_to_receive_audio = 0;
2373 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002375 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002376 CreateOffer(options));
2377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 ASSERT_TRUE(offer != NULL);
2379 const cricket::ContentInfo* content =
2380 cricket::GetFirstAudioContent(offer->description());
2381 EXPECT_TRUE(content == NULL);
2382 content = cricket::GetFirstVideoContent(offer->description());
2383 EXPECT_TRUE(content == NULL);
2384}
2385
2386// Test that an offer contains only audio media content descriptions if
2387// kOfferToReceiveAudio constraints are set to true.
2388TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002389 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002390 PeerConnectionInterface::RTCOfferAnswerOptions options;
2391 options.offer_to_receive_audio =
2392 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2393
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002394 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002395 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396
2397 const cricket::ContentInfo* content =
2398 cricket::GetFirstAudioContent(offer->description());
2399 EXPECT_TRUE(content != NULL);
2400 content = cricket::GetFirstVideoContent(offer->description());
2401 EXPECT_TRUE(content == NULL);
2402}
2403
2404// Test that an offer contains audio and video media content descriptions if
2405// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2406TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002407 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002409 PeerConnectionInterface::RTCOfferAnswerOptions options;
2410 options.offer_to_receive_audio =
2411 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2412 options.offer_to_receive_video =
2413 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2414
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002415 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002416 CreateOffer(options));
2417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 const cricket::ContentInfo* content =
2419 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002420 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422 content = cricket::GetFirstVideoContent(offer->description());
2423 EXPECT_TRUE(content != NULL);
2424
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002425 // Sets constraints to false and verifies that audio/video contents are
2426 // removed.
2427 options.offer_to_receive_audio = 0;
2428 options.offer_to_receive_video = 0;
2429 offer.reset(CreateOffer(options));
2430
2431 content = cricket::GetFirstAudioContent(offer->description());
2432 EXPECT_TRUE(content == NULL);
2433 content = cricket::GetFirstVideoContent(offer->description());
2434 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435}
2436
2437// Test that an answer can not be created if the last remote description is not
2438// an offer.
2439TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002440 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002441 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 SetLocalDescriptionWithoutError(offer);
2443 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2444 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002445 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446}
2447
2448// Test that an answer contains the correct media content descriptions when no
2449// constraints have been set.
2450TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002451 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002453 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002455 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002456 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 const cricket::ContentInfo* content =
2458 cricket::GetFirstAudioContent(answer->description());
2459 ASSERT_TRUE(content != NULL);
2460 EXPECT_FALSE(content->rejected);
2461
2462 content = cricket::GetFirstVideoContent(answer->description());
2463 ASSERT_TRUE(content != NULL);
2464 EXPECT_FALSE(content->rejected);
2465}
2466
2467// Test that an answer contains the correct media content descriptions when no
2468// constraints have been set and the offer only contain audio.
2469TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002470 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 // Create a remote offer with audio only.
2472 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002473
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002474 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 CreateRemoteOffer(options));
2476 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2477 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2478
2479 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002480 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002481 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 const cricket::ContentInfo* content =
2483 cricket::GetFirstAudioContent(answer->description());
2484 ASSERT_TRUE(content != NULL);
2485 EXPECT_FALSE(content->rejected);
2486
2487 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2488}
2489
2490// Test that an answer contains the correct media content descriptions when no
2491// constraints have been set.
2492TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002493 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002495 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 SetRemoteDescriptionWithoutError(offer.release());
2497 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002498 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002499 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002500 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 const cricket::ContentInfo* content =
2502 cricket::GetFirstAudioContent(answer->description());
2503 ASSERT_TRUE(content != NULL);
2504 EXPECT_FALSE(content->rejected);
2505
2506 content = cricket::GetFirstVideoContent(answer->description());
2507 ASSERT_TRUE(content != NULL);
2508 EXPECT_FALSE(content->rejected);
2509}
2510
2511// Test that an answer contains the correct media content descriptions when
2512// constraints have been set but no stream is sent.
2513TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002514 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002516 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 SetRemoteDescriptionWithoutError(offer.release());
2518
2519 webrtc::FakeConstraints constraints_no_receive;
2520 constraints_no_receive.SetMandatoryReceiveAudio(false);
2521 constraints_no_receive.SetMandatoryReceiveVideo(false);
2522
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002523 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002524 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(answer->description());
2527 ASSERT_TRUE(content != NULL);
2528 EXPECT_TRUE(content->rejected);
2529
2530 content = cricket::GetFirstVideoContent(answer->description());
2531 ASSERT_TRUE(content != NULL);
2532 EXPECT_TRUE(content->rejected);
2533}
2534
2535// Test that an answer contains the correct media content descriptions when
2536// constraints have been set and streams are sent.
2537TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002540 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 SetRemoteDescriptionWithoutError(offer.release());
2542
2543 webrtc::FakeConstraints constraints_no_receive;
2544 constraints_no_receive.SetMandatoryReceiveAudio(false);
2545 constraints_no_receive.SetMandatoryReceiveVideo(false);
2546
2547 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002548 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002549 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002550 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551
2552 // TODO(perkj): Should the direction be set to SEND_ONLY?
2553 const cricket::ContentInfo* content =
2554 cricket::GetFirstAudioContent(answer->description());
2555 ASSERT_TRUE(content != NULL);
2556 EXPECT_FALSE(content->rejected);
2557
2558 // TODO(perkj): Should the direction be set to SEND_ONLY?
2559 content = cricket::GetFirstVideoContent(answer->description());
2560 ASSERT_TRUE(content != NULL);
2561 EXPECT_FALSE(content->rejected);
2562}
2563
2564TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2565 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002566 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002567 PeerConnectionInterface::RTCOfferAnswerOptions options;
2568 options.offer_to_receive_audio =
2569 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2570 options.voice_activity_detection = false;
2571
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002572 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002573 CreateOffer(options));
2574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 const cricket::ContentInfo* content =
2576 cricket::GetFirstAudioContent(offer->description());
2577 EXPECT_TRUE(content != NULL);
2578 EXPECT_TRUE(VerifyNoCNCodecs(content));
2579}
2580
2581TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2582 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002583 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002585 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 SetRemoteDescriptionWithoutError(offer.release());
2587
2588 webrtc::FakeConstraints constraints;
2589 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002590 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002591 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 const cricket::ContentInfo* content =
2593 cricket::GetFirstAudioContent(answer->description());
2594 ASSERT_TRUE(content != NULL);
2595 EXPECT_TRUE(VerifyNoCNCodecs(content));
2596}
2597
2598// This test verifies the call setup when remote answer with audio only and
2599// later updates with video.
2600TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002601 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2603 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2604
deadbeefab9b2d12015-10-14 11:33:11 -07002605 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002606 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607
2608 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2610
2611 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2612 // and answer;
2613 SetLocalDescriptionWithoutError(offer);
2614 SetRemoteDescriptionWithoutError(answer);
2615
2616 video_channel_ = media_engine_->GetVideoChannel(0);
2617 voice_channel_ = media_engine_->GetVoiceChannel(0);
2618
2619 ASSERT_TRUE(video_channel_ == NULL);
2620
2621 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2622 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2623 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2624
2625 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002626 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 CreateAndSetRemoteOfferAndLocalAnswer();
2628
2629 video_channel_ = media_engine_->GetVideoChannel(0);
2630 voice_channel_ = media_engine_->GetVoiceChannel(0);
2631
2632 ASSERT_TRUE(video_channel_ != NULL);
2633 ASSERT_TRUE(voice_channel_ != NULL);
2634
2635 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2636 ASSERT_EQ(1u, video_channel_->send_streams().size());
2637 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2638 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2639 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2640 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2641 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2642 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2643
2644 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002645 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 CreateAndSetRemoteOfferAndLocalAnswer();
2647
2648 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2649 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2650 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2651 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2652 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2653}
2654
2655// This test verifies the call setup when remote answer with video only and
2656// later updates with audio.
2657TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002658 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2660 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002661 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002662 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663
2664 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002665 options.recv_audio = false;
2666 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2668 offer, options, cricket::SEC_ENABLED);
2669
2670 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2671 // and answer.
2672 SetLocalDescriptionWithoutError(offer);
2673 SetRemoteDescriptionWithoutError(answer);
2674
2675 video_channel_ = media_engine_->GetVideoChannel(0);
2676 voice_channel_ = media_engine_->GetVoiceChannel(0);
2677
2678 ASSERT_TRUE(voice_channel_ == NULL);
2679 ASSERT_TRUE(video_channel_ != NULL);
2680
2681 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2682 ASSERT_EQ(1u, video_channel_->send_streams().size());
2683 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2684
2685 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002686 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 CreateAndSetRemoteOfferAndLocalAnswer();
2688
2689 voice_channel_ = media_engine_->GetVoiceChannel(0);
2690 ASSERT_TRUE(voice_channel_ != NULL);
2691
2692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2693 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2694 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2695 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2696
2697 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002698 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 CreateAndSetRemoteOfferAndLocalAnswer();
2700
2701 video_channel_ = media_engine_->GetVideoChannel(0);
2702 voice_channel_ = media_engine_->GetVoiceChannel(0);
2703
2704 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2705 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2706 ASSERT_EQ(1u, video_channel_->send_streams().size());
2707 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2708}
2709
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002711 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002712 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002713 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 VerifyCryptoParams(offer->description());
2715 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002716 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 VerifyCryptoParams(answer->description());
2718}
2719
2720TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002721 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002722 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002723 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002724 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 VerifyNoCryptoParams(offer->description(), false);
2726}
2727
2728TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002729 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 VerifyAnswerFromNonCryptoOffer();
2731}
2732
2733TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002734 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 VerifyAnswerFromCryptoOffer();
2736}
2737
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002738// This test verifies that setLocalDescription fails if
2739// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2740TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002741 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002742 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002743 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2744
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002745 std::string sdp;
2746 RemoveIceUfragPwdLines(offer.get(), &sdp);
2747 SessionDescriptionInterface* modified_offer =
2748 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002749 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002750}
2751
2752// This test verifies that setRemoteDescription fails if
2753// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2754TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002755 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002756 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002757 std::string sdp;
2758 RemoveIceUfragPwdLines(offer.get(), &sdp);
2759 SessionDescriptionInterface* modified_offer =
2760 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002761 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002762}
2763
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002764// This test verifies that setLocalDescription fails if local offer has
2765// too short ice ufrag and pwd strings.
2766TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002767 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002768 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002769 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2770
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002771 std::string sdp;
2772 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2773 // recommended values of 4 and 22 bytes respectively.
2774 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2775 SessionDescriptionInterface* modified_offer =
2776 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2777 std::string error;
2778 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2779
2780 // Test with string greater than 256.
2781 sdp.clear();
2782 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2783 &sdp);
2784 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2785 NULL);
2786 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2787}
2788
2789// This test verifies that setRemoteDescription fails if remote offer has
2790// too short ice ufrag and pwd strings.
2791TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002792 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002793 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002794 std::string sdp;
2795 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2796 // recommended values of 4 and 22 bytes respectively.
2797 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2798 SessionDescriptionInterface* modified_offer =
2799 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2800 std::string error;
2801 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2802
2803 sdp.clear();
2804 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2805 &sdp);
2806 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2807 NULL);
2808 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2809}
2810
honghaiz503726c2015-07-31 12:37:38 -07002811// Test that if the remote description indicates the peer requested ICE restart
2812// (via a new ufrag or pwd), the old ICE candidates are not copied,
2813// and vice versa.
2814TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2815 Init();
2816 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2817
2818 // Create the first offer.
2819 std::string sdp;
2820 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2821 "abcdefghijklmnopqrstuvwx", &sdp);
2822 SessionDescriptionInterface* offer1 =
2823 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2824 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2825 0, "", "", "relay", 0, "");
2826 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2827 candidate1);
2828 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2829 SetRemoteDescriptionWithoutError(offer1);
2830 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2831
2832 // The second offer has the same ufrag and pwd but different address.
2833 sdp.clear();
2834 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2835 "abcdefghijklmnopqrstuvwx", &sdp);
2836 SessionDescriptionInterface* offer2 =
2837 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2838 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2839 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2840 candidate1);
2841 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2842 SetRemoteDescriptionWithoutError(offer2);
2843 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2844
2845 // The third offer has a different ufrag and different address.
2846 sdp.clear();
2847 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2848 "abcdefghijklmnopqrstuvwx", &sdp);
2849 SessionDescriptionInterface* offer3 =
2850 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2851 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2852 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2853 candidate1);
2854 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2855 SetRemoteDescriptionWithoutError(offer3);
2856 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2857
2858 // The fourth offer has no candidate but a different ufrag/pwd.
2859 sdp.clear();
2860 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2861 "abcdefghijklmnopqrstuvyz", &sdp);
2862 SessionDescriptionInterface* offer4 =
2863 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2864 SetRemoteDescriptionWithoutError(offer4);
2865 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2866}
2867
Donald Curtisd4f769d2015-05-28 09:48:21 -07002868// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002869// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002870TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2871 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2872
2873 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002874 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002875
2876 PeerConnectionInterface::RTCOfferAnswerOptions options;
2877 options.use_rtp_mux = true;
2878
2879 SessionDescriptionInterface* offer = CreateRemoteOffer();
2880 SetRemoteDescriptionWithoutError(offer);
2881
2882 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2883 SetLocalDescriptionWithoutError(answer);
2884
deadbeefcbecd352015-09-23 11:50:27 -07002885 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2886 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002887
deadbeefcbecd352015-09-23 11:50:27 -07002888 cricket::BaseChannel* voice_channel = session_->voice_channel();
2889 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002890
2891 // Checks if one of the transport channels contains a connection using a given
2892 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002893 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002894 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002895 session_->GetChannelTransportStats(voice_channel, &stats);
2896 for (auto& kv : stats.transport_stats) {
2897 for (auto& chan_stat : kv.second.channel_stats) {
2898 for (auto& conn_info : chan_stat.connection_infos) {
2899 if (conn_info.remote_candidate.address().port() == port) {
2900 return true;
2901 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002902 }
2903 }
2904 }
2905 return false;
2906 };
2907
2908 EXPECT_FALSE(connection_with_remote_port(5000));
2909 EXPECT_FALSE(connection_with_remote_port(5001));
2910 EXPECT_FALSE(connection_with_remote_port(6000));
2911
2912 // The way the *_WAIT checks work is they only wait if the condition fails,
2913 // which does not help in the case where state is not changing. This is
2914 // problematic in this test since we want to verify that adding a video
2915 // candidate does _not_ change state. So we interleave candidates and assume
2916 // that messages are executed in the order they were posted.
2917
2918 // First audio candidate.
2919 cricket::Candidate candidate0;
2920 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2921 candidate0.set_component(1);
2922 candidate0.set_protocol("udp");
2923 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2924 candidate0);
2925 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2926
2927 // Video candidate.
2928 cricket::Candidate candidate1;
2929 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2930 candidate1.set_component(1);
2931 candidate1.set_protocol("udp");
2932 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2933 candidate1);
2934 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2935
2936 // Second audio candidate.
2937 cricket::Candidate candidate2;
2938 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2939 candidate2.set_component(1);
2940 candidate2.set_protocol("udp");
2941 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2942 candidate2);
2943 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2944
2945 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2946 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2947
2948 // No need here for a _WAIT check since we are checking that state hasn't
2949 // changed: if this is false we would be doing waits for nothing and if this
2950 // is true then there will be no messages processed anyways.
2951 EXPECT_FALSE(connection_with_remote_port(6000));
2952}
2953
deadbeefcbecd352015-09-23 11:50:27 -07002954// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002955TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2956 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002957 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002958
2959 PeerConnectionInterface::RTCOfferAnswerOptions options;
2960 options.use_rtp_mux = true;
2961
2962 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002964
deadbeefcbecd352015-09-23 11:50:27 -07002965 EXPECT_NE(session_->voice_rtp_transport_channel(),
2966 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002967
deadbeefab9b2d12015-10-14 11:33:11 -07002968 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002969 SessionDescriptionInterface* answer =
2970 CreateRemoteAnswer(session_->local_description());
2971 SetRemoteDescriptionWithoutError(answer);
2972
deadbeefcbecd352015-09-23 11:50:27 -07002973 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2974 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002975}
2976
deadbeefcbecd352015-09-23 11:50:27 -07002977// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002978TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2979 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002980 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002981
Donald Curtis0e209b02015-03-24 09:29:54 -07002982 PeerConnectionInterface::RTCOfferAnswerOptions options;
2983 options.use_rtp_mux = true;
2984
2985 SessionDescriptionInterface* offer = CreateOffer(options);
2986 SetLocalDescriptionWithoutError(offer);
2987
deadbeefcbecd352015-09-23 11:50:27 -07002988 EXPECT_NE(session_->voice_rtp_transport_channel(),
2989 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002990
deadbeefab9b2d12015-10-14 11:33:11 -07002991 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002992
2993 // Remove BUNDLE from the answer.
2994 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2995 CreateRemoteAnswer(session_->local_description()));
2996 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2997 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2998 JsepSessionDescription* modified_answer =
2999 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3000 modified_answer->Initialize(answer_copy, "1", "1");
3001 SetRemoteDescriptionWithoutError(modified_answer); //
3002
deadbeefcbecd352015-09-23 11:50:27 -07003003 EXPECT_NE(session_->voice_rtp_transport_channel(),
3004 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003005}
3006
3007// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3008TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3009 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003010 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003011
3012 PeerConnectionInterface::RTCOfferAnswerOptions options;
3013 options.use_rtp_mux = true;
3014
3015 SessionDescriptionInterface* offer = CreateOffer(options);
3016 SetLocalDescriptionWithoutError(offer);
3017
deadbeefcbecd352015-09-23 11:50:27 -07003018 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3019 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003020
deadbeefab9b2d12015-10-14 11:33:11 -07003021 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003022 SessionDescriptionInterface* answer =
3023 CreateRemoteAnswer(session_->local_description());
3024 SetRemoteDescriptionWithoutError(answer);
3025
deadbeefcbecd352015-09-23 11:50:27 -07003026 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3027 session_->video_rtp_transport_channel());
3028}
3029
3030// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3031// audio content in the answer.
3032TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3033 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003034 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003035
3036 PeerConnectionInterface::RTCOfferAnswerOptions options;
3037 options.use_rtp_mux = true;
3038
3039 SessionDescriptionInterface* offer = CreateOffer(options);
3040 SetLocalDescriptionWithoutError(offer);
3041
3042 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3043 session_->video_rtp_transport_channel());
3044
deadbeefab9b2d12015-10-14 11:33:11 -07003045 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003046 cricket::MediaSessionOptions recv_options;
3047 recv_options.recv_audio = false;
3048 recv_options.recv_video = true;
3049 SessionDescriptionInterface* answer =
3050 CreateRemoteAnswer(session_->local_description(), recv_options);
3051 SetRemoteDescriptionWithoutError(answer);
3052
deadbeefd59daf82015-10-14 15:02:44 -07003053 EXPECT_TRUE(nullptr == session_->voice_channel());
3054 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003055
deadbeefd59daf82015-10-14 15:02:44 -07003056 session_->Close();
3057 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3058 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3059 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3060 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003061}
3062
3063// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3064TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3065 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003066 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003067
Donald Curtis0e209b02015-03-24 09:29:54 -07003068 PeerConnectionInterface::RTCOfferAnswerOptions options;
3069 options.use_rtp_mux = true;
3070
3071 SessionDescriptionInterface* offer = CreateOffer(options);
3072 SetLocalDescriptionWithoutError(offer);
3073
deadbeefcbecd352015-09-23 11:50:27 -07003074 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3075 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003076
deadbeefab9b2d12015-10-14 11:33:11 -07003077 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003078
3079 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003080 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081 CreateRemoteAnswer(session_->local_description()));
3082 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3083 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3084 JsepSessionDescription* modified_answer =
3085 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3086 modified_answer->Initialize(answer_copy, "1", "1");
3087 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088
deadbeefcbecd352015-09-23 11:50:27 -07003089 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3090 session_->video_rtp_transport_channel());
3091}
3092
3093// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3094TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3095 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003096 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003097
3098 SessionDescriptionInterface* offer = CreateRemoteOffer();
3099 SetRemoteDescriptionWithoutError(offer);
3100
3101 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3102 session_->video_rtp_transport_channel());
3103
deadbeefab9b2d12015-10-14 11:33:11 -07003104 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003105 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3106 SetLocalDescriptionWithoutError(answer);
3107
3108 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3109 session_->video_rtp_transport_channel());
3110}
3111
3112// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3113TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3114 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003115 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003116
3117 // Remove BUNDLE from the offer.
3118 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3119 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3120 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3121 JsepSessionDescription* modified_offer =
3122 new JsepSessionDescription(JsepSessionDescription::kOffer);
3123 modified_offer->Initialize(offer_copy, "1", "1");
3124
3125 // Expect an error when applying the remote description
3126 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3127 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003128}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129
Peter Thatcher4eddf182015-04-30 10:55:59 -07003130// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003131TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3132 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003133 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134
Donald Curtis0e209b02015-03-24 09:29:54 -07003135 PeerConnectionInterface::RTCOfferAnswerOptions options;
3136 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003137
Donald Curtis0e209b02015-03-24 09:29:54 -07003138 SessionDescriptionInterface* offer = CreateOffer(options);
3139 SetLocalDescriptionWithoutError(offer);
3140
deadbeefcbecd352015-09-23 11:50:27 -07003141 EXPECT_NE(session_->voice_rtp_transport_channel(),
3142 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003143
deadbeefab9b2d12015-10-14 11:33:11 -07003144 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003145 SessionDescriptionInterface* answer =
3146 CreateRemoteAnswer(session_->local_description());
3147 SetRemoteDescriptionWithoutError(answer);
3148
3149 // This should lead to an audio-only call but isn't implemented
3150 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003151 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3152 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003153}
3154
deadbeefcbecd352015-09-23 11:50:27 -07003155// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003156TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3157 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003158 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003159 PeerConnectionInterface::RTCOfferAnswerOptions options;
3160 options.use_rtp_mux = true;
3161
3162 SessionDescriptionInterface* offer = CreateOffer(options);
3163 SetLocalDescriptionWithoutError(offer);
3164
deadbeefcbecd352015-09-23 11:50:27 -07003165 EXPECT_NE(session_->voice_rtp_transport_channel(),
3166 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003167
deadbeefab9b2d12015-10-14 11:33:11 -07003168 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003169
3170 // Remove BUNDLE from the answer.
3171 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3172 CreateRemoteAnswer(session_->local_description()));
3173 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3174 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3175 JsepSessionDescription* modified_answer =
3176 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3177 modified_answer->Initialize(answer_copy, "1", "1");
3178 SetRemoteDescriptionWithoutError(modified_answer); //
3179
deadbeefcbecd352015-09-23 11:50:27 -07003180 EXPECT_NE(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182}
3183
Peter Thatcher4eddf182015-04-30 10:55:59 -07003184// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3185TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3186 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003187 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003188
3189 PeerConnectionInterface::RTCOfferAnswerOptions options;
3190 options.use_rtp_mux = true;
3191
3192 SessionDescriptionInterface* offer = CreateOffer(options);
3193 SetRemoteDescriptionWithoutError(offer);
3194
deadbeefcbecd352015-09-23 11:50:27 -07003195 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3196 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003197}
3198
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003199TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3200 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003201 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003202
3203 PeerConnectionInterface::RTCOfferAnswerOptions options;
3204 SessionDescriptionInterface* offer = CreateOffer(options);
3205 SetLocalDescriptionWithoutError(offer);
3206
deadbeefcbecd352015-09-23 11:50:27 -07003207 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3208 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003209
deadbeefab9b2d12015-10-14 11:33:11 -07003210 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003211 SessionDescriptionInterface* answer =
3212 CreateRemoteAnswer(session_->local_description());
3213 SetRemoteDescriptionWithoutError(answer);
3214
deadbeefcbecd352015-09-23 11:50:27 -07003215 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3216 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003217}
3218
3219TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3220 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003221 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003222
3223 PeerConnectionInterface::RTCOfferAnswerOptions options;
3224 SessionDescriptionInterface* offer = CreateOffer(options);
3225 SetLocalDescriptionWithoutError(offer);
3226
deadbeefcbecd352015-09-23 11:50:27 -07003227 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3228 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003229
deadbeefab9b2d12015-10-14 11:33:11 -07003230 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003231 SessionDescriptionInterface* answer =
3232 CreateRemoteAnswer(session_->local_description());
3233 SetRemoteDescriptionWithoutError(answer);
3234
deadbeefcbecd352015-09-23 11:50:27 -07003235 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3236 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003237}
3238
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003239// This test verifies that SetLocalDescription and SetRemoteDescription fails
3240// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3241TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003244
3245 PeerConnectionInterface::RTCOfferAnswerOptions options;
3246 options.use_rtp_mux = true;
3247
3248 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003249 std::string offer_str;
3250 offer->ToString(&offer_str);
3251 // Disable rtcp-mux
3252 const std::string rtcp_mux = "rtcp-mux";
3253 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003254 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003255 xrtcp_mux.c_str(), xrtcp_mux.length(),
3256 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003257 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003258 new JsepSessionDescription(JsepSessionDescription::kOffer);
3259 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003260 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003261 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003262 new JsepSessionDescription(JsepSessionDescription::kOffer);
3263 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003264 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003265 // Trying unmodified SDP.
3266 SetLocalDescriptionWithoutError(offer);
3267}
3268
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003270 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003271 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 CreateAndSetRemoteOfferAndLocalAnswer();
3273 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3274 ASSERT_TRUE(channel != NULL);
3275 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003276 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003277 double volume;
3278 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3279 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003280 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003281 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3282 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003283 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003284 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3285 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286}
3287
3288TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003289 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 CreateAndSetRemoteOfferAndLocalAnswer();
3292 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3293 ASSERT_TRUE(channel != NULL);
3294 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003295 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3297
3298 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003299 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003301 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003302 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003303 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003304 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003305 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003307 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003308 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003310 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003311 EXPECT_TRUE(renderer->sink() == NULL);
3312}
3313
3314TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003315 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003316 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003317 CreateAndSetRemoteOfferAndLocalAnswer();
3318 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3319 ASSERT_TRUE(channel != NULL);
3320 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003321 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003322
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003323 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003324 cricket::AudioOptions options;
3325 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3326 EXPECT_TRUE(renderer->sink() != NULL);
3327
3328 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3329 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3330 // SetSink(NULL) callback afterwards.
3331 renderer.reset();
3332
3333 // This will trigger SetSink(NULL) if no OnClose() callback.
3334 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335}
3336
3337TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003338 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003339 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 CreateAndSetRemoteOfferAndLocalAnswer();
3341 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3342 ASSERT_TRUE(channel != NULL);
3343 ASSERT_LT(0u, channel->renderers().size());
3344 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3345 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003346 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347 cricket::FakeVideoRenderer renderer;
3348 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3349 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3350 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3351 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3352}
3353
3354TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003355 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003356 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357 CreateAndSetRemoteOfferAndLocalAnswer();
3358 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3359 ASSERT_TRUE(channel != NULL);
3360 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003361 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3363 cricket::VideoOptions* options = NULL;
3364 session_->SetVideoSend(send_ssrc, false, options);
3365 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3366 session_->SetVideoSend(send_ssrc, true, options);
3367 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3368}
3369
3370TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3371 TestCanInsertDtmf(false);
3372}
3373
3374TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3375 TestCanInsertDtmf(true);
3376}
3377
3378TEST_F(WebRtcSessionTest, InsertDtmf) {
3379 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003380 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003381 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 CreateAndSetRemoteOfferAndLocalAnswer();
3383 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3384 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3385
3386 // Insert DTMF
3387 const int expected_flags = DF_SEND;
3388 const int expected_duration = 90;
3389 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3390 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3391 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3392
3393 // Verify
3394 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003395 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3397 expected_duration, expected_flags));
3398 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3399 expected_duration, expected_flags));
3400 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3401 expected_duration, expected_flags));
3402}
3403
deadbeefd59daf82015-10-14 15:02:44 -07003404// This test verifies the |initial_offerer| flag when session initiates the
3405// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003407 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003408 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003409 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3411 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003412 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003414 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415}
3416
deadbeefd59daf82015-10-14 15:02:44 -07003417// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003419 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003420 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 SessionDescriptionInterface* offer = CreateRemoteOffer();
3422 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003423 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424
deadbeefd59daf82015-10-14 15:02:44 -07003425 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003427 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428}
3429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3431TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003432 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003433 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003434 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003436 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 CreateRemoteAnswer(session_->local_description()));
3438
3439 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3440 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003441 JsepSessionDescription* modified_answer =
3442 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443
3444 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3445 answer->session_id(),
3446 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003447 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448
wu@webrtc.org4e393072014-04-07 17:04:35 +00003449 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 std::string sdp;
3451 EXPECT_TRUE(answer->ToString(&sdp));
3452 const std::string kAudioMid = "a=mid:audio";
3453 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003454 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 kAudioMidReplaceStr.c_str(),
3456 kAudioMidReplaceStr.length(),
3457 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003458 SessionDescriptionInterface* modified_answer1 =
3459 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003460 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461
wu@webrtc.org4e393072014-04-07 17:04:35 +00003462 // Different media types.
3463 EXPECT_TRUE(answer->ToString(&sdp));
3464 const std::string kAudioMline = "m=audio";
3465 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003466 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003467 kAudioMlineReplaceStr.c_str(),
3468 kAudioMlineReplaceStr.length(),
3469 &sdp);
3470 SessionDescriptionInterface* modified_answer2 =
3471 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3472 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 SetRemoteDescriptionWithoutError(answer.release());
3475}
3476
3477// Verifying remote offer and local answer have matching m-lines as per
3478// RFC 3264.
3479TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003480 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003481 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 SessionDescriptionInterface* offer = CreateRemoteOffer();
3483 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003484 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485
3486 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3487 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003488 JsepSessionDescription* modified_answer =
3489 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490
3491 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3492 answer->session_id(),
3493 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003494 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 SetLocalDescriptionWithoutError(answer);
3496}
3497
3498// This test verifies that WebRtcSession does not start candidate allocation
3499// before SetLocalDescription is called.
3500TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003501 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003502 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 SessionDescriptionInterface* offer = CreateRemoteOffer();
3504 cricket::Candidate candidate;
3505 candidate.set_component(1);
3506 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3507 candidate);
3508 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3509 cricket::Candidate candidate1;
3510 candidate1.set_component(1);
3511 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3512 candidate1);
3513 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3514 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003515 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3516 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517
3518 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003519 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3521 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3522
wu@webrtc.org91053e72013-08-10 07:18:04 +00003523 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3526}
3527
3528// This test verifies that crypto parameter is updated in local session
3529// description as per security policy set in MediaSessionDescriptionFactory.
3530TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003531 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003532 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003533 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534
3535 // Making sure SetLocalDescription correctly sets crypto value in
3536 // SessionDescription object after de-serialization of sdp string. The value
3537 // will be set as per MediaSessionDescriptionFactory.
3538 std::string offer_str;
3539 offer->ToString(&offer_str);
3540 SessionDescriptionInterface* jsep_offer_str =
3541 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3542 SetLocalDescriptionWithoutError(jsep_offer_str);
3543 EXPECT_TRUE(session_->voice_channel()->secure_required());
3544 EXPECT_TRUE(session_->video_channel()->secure_required());
3545}
3546
3547// This test verifies the crypto parameter when security is disabled.
3548TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003549 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003550 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003551 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003552 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553
3554 // Making sure SetLocalDescription correctly sets crypto value in
3555 // SessionDescription object after de-serialization of sdp string. The value
3556 // will be set as per MediaSessionDescriptionFactory.
3557 std::string offer_str;
3558 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003559 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3561 SetLocalDescriptionWithoutError(jsep_offer_str);
3562 EXPECT_FALSE(session_->voice_channel()->secure_required());
3563 EXPECT_FALSE(session_->video_channel()->secure_required());
3564}
3565
3566// This test verifies that an answer contains new ufrag and password if an offer
3567// with new ufrag and password is received.
3568TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003569 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003571 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003572 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 CreateRemoteOffer(options));
3574 SetRemoteDescriptionWithoutError(offer.release());
3575
deadbeefab9b2d12015-10-14 11:33:11 -07003576 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003577 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003578 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 SetLocalDescriptionWithoutError(answer.release());
3580
3581 // Receive an offer with new ufrag and password.
3582 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003583 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003584 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585 SetRemoteDescriptionWithoutError(updated_offer1.release());
3586
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003587 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003588 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589
3590 CompareIceUfragAndPassword(updated_answer1->description(),
3591 session_->local_description()->description(),
3592 false);
3593
3594 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003595}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596
wu@webrtc.org91053e72013-08-10 07:18:04 +00003597// This test verifies that an answer contains old ufrag and password if an offer
3598// with old ufrag and password is received.
3599TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003600 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003601 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003602 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003603 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003604 CreateRemoteOffer(options));
3605 SetRemoteDescriptionWithoutError(offer.release());
3606
deadbeefab9b2d12015-10-14 11:33:11 -07003607 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003608 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003609 CreateAnswer(NULL));
3610 SetLocalDescriptionWithoutError(answer.release());
3611
3612 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003614 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003615 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 SetRemoteDescriptionWithoutError(updated_offer2.release());
3617
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003618 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003619 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003620
3621 CompareIceUfragAndPassword(updated_answer2->description(),
3622 session_->local_description()->description(),
3623 true);
3624
3625 SetLocalDescriptionWithoutError(updated_answer2.release());
3626}
3627
3628TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003629 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003630 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003631 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 const std::string session_id_orig = offer->session_id();
3633 const std::string session_version_orig = offer->session_version();
3634 SetLocalDescriptionWithoutError(offer);
3635
3636 video_channel_ = media_engine_->GetVideoChannel(0);
3637 video_channel_->set_fail_set_send_codecs(true);
3638
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003639 SessionDescriptionInterface* answer =
3640 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003641 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003642
3643 // Test that after a content error, setting any description will
3644 // result in an error.
3645 video_channel_->set_fail_set_send_codecs(false);
3646 answer = CreateRemoteAnswer(session_->local_description());
3647 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3648 offer = CreateRemoteOffer();
3649 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650}
3651
3652// Runs the loopback call test with BUNDLE and STUN disabled.
3653TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3654 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003655 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003656 cricket::PORTALLOCATOR_DISABLE_STUN |
3657 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003658 TestLoopbackCall();
3659}
3660
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003661TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003662 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003663 cricket::PORTALLOCATOR_DISABLE_STUN |
3664 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3665 cricket::PORTALLOCATOR_DISABLE_RELAY);
3666
3667 // best connection is IPv6 since it has higher network preference.
3668 LoopbackNetworkConfiguration config;
3669 config.test_ipv6_network_ = true;
3670 config.best_connection_after_initial_ice_converged_ =
3671 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3672
3673 TestLoopbackCall(config);
3674}
3675
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003676// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003677TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003678 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3679 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003680 TestLoopbackCall();
3681}
3682
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003683TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3684 constraints_.reset(new FakeConstraints());
3685 constraints_->AddOptional(
3686 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003687 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003688
3689 SetLocalDescriptionWithDataChannel();
3690 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3691}
3692
Henrik Boström87713d02015-08-25 09:53:21 +02003693TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003694 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003695
3696 constraints_.reset(new FakeConstraints());
3697 constraints_->AddOptional(
3698 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003699 options_.disable_sctp_data_channels = false;
3700
Henrik Boström87713d02015-08-25 09:53:21 +02003701 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003702
3703 SetLocalDescriptionWithDataChannel();
3704 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3705}
3706
Henrik Boström87713d02015-08-25 09:53:21 +02003707TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003708 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003709
Henrik Boström87713d02015-08-25 09:53:21 +02003710 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003711
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003712 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003713 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003714 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3715}
3716
Henrik Boström87713d02015-08-25 09:53:21 +02003717TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003718 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003719 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003720 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003721
3722 // Create remote offer with SCTP.
3723 cricket::MediaSessionOptions options;
3724 options.data_channel_type = cricket::DCT_SCTP;
3725 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003726 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003727 SetRemoteDescriptionWithoutError(offer);
3728
3729 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003730 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003731 EXPECT_TRUE(answer != NULL);
3732 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3733 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003734}
3735
Henrik Boström87713d02015-08-25 09:53:21 +02003736TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737 constraints_.reset(new FakeConstraints());
3738 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003739 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003740 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003741
3742 SetLocalDescriptionWithDataChannel();
3743 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3744}
3745
Henrik Boström87713d02015-08-25 09:53:21 +02003746TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003747 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003748
Henrik Boström87713d02015-08-25 09:53:21 +02003749 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750
3751 SetLocalDescriptionWithDataChannel();
3752 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3753}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003754
Henrik Boström87713d02015-08-25 09:53:21 +02003755TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003756 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003757 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003758 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003759
3760 SetLocalDescriptionWithDataChannel();
3761 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3762}
3763
Henrik Boström87713d02015-08-25 09:53:21 +02003764TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003765 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003766 const int new_send_port = 9998;
3767 const int new_recv_port = 7775;
3768
Henrik Boström87713d02015-08-25 09:53:21 +02003769 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003770 SetFactoryDtlsSrtp();
3771
3772 // By default, don't actually add the codecs to desc_factory_; they don't
3773 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3774 // let the session description get parsed. That'll get the proper codecs
3775 // into the stream.
3776 cricket::MediaSessionOptions options;
3777 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3778 "stream1", new_send_port, options);
3779
3780 // SetRemoteDescription will take the ownership of the offer.
3781 SetRemoteDescriptionWithoutError(offer);
3782
3783 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3784 new_recv_port, CreateAnswer(NULL));
3785 ASSERT_TRUE(answer != NULL);
3786
3787 // Now set the local description, which'll take ownership of the answer.
3788 SetLocalDescriptionWithoutError(answer);
3789
3790 // TEST PLAN: Set the port number to something new, set it in the SDP,
3791 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003792 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003793 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003794
3795 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3796 int portnum = -1;
3797 ASSERT_TRUE(ch != NULL);
3798 ASSERT_EQ(1UL, ch->send_codecs().size());
3799 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003800 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003801 ch->send_codecs()[0].name.c_str()));
3802 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3803 &portnum));
3804 EXPECT_EQ(new_send_port, portnum);
3805
3806 ASSERT_EQ(1UL, ch->recv_codecs().size());
3807 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003808 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003809 ch->recv_codecs()[0].name.c_str()));
3810 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3811 &portnum));
3812 EXPECT_EQ(new_recv_port, portnum);
3813}
3814
deadbeefab9b2d12015-10-14 11:33:11 -07003815// Verifies that when a session's DataChannel receives an OPEN message,
3816// WebRtcSession signals the DataChannel creation request with the expected
3817// config.
3818TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3820
3821 InitWithDtls(GetParam());
3822
3823 SetLocalDescriptionWithDataChannel();
3824 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3825
3826 webrtc::DataChannelInit config;
3827 config.id = 1;
3828 rtc::Buffer payload;
3829 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3830 cricket::ReceiveDataParams params;
3831 params.ssrc = config.id;
3832 params.type = cricket::DMT_CONTROL;
3833
3834 cricket::DataChannel* data_channel = session_->data_channel();
3835 data_channel->SignalDataReceived(data_channel, params, payload);
3836
3837 EXPECT_EQ("a", last_data_channel_label_);
3838 EXPECT_EQ(config.id, last_data_channel_config_.id);
3839 EXPECT_FALSE(last_data_channel_config_.negotiated);
3840 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3841 last_data_channel_config_.open_handshake_role);
3842}
3843
3844TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003845 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3846 FakeDtlsIdentityStore::GenerateCertificate();
3847
3848 PeerConnectionInterface::RTCConfiguration configuration;
3849 configuration.certificates.push_back(certificate);
3850 Init(nullptr, configuration);
3851 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3852
3853 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3854}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003855
Henrik Boström87713d02015-08-25 09:53:21 +02003856// Verifies that CreateOffer succeeds when CreateOffer is called before async
3857// identity generation is finished (even if a certificate is provided this is
3858// an async op).
3859TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3860 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3861 InitWithDtls(GetParam());
3862
Henrik Boströmd8281982015-08-27 10:12:24 +02003863 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003864 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003865 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3866
wu@webrtc.org91053e72013-08-10 07:18:04 +00003867 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003868 VerifyNoCryptoParams(offer->description(), true);
3869 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003870}
3871
3872// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003873// identity generation is finished (even if a certificate is provided this is
3874// an async op).
3875TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003876 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003877 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003878 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003879
3880 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003881 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003882 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003883 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003884 ASSERT_TRUE(offer.get() != NULL);
3885 SetRemoteDescriptionWithoutError(offer.release());
3886
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003887 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003888 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003889 VerifyNoCryptoParams(answer->description(), true);
3890 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003891}
3892
3893// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003894// identity generation is finished (even if a certificate is provided this is
3895// an async op).
3896TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003897 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003898 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003899
Henrik Boströmd8281982015-08-27 10:12:24 +02003900 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003901
3902 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003903 EXPECT_TRUE(offer != NULL);
3904}
3905
3906// Verifies that CreateOffer fails when CreateOffer is called after async
3907// identity generation fails.
3908TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003909 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003910 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003911
Henrik Boströmd8281982015-08-27 10:12:24 +02003912 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003913
3914 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003915 EXPECT_TRUE(offer == NULL);
3916}
3917
3918// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3919// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003920TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003921 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003922 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003923 VerifyMultipleAsyncCreateDescription(GetParam(),
3924 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003925}
3926
3927// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3928// before async identity generation fails.
3929TEST_F(WebRtcSessionTest,
3930 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003931 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003932 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3933 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003934}
3935
3936// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3937// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003938TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003939 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003940 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003941 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003942 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003943}
3944
3945// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3946// before async identity generation fails.
3947TEST_F(WebRtcSessionTest,
3948 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003949 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003950 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3951 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003952}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003953
3954// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3955// offer has no SDES crypto but only DTLS fingerprint.
3956TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3957 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003958 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003959 // Create a remote offer with secured transport disabled.
3960 cricket::MediaSessionOptions options;
3961 JsepSessionDescription* offer(CreateRemoteOffer(
3962 options, cricket::SEC_DISABLED));
3963 // Adds a DTLS fingerprint to the remote offer.
3964 cricket::SessionDescription* sdp = offer->description();
3965 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3966 ASSERT_TRUE(audio != NULL);
3967 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3968 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003969 rtc::SSLFingerprint::CreateFromRfc4572(
3970 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003971 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003972 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003973}
3974
wu@webrtc.orgde305012013-10-31 15:40:38 +00003975// This test verifies DSCP is properly applied on the media channels.
3976TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3977 constraints_.reset(new FakeConstraints());
3978 constraints_->AddOptional(
3979 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003980 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003981 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003982 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003983
3984 SetLocalDescriptionWithoutError(offer);
3985
3986 video_channel_ = media_engine_->GetVideoChannel(0);
3987 voice_channel_ = media_engine_->GetVoiceChannel(0);
3988
3989 ASSERT_TRUE(video_channel_ != NULL);
3990 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003991 const cricket::AudioOptions& audio_options = voice_channel_->options();
3992 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01003993 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
3994 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00003995}
3996
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003997TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3998 constraints_.reset(new FakeConstraints());
3999 constraints_->AddOptional(
4000 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4001 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004002 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004003 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004004 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004005
4006 SetLocalDescriptionWithoutError(offer);
4007
4008 video_channel_ = media_engine_->GetVideoChannel(0);
4009
4010 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004011 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004012 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004013}
4014
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004015TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4016 // Number of unsignalled receiving streams should be between 0 and
4017 // kMaxUnsignalledRecvStreams.
4018 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4019 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4020 kMaxUnsignalledRecvStreams);
4021 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4022}
4023
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004024TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4025 constraints_.reset(new FakeConstraints());
4026 constraints_->AddOptional(
4027 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4028 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004029 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004030 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004031 SessionDescriptionInterface* offer = CreateOffer();
4032
4033 SetLocalDescriptionWithoutError(offer);
4034
4035 voice_channel_ = media_engine_->GetVoiceChannel(0);
4036
4037 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004038 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004039 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004040}
4041
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004042// Tests that we can renegotiate new media content with ICE candidates in the
4043// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004044TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004045 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004046 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004047 SetFactoryDtlsSrtp();
4048
deadbeefab9b2d12015-10-14 11:33:11 -07004049 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004050 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004051 SetLocalDescriptionWithoutError(offer);
4052
4053 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4054 SetRemoteDescriptionWithoutError(answer);
4055
4056 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004057 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004058 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4059
4060 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004061 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004062 candidate1.set_component(1);
4063 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4064 candidate1);
4065 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4066 SetRemoteDescriptionWithoutError(offer);
4067
4068 answer = CreateAnswer(NULL);
4069 SetLocalDescriptionWithoutError(answer);
4070}
4071
4072// Tests that we can renegotiate new media content with ICE candidates separated
4073// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004074TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004075 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004076 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004077 SetFactoryDtlsSrtp();
4078
deadbeefab9b2d12015-10-14 11:33:11 -07004079 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004080 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004081 SetLocalDescriptionWithoutError(offer);
4082
4083 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4084 SetRemoteDescriptionWithoutError(answer);
4085
4086 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004087 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004088 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4089 SetRemoteDescriptionWithoutError(offer);
4090
4091 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004092 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004093 candidate1.set_component(1);
4094 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4095 candidate1);
4096 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4097
4098 answer = CreateAnswer(NULL);
4099 SetLocalDescriptionWithoutError(answer);
4100}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004101// Tests that RTX codec is removed from the answer when it isn't supported
4102// by local side.
4103TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4104 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004105 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004106 std::string offer_sdp(kSdpWithRtx);
4107
4108 SessionDescriptionInterface* offer =
4109 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4110 EXPECT_TRUE(offer->ToString(&offer_sdp));
4111
4112 // Offer SDP contains the RTX codec.
4113 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4114 SetRemoteDescriptionWithoutError(offer);
4115
4116 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4117 std::string answer_sdp;
4118 answer->ToString(&answer_sdp);
4119 // Answer SDP removes the unsupported RTX codec.
4120 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4121 SetLocalDescriptionWithoutError(answer);
4122}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004123
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004124// This verifies that the voice channel after bundle has both options from video
4125// and voice channels.
4126TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4127 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004128 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004129
4130 PeerConnectionInterface::RTCOfferAnswerOptions options;
4131 options.use_rtp_mux = true;
4132
4133 SessionDescriptionInterface* offer = CreateOffer(options);
4134 SetLocalDescriptionWithoutError(offer);
4135
4136 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4137 rtc::Socket::Option::OPT_SNDBUF, 4000);
4138
4139 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4140 rtc::Socket::Option::OPT_RCVBUF, 8000);
4141
4142 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004143 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004144 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4145 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004146 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004147 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4148
deadbeefcbecd352015-09-23 11:50:27 -07004149 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004150 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4151 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004152 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004153 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4154
deadbeefcbecd352015-09-23 11:50:27 -07004155 EXPECT_NE(session_->voice_rtp_transport_channel(),
4156 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004157
deadbeefab9b2d12015-10-14 11:33:11 -07004158 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004159 SessionDescriptionInterface* answer =
4160 CreateRemoteAnswer(session_->local_description());
4161 SetRemoteDescriptionWithoutError(answer);
4162
deadbeefcbecd352015-09-23 11:50:27 -07004163 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004164 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4165 EXPECT_EQ(4000, option_val);
4166
deadbeefcbecd352015-09-23 11:50:27 -07004167 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004168 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4169 EXPECT_EQ(8000, option_val);
4170}
4171
tommi0f620f42015-07-09 03:25:02 -07004172// Test creating a session, request multiple offers, destroy the session
4173// and make sure we got success/failure callbacks for all of the requests.
4174// Background: crbug.com/507307
4175TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4176 Init();
4177
4178 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4179 PeerConnectionInterface::RTCOfferAnswerOptions options;
4180 options.offer_to_receive_audio =
4181 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004182 cricket::MediaSessionOptions session_options;
4183 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004184
4185 for (auto& o : observers) {
4186 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004187 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004188 }
4189
4190 session_.reset();
4191
tommi0f620f42015-07-09 03:25:02 -07004192 for (auto& o : observers) {
4193 // We expect to have received a notification now even if the session was
4194 // terminated. The offer creation may or may not have succeeded, but we
4195 // must have received a notification which, so the only invalid state
4196 // is kInit.
4197 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4198 }
4199}
4200
stefanc1aeaf02015-10-15 07:26:07 -07004201TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4202 TestPacketOptions();
4203}
4204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004205// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4206// currently fails because upon disconnection and reconnection OnIceComplete is
4207// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004208
deadbeefcbecd352015-09-23 11:50:27 -07004209INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4210 WebRtcSessionTest,
4211 testing::Values(ALREADY_GENERATED,
4212 DTLS_IDENTITY_STORE));