blob: 9618db9d80be923c2e47f9f48766afb3d9476e7b [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"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/app/webrtc/mediastreamsignaling.h"
deadbeefab9b2d12015-10-14 11:33:11 -070037#include "talk/app/webrtc/sctputils.h"
38#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020041#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000044#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/media/base/fakemediaengine.h"
46#include "talk/media/base/fakevideorenderer.h"
47#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070048#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000049#include "webrtc/p2p/base/stunserver.h"
50#include "webrtc/p2p/base/teststunserver.h"
51#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000052#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000054#include "talk/session/media/channelmanager.h"
55#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056#include "webrtc/base/fakenetwork.h"
57#include "webrtc/base/firewallsocketserver.h"
58#include "webrtc/base/gunit.h"
59#include "webrtc/base/logging.h"
60#include "webrtc/base/network.h"
61#include "webrtc/base/physicalsocketserver.h"
62#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020063#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064#include "webrtc/base/sslstreamadapter.h"
65#include "webrtc/base/stringutils.h"
66#include "webrtc/base/thread.h"
67#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
69#define MAYBE_SKIP_TEST(feature) \
70 if (!(feature())) { \
71 LOG(LS_INFO) << "Feature disabled... skipping"; \
72 return; \
73 }
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::DF_PLAY;
76using cricket::DF_SEND;
77using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000079using rtc::SocketAddress;
80using rtc::scoped_ptr;
81using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000083using webrtc::CreateSessionDescriptionObserver;
84using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070085using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020086using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070088using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070090using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091using webrtc::JsepIceCandidate;
92using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000093using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::PeerConnectionInterface;
95using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070096using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000098using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000099using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kCreateChannelFailed;
101using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000103using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000104using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000105using webrtc::kSdpWithoutDtlsFingerprint;
106using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000108using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000109using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000111typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
112
wu@webrtc.org364f2042013-11-20 21:49:41 +0000113static const int kClientAddrPort = 0;
114static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000115static const char kClientIPv6AddrHost1[] =
116 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000117static const char kClientAddrHost2[] = "22.22.22.22";
118static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000119static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
120static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000121static const char kTurnUsername[] = "test";
122static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
124static const char kSessionVersion[] = "1";
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Media index of candidates belonging to the first media content.
127static const int kMediaContentIndex0 = 0;
128static const char kMediaContentName0[] = "audio";
129
130// Media index of candidates belonging to the second media content.
131static const int kMediaContentIndex1 = 1;
132static const char kMediaContentName1[] = "video";
133
134static const int kIceCandidatesTimeout = 10000;
135
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000136static const char kFakeDtlsFingerprint[] =
137 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
138 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
139
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000140static const char kTooLongIceUfragPwd[] =
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
143 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
144 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
145
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000146static const char kSdpWithRtx[] =
147 "v=0\r\n"
148 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
149 "s=-\r\n"
150 "t=0 0\r\n"
151 "a=msid-semantic: WMS stream1\r\n"
152 "m=video 9 RTP/SAVPF 0 96\r\n"
153 "c=IN IP4 0.0.0.0\r\n"
154 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
155 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
156 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
157 "a=mid:video\r\n"
158 "a=sendrecv\r\n"
159 "a=rtcp-mux\r\n"
160 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
161 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
162 "a=rtpmap:0 fake_video_codec/90000\r\n"
163 "a=rtpmap:96 rtx/90000\r\n"
164 "a=fmtp:96 apt=0\r\n";
165
deadbeefab9b2d12015-10-14 11:33:11 -0700166static const char kStream1[] = "stream1";
167static const char kVideoTrack1[] = "video1";
168static const char kAudioTrack1[] = "audio1";
169
170static const char kStream2[] = "stream2";
171static const char kVideoTrack2[] = "video2";
172static const char kAudioTrack2[] = "audio2";
173
Henrik Boström87713d02015-08-25 09:53:21 +0200174enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
175
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176// Add some extra |newlines| to the |message| after |line|.
177static void InjectAfter(const std::string& line,
178 const std::string& newlines,
179 std::string* message) {
180 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700181 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
182 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183}
184
185class MockIceObserver : public webrtc::IceObserver {
186 public:
187 MockIceObserver()
188 : oncandidatesready_(false),
189 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
190 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
191 }
192
193 virtual void OnIceConnectionChange(
194 PeerConnectionInterface::IceConnectionState new_state) {
195 ice_connection_state_ = new_state;
196 }
197 virtual void OnIceGatheringChange(
198 PeerConnectionInterface::IceGatheringState new_state) {
199 // We can never transition back to "new".
200 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
201 ice_gathering_state_ = new_state;
202
203 // oncandidatesready_ really means "ICE gathering is complete".
204 // This if statement ensures that this value remains correct when we
205 // transition from kIceGatheringComplete to kIceGatheringGathering.
206 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
207 oncandidatesready_ = false;
208 }
209 }
210
211 // Found a new candidate.
212 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000213 switch (candidate->sdp_mline_index()) {
214 case kMediaContentIndex0:
215 mline_0_candidates_.push_back(candidate->candidate());
216 break;
217 case kMediaContentIndex1:
218 mline_1_candidates_.push_back(candidate->candidate());
219 break;
220 default:
221 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000223
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 // The ICE gathering state should always be Gathering when a candidate is
225 // received (or possibly Completed in the case of the final candidate).
226 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
227 }
228
229 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
230 virtual void OnIceComplete() {
231 EXPECT_FALSE(oncandidatesready_);
232 oncandidatesready_ = true;
233
234 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
235 // be called approximately simultaneously. For ease of testing, this
236 // check additionally requires that they be called in the above order.
237 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
238 ice_gathering_state_);
239 }
240
241 bool oncandidatesready_;
242 std::vector<cricket::Candidate> mline_0_candidates_;
243 std::vector<cricket::Candidate> mline_1_candidates_;
244 PeerConnectionInterface::IceConnectionState ice_connection_state_;
245 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
246};
247
248class WebRtcSessionForTest : public webrtc::WebRtcSession {
249 public:
stefanc1aeaf02015-10-15 07:26:07 -0700250 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000251 rtc::Thread* signaling_thread,
252 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700254 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700255 : WebRtcSession(media_controller,
256 signaling_thread,
257 worker_thread,
258 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 RegisterIceObserver(ice_observer);
260 }
261 virtual ~WebRtcSessionForTest() {}
262
deadbeefcbecd352015-09-23 11:50:27 -0700263 // Note that these methods are only safe to use if the signaling thread
264 // is the same as the worker thread
265 cricket::TransportChannel* voice_rtp_transport_channel() {
266 return rtp_transport_channel(voice_channel());
267 }
268
269 cricket::TransportChannel* voice_rtcp_transport_channel() {
270 return rtcp_transport_channel(voice_channel());
271 }
272
273 cricket::TransportChannel* video_rtp_transport_channel() {
274 return rtp_transport_channel(video_channel());
275 }
276
277 cricket::TransportChannel* video_rtcp_transport_channel() {
278 return rtcp_transport_channel(video_channel());
279 }
280
281 cricket::TransportChannel* data_rtp_transport_channel() {
282 return rtp_transport_channel(data_channel());
283 }
284
285 cricket::TransportChannel* data_rtcp_transport_channel() {
286 return rtcp_transport_channel(data_channel());
287 }
288
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 using webrtc::WebRtcSession::SetAudioPlayout;
290 using webrtc::WebRtcSession::SetAudioSend;
291 using webrtc::WebRtcSession::SetCaptureDevice;
292 using webrtc::WebRtcSession::SetVideoPlayout;
293 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700294
295 private:
296 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
297 if (!ch) {
298 return nullptr;
299 }
300 return ch->transport_channel();
301 }
302
303 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
304 if (!ch) {
305 return nullptr;
306 }
307 return ch->rtcp_transport_channel();
308 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309};
310
wu@webrtc.org91053e72013-08-10 07:18:04 +0000311class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000312 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000314 enum State {
315 kInit,
316 kFailed,
317 kSucceeded,
318 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000319 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000320
321 // CreateSessionDescriptionObserver implementation.
322 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000323 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000324 state_ = kSucceeded;
325 }
326 virtual void OnFailure(const std::string& error) {
327 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 }
329
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000330 SessionDescriptionInterface* description() { return description_.get(); }
331
332 SessionDescriptionInterface* ReleaseDescription() {
333 return description_.release();
334 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
wu@webrtc.org91053e72013-08-10 07:18:04 +0000336 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337
wu@webrtc.org91053e72013-08-10 07:18:04 +0000338 protected:
339 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340
341 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000342 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000343 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344};
345
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000346class FakeAudioRenderer : public cricket::AudioRenderer {
347 public:
solenberg98c68862015-10-09 03:27:14 -0700348 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000349 virtual ~FakeAudioRenderer() {
350 if (sink_)
351 sink_->OnClose();
352 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000353
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000354 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000355
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000356 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000357 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000358 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000359};
360
Henrik Boström87713d02015-08-25 09:53:21 +0200361class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700362 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
363 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 protected:
365 // TODO Investigate why ChannelManager crashes, if it's created
366 // after stun_server.
367 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700368 : media_engine_(new cricket::FakeMediaEngine()),
369 data_engine_(new cricket::FakeDataEngine()),
370 channel_manager_(
371 new cricket::ChannelManager(media_engine_,
372 data_engine_,
373 new cricket::CaptureManager(),
374 rtc::Thread::Current())),
375 fake_call_(webrtc::Call::Config()),
376 media_controller_(
377 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
378 channel_manager_.get())),
379 tdesc_factory_(new cricket::TransportDescriptionFactory()),
380 desc_factory_(
381 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
382 tdesc_factory_.get())),
383 pss_(new rtc::PhysicalSocketServer),
384 vss_(new rtc::VirtualSocketServer(pss_.get())),
385 fss_(new rtc::FirewallSocketServer(vss_.get())),
386 ss_scope_(fss_.get()),
387 stun_socket_addr_(
388 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
389 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
390 stun_socket_addr_)),
391 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
392 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000393 cricket::ServerAddresses stun_servers;
394 stun_servers.insert(stun_socket_addr_);
395 allocator_.reset(new cricket::BasicPortAllocator(
396 &network_manager_,
397 stun_servers,
398 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000399 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700400 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 EXPECT_TRUE(channel_manager_->Init());
402 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000403 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
405
406 void AddInterface(const SocketAddress& addr) {
407 network_manager_.AddInterface(addr);
408 }
409
Henrik Boström87713d02015-08-25 09:53:21 +0200410 // If |dtls_identity_store| != null or |rtc_configuration| contains
411 // |certificates| then DTLS will be enabled unless explicitly disabled by
412 // |rtc_configuration| options. When DTLS is enabled a certificate will be
413 // used if provided, otherwise one will be generated using the
414 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000415 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200416 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200417 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 ASSERT_TRUE(session_.get() == NULL);
419 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700420 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700421 allocator_.get(), &observer_));
422 session_->SignalDataChannelOpenMessage.connect(
423 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424
425 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
426 observer_.ice_connection_state_);
427 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
428 observer_.ice_gathering_state_);
429
deadbeefcbecd352015-09-23 11:50:27 -0700430 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
431 dtls_identity_store.Pass(),
432 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700433 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 }
435
deadbeefab9b2d12015-10-14 11:33:11 -0700436 void OnDataChannelOpenMessage(const std::string& label,
437 const InternalDataChannelInit& config) {
438 last_data_channel_label_ = label;
439 last_data_channel_config_ = config;
440 }
441
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000442 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200443 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200444 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000445 }
446
447 void InitWithIceTransport(
448 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200449 PeerConnectionInterface::RTCConfiguration configuration;
450 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200451 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000452 }
453
454 void InitWithBundlePolicy(
455 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200456 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200457 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200458 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700459 }
460
461 void InitWithRtcpMuxPolicy(
462 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
463 PeerConnectionInterface::RTCConfiguration configuration;
464 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200465 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000466 }
467
Henrik Boström87713d02015-08-25 09:53:21 +0200468 // Successfully init with DTLS; with a certificate generated and supplied or
469 // with a store that generates it for us.
470 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
471 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
472 PeerConnectionInterface::RTCConfiguration configuration;
473 if (cert_gen_method == ALREADY_GENERATED) {
474 configuration.certificates.push_back(
475 FakeDtlsIdentityStore::GenerateCertificate());
476 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
477 dtls_identity_store.reset(new FakeDtlsIdentityStore());
478 dtls_identity_store->set_should_fail(false);
479 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700480 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200481 }
482 Init(dtls_identity_store.Pass(), configuration);
483 }
484
485 // Init with DTLS with a store that will fail to generate a certificate.
486 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200487 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
488 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200489 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200490 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200491 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000492 }
493
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 void InitWithDtmfCodec() {
495 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000496 const cricket::AudioCodec kTelephoneEventCodec(
497 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 std::vector<cricket::AudioCodec> codecs;
499 codecs.push_back(kTelephoneEventCodec);
500 media_engine_->SetAudioCodecs(codecs);
501 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000502 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 }
504
deadbeefab9b2d12015-10-14 11:33:11 -0700505 void SendAudioVideoStream1() {
506 send_stream_1_ = true;
507 send_stream_2_ = false;
508 send_audio_ = true;
509 send_video_ = true;
510 }
511
512 void SendAudioVideoStream2() {
513 send_stream_1_ = false;
514 send_stream_2_ = true;
515 send_audio_ = true;
516 send_video_ = true;
517 }
518
519 void SendAudioVideoStream1And2() {
520 send_stream_1_ = true;
521 send_stream_2_ = true;
522 send_audio_ = true;
523 send_video_ = true;
524 }
525
526 void SendNothing() {
527 send_stream_1_ = false;
528 send_stream_2_ = false;
529 send_audio_ = false;
530 send_video_ = false;
531 }
532
533 void SendAudioOnlyStream2() {
534 send_stream_1_ = false;
535 send_stream_2_ = true;
536 send_audio_ = true;
537 send_video_ = false;
538 }
539
540 void SendVideoOnlyStream2() {
541 send_stream_1_ = false;
542 send_stream_2_ = true;
543 send_audio_ = false;
544 send_video_ = true;
545 }
546
547 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
548 if (send_stream_1_ && send_audio_) {
549 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
550 kStream1);
551 }
552 if (send_stream_1_ && send_video_) {
553 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
554 kStream1);
555 }
556 if (send_stream_2_ && send_audio_) {
557 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
558 kStream2);
559 }
560 if (send_stream_2_ && send_video_) {
561 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
562 kStream2);
563 }
564 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
565 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
566 data_channel_->label(),
567 data_channel_->label());
568 }
569 }
570
571 void GetOptionsForOffer(
572 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
573 cricket::MediaSessionOptions* session_options) {
574 AddStreamsToOptions(session_options);
575 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
576
577 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
578 session_options->data_channel_type = cricket::DCT_SCTP;
579 }
580 }
581
582 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
583 cricket::MediaSessionOptions* session_options) {
584 AddStreamsToOptions(session_options);
585 session_options->recv_audio = false;
586 session_options->recv_video = false;
587 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
588
589 if (session_->data_channel_type() == cricket::DCT_SCTP) {
590 session_options->data_channel_type = cricket::DCT_SCTP;
591 }
592 }
593
594 // Creates a local offer and applies it. Starts ICE.
595 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 // to decide which streams to create.
597 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000598 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 SetLocalDescriptionWithoutError(offer);
600 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
601 observer_.ice_gathering_state_,
602 kIceCandidatesTimeout);
603 }
604
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000605 SessionDescriptionInterface* CreateOffer() {
606 PeerConnectionInterface::RTCOfferAnswerOptions options;
607 options.offer_to_receive_audio =
608 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
609
610 return CreateOffer(options);
611 }
612
wu@webrtc.org91053e72013-08-10 07:18:04 +0000613 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000614 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000615 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700617 cricket::MediaSessionOptions session_options;
618 GetOptionsForOffer(options, &session_options);
619 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000620 EXPECT_TRUE_WAIT(
621 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000622 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000623 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000624 }
625
626 SessionDescriptionInterface* CreateAnswer(
627 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000628 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000629 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700630 cricket::MediaSessionOptions session_options;
631 GetOptionsForAnswer(constraints, &session_options);
632 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 EXPECT_TRUE_WAIT(
634 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000635 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000636 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000637 }
638
wu@webrtc.org364f2042013-11-20 21:49:41 +0000639 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 return (session_->voice_channel() != NULL &&
641 session_->video_channel() != NULL);
642 }
643
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
645 ASSERT_TRUE(session_.get() != NULL);
646 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
647 ASSERT_TRUE(content != NULL);
648 const cricket::AudioContentDescription* audio_content =
649 static_cast<const cricket::AudioContentDescription*>(
650 content->description);
651 ASSERT_TRUE(audio_content != NULL);
652 ASSERT_EQ(1U, audio_content->cryptos().size());
653 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
654 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
655 audio_content->cryptos()[0].cipher_suite);
656 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
657 audio_content->protocol());
658
659 content = cricket::GetFirstVideoContent(sdp);
660 ASSERT_TRUE(content != NULL);
661 const cricket::VideoContentDescription* video_content =
662 static_cast<const cricket::VideoContentDescription*>(
663 content->description);
664 ASSERT_TRUE(video_content != NULL);
665 ASSERT_EQ(1U, video_content->cryptos().size());
666 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
667 video_content->cryptos()[0].cipher_suite);
668 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
669 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
670 video_content->protocol());
671 }
672
673 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
674 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
675 ASSERT_TRUE(content != NULL);
676 const cricket::AudioContentDescription* audio_content =
677 static_cast<const cricket::AudioContentDescription*>(
678 content->description);
679 ASSERT_TRUE(audio_content != NULL);
680 ASSERT_EQ(0U, audio_content->cryptos().size());
681
682 content = cricket::GetFirstVideoContent(sdp);
683 ASSERT_TRUE(content != NULL);
684 const cricket::VideoContentDescription* video_content =
685 static_cast<const cricket::VideoContentDescription*>(
686 content->description);
687 ASSERT_TRUE(video_content != NULL);
688 ASSERT_EQ(0U, video_content->cryptos().size());
689
690 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700691 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700693 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 video_content->protocol());
695 } else {
696 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
697 audio_content->protocol());
698 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
699 video_content->protocol());
700 }
701 }
702
703 // Set the internal fake description factories to do DTLS-SRTP.
704 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000705 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000707 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200708 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200709 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700710 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
711 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
713 }
714
715 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
716 bool expected) {
717 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
718 ASSERT_TRUE(audio != NULL);
719 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 const TransportInfo* video = sdp->GetTransportInfoByName("video");
721 ASSERT_TRUE(video != NULL);
722 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 }
724
725 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000726 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000728 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000729 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000731 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000733 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
734 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000735 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 // Answer should be NULL as no crypto params in offer.
737 ASSERT_TRUE(answer == NULL);
738 }
739
740 void VerifyAnswerFromCryptoOffer() {
741 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000742 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 options.bundle_enabled = true;
744 scoped_ptr<JsepSessionDescription> offer(
745 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
746 ASSERT_TRUE(offer.get() != NULL);
747 VerifyCryptoParams(offer->description());
748 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000749 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 ASSERT_TRUE(answer.get() != NULL);
751 VerifyCryptoParams(answer->description());
752 }
753
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000754 void SetAndVerifyNumUnsignalledRecvStreams(
755 int value_set, int value_expected) {
756 constraints_.reset(new FakeConstraints());
757 constraints_->AddOptional(
758 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
759 value_set);
760 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000761 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700762 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000763 SessionDescriptionInterface* offer = CreateOffer();
764
765 SetLocalDescriptionWithoutError(offer);
766
767 video_channel_ = media_engine_->GetVideoChannel(0);
768
769 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700770 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000771 EXPECT_EQ(value_expected,
772 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
773 }
774
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
776 const cricket::SessionDescription* desc2,
777 bool expect_equal) {
778 if (desc1->contents().size() != desc2->contents().size()) {
779 EXPECT_FALSE(expect_equal);
780 return;
781 }
782
783 const cricket::ContentInfos& contents = desc1->contents();
784 cricket::ContentInfos::const_iterator it = contents.begin();
785
786 for (; it != contents.end(); ++it) {
787 const cricket::TransportDescription* transport_desc1 =
788 desc1->GetTransportDescriptionByName(it->name);
789 const cricket::TransportDescription* transport_desc2 =
790 desc2->GetTransportDescriptionByName(it->name);
791 if (!transport_desc1 || !transport_desc2) {
792 EXPECT_FALSE(expect_equal);
793 return;
794 }
795 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
796 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
797 EXPECT_FALSE(expect_equal);
798 return;
799 }
800 }
801 EXPECT_TRUE(expect_equal);
802 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000803
804 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
805 std::string *sdp) {
806 const cricket::SessionDescription* desc = current_desc->description();
807 EXPECT_TRUE(current_desc->ToString(sdp));
808
809 const cricket::ContentInfos& contents = desc->contents();
810 cricket::ContentInfos::const_iterator it = contents.begin();
811 // Replace ufrag and pwd lines with empty strings.
812 for (; it != contents.end(); ++it) {
813 const cricket::TransportDescription* transport_desc =
814 desc->GetTransportDescriptionByName(it->name);
815 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
816 + "\r\n";
817 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
818 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000819 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000820 "", 0,
821 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000822 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000823 "", 0,
824 sdp);
825 }
826 }
827
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000828 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
829 const std::string& modified_ice_ufrag,
830 const std::string& modified_ice_pwd,
831 std::string* sdp) {
832 const cricket::SessionDescription* desc = current_desc->description();
833 EXPECT_TRUE(current_desc->ToString(sdp));
834
835 const cricket::ContentInfos& contents = desc->contents();
836 cricket::ContentInfos::const_iterator it = contents.begin();
837 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
838 // |modified_ice_pwd| strings.
839 for (; it != contents.end(); ++it) {
840 const cricket::TransportDescription* transport_desc =
841 desc->GetTransportDescriptionByName(it->name);
842 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
843 + "\r\n";
844 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
845 + "\r\n";
846 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
847 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000848 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000849 mod_ufrag.c_str(), mod_ufrag.length(),
850 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000852 mod_pwd.c_str(), mod_pwd.length(),
853 sdp);
854 }
855 }
856
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 // Creates a remote offer and and applies it as a remote description,
858 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700859 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 // to decide which local and remote streams to create.
861 void CreateAndSetRemoteOfferAndLocalAnswer() {
862 SessionDescriptionInterface* offer = CreateRemoteOffer();
863 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000864 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 SetLocalDescriptionWithoutError(answer);
866 }
867 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
868 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700869 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 }
871 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700872 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 SetLocalDescriptionWithoutError(desc);
874 EXPECT_EQ(expected_state, session_->state());
875 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000876 void SetLocalDescriptionExpectError(const std::string& action,
877 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 SessionDescriptionInterface* desc) {
879 std::string error;
880 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000881 std::string sdp_type = "local ";
882 sdp_type.append(action);
883 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_NE(std::string::npos, error.find(expected_error));
885 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
887 SessionDescriptionInterface* desc) {
888 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
889 expected_error, desc);
890 }
891 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
892 SessionDescriptionInterface* desc) {
893 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
894 expected_error, desc);
895 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
897 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
898 }
899 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700900 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 SetRemoteDescriptionWithoutError(desc);
902 EXPECT_EQ(expected_state, session_->state());
903 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000904 void SetRemoteDescriptionExpectError(const std::string& action,
905 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 SessionDescriptionInterface* desc) {
907 std::string error;
908 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000909 std::string sdp_type = "remote ";
910 sdp_type.append(action);
911 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_NE(std::string::npos, error.find(expected_error));
913 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000914 void SetRemoteDescriptionOfferExpectError(
915 const std::string& expected_error, SessionDescriptionInterface* desc) {
916 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
917 expected_error, desc);
918 }
919 void SetRemoteDescriptionPranswerExpectError(
920 const std::string& expected_error, SessionDescriptionInterface* desc) {
921 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
922 expected_error, desc);
923 }
924 void SetRemoteDescriptionAnswerExpectError(
925 const std::string& expected_error, SessionDescriptionInterface* desc) {
926 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
927 expected_error, desc);
928 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929
930 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
931 SessionDescriptionInterface** nocrypto_answer) {
932 // Create a SDP without Crypto.
933 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000934 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 options.bundle_enabled = true;
936 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
937 ASSERT_TRUE(*offer != NULL);
938 VerifyCryptoParams((*offer)->description());
939
940 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
941 cricket::SEC_DISABLED);
942 EXPECT_TRUE(*nocrypto_answer != NULL);
943 }
944
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000945 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
946 SessionDescriptionInterface** nodtls_answer) {
947 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000948 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000949 options.bundle_enabled = true;
950
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000951 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000952 CreateRemoteOffer(options, cricket::SEC_ENABLED));
953
954 *nodtls_answer =
955 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
956 EXPECT_TRUE(*nodtls_answer != NULL);
957 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
958 VerifyCryptoParams((*nodtls_answer)->description());
959
960 SetFactoryDtlsSrtp();
961 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
962 ASSERT_TRUE(*offer != NULL);
963 VerifyFingerprintStatus((*offer)->description(), true);
964 VerifyCryptoParams((*offer)->description());
965 }
966
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 JsepSessionDescription* CreateRemoteOfferWithVersion(
968 cricket::MediaSessionOptions options,
969 cricket::SecurePolicy secure_policy,
970 const std::string& session_version,
971 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000972 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 const cricket::SessionDescription* cricket_desc = NULL;
974 if (current_desc) {
975 cricket_desc = current_desc->description();
976 session_id = current_desc->session_id();
977 }
978
979 desc_factory_->set_secure(secure_policy);
980 JsepSessionDescription* offer(
981 new JsepSessionDescription(JsepSessionDescription::kOffer));
982 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
983 session_id, session_version)) {
984 delete offer;
985 offer = NULL;
986 }
987 return offer;
988 }
989 JsepSessionDescription* CreateRemoteOffer(
990 cricket::MediaSessionOptions options) {
991 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
992 kSessionVersion, NULL);
993 }
994 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000995 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
996 return CreateRemoteOfferWithVersion(
997 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 }
999 JsepSessionDescription* CreateRemoteOffer(
1000 cricket::MediaSessionOptions options,
1001 const SessionDescriptionInterface* current_desc) {
1002 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1003 kSessionVersion, current_desc);
1004 }
1005
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001006 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1007 const char* sctp_stream_name, int new_port,
1008 cricket::MediaSessionOptions options) {
1009 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001010 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1011 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001012 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1013 }
1014
1015 // Takes ownership of offer_basis (and deletes it).
1016 JsepSessionDescription* ChangeSDPSctpPort(
1017 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1018 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1019 // SessionDescription from the mutated string.
1020 const char* default_port_str = "5000";
1021 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001022 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001023 std::string offer_str;
1024 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001025 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001026 new_port_str, strlen(new_port_str),
1027 &offer_str);
1028 JsepSessionDescription* offer = new JsepSessionDescription(
1029 offer_basis->type());
1030 delete offer_basis;
1031 offer->Initialize(offer_str, NULL);
1032 return offer;
1033 }
1034
deadbeefab9b2d12015-10-14 11:33:11 -07001035 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 // before this function to decide which streams to create.
1037 JsepSessionDescription* CreateRemoteOffer() {
1038 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001039 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 return CreateRemoteOffer(options, session_->remote_description());
1041 }
1042
1043 JsepSessionDescription* CreateRemoteAnswer(
1044 const SessionDescriptionInterface* offer,
1045 cricket::MediaSessionOptions options,
1046 cricket::SecurePolicy policy) {
1047 desc_factory_->set_secure(policy);
1048 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001049 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 JsepSessionDescription* answer(
1051 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1052 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1053 options, NULL),
1054 session_id, kSessionVersion)) {
1055 delete answer;
1056 answer = NULL;
1057 }
1058 return answer;
1059 }
1060
1061 JsepSessionDescription* CreateRemoteAnswer(
1062 const SessionDescriptionInterface* offer,
1063 cricket::MediaSessionOptions options) {
1064 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1065 }
1066
deadbeefab9b2d12015-10-14 11:33:11 -07001067 // Creates an answer session description.
1068 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 // to decide which streams to create.
1070 JsepSessionDescription* CreateRemoteAnswer(
1071 const SessionDescriptionInterface* offer) {
1072 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001073 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1075 }
1076
1077 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001078 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001079 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001080 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001081
1082 PeerConnectionInterface::RTCOfferAnswerOptions options;
1083 options.use_rtp_mux = bundle;
1084
1085 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1087 // and answer.
1088 SetLocalDescriptionWithoutError(offer);
1089
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001090 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001091 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 std::string sdp;
1093 EXPECT_TRUE(answer->ToString(&sdp));
1094
1095 size_t expected_candidate_num = 2;
1096 if (!rtcp_mux) {
1097 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1098 // for rtp and rtcp.
1099 expected_candidate_num = 4;
1100 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 const std::string kRtcpMux = "a=rtcp-mux";
1102 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001103 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 kXRtcpMux.c_str(), kXRtcpMux.length(),
1105 &sdp);
1106 }
1107
1108 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1109 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110
1111 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001112 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1114 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001115 if (bundle) {
1116 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1117 } else {
1118 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 }
1120 }
1121 // Tests that we can only send DTMF when the dtmf codec is supported.
1122 void TestCanInsertDtmf(bool can) {
1123 if (can) {
1124 InitWithDtmfCodec();
1125 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001126 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 }
deadbeefab9b2d12015-10-14 11:33:11 -07001128 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 CreateAndSetRemoteOfferAndLocalAnswer();
1130 EXPECT_FALSE(session_->CanInsertDtmf(""));
1131 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1132 }
1133
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001134 // Helper class to configure loopback network and verify Best
1135 // Connection using right IP protocol for TestLoopbackCall
1136 // method. LoopbackNetworkManager applies firewall rules to block
1137 // all ping traffic once ICE completed, and remove them to observe
1138 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1139 // verifies the best connection is using the right IP protocol after
1140 // initial ICE convergences.
1141
1142 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001143 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001144 LoopbackNetworkConfiguration()
1145 : test_ipv6_network_(false),
1146 test_extra_ipv4_network_(false),
1147 best_connection_after_initial_ice_converged_(1, 0) {}
1148
1149 // Used to track the expected best connection count in each IP protocol.
1150 struct ExpectedBestConnection {
1151 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1152 : ipv4_count_(ipv4_count),
1153 ipv6_count_(ipv6_count) {}
1154
1155 int ipv4_count_;
1156 int ipv6_count_;
1157 };
1158
1159 bool test_ipv6_network_;
1160 bool test_extra_ipv4_network_;
1161 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1162
1163 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001164 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001165 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1166 }
1167
1168 private:
jbauchac8869e2015-07-03 01:36:14 -07001169 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170 const ExpectedBestConnection& expected) const {
1171 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001172 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1173 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001174 expected.ipv4_count_);
1175 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001176 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1177 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001178 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001179 // This is used in the loopback call so there is only single host to host
1180 // candidate pair.
1181 EXPECT_EQ(metrics_observer->GetEnumCounter(
1182 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1183 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001184 0);
1185 EXPECT_EQ(metrics_observer->GetEnumCounter(
1186 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1187 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001188 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001189 }
1190 };
1191
1192 class LoopbackNetworkManager {
1193 public:
1194 LoopbackNetworkManager(WebRtcSessionTest* session,
1195 const LoopbackNetworkConfiguration& config)
1196 : config_(config) {
1197 session->AddInterface(
1198 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1199 if (config_.test_extra_ipv4_network_) {
1200 session->AddInterface(
1201 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1202 }
1203 if (config_.test_ipv6_network_) {
1204 session->AddInterface(
1205 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1206 }
1207 }
1208
1209 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1210 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1211 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1212 if (config_.test_extra_ipv4_network_) {
1213 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1214 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1215 }
1216 if (config_.test_ipv6_network_) {
1217 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1218 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1219 }
1220 }
1221
1222 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1223
1224 private:
1225 LoopbackNetworkConfiguration config_;
1226 };
1227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 // The method sets up a call from the session to itself, in a loopback
1229 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001230 // disconnection, and then a permanent disconnection.
1231 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1233 // While running the call, this method also checks if the session goes through
1234 // the correct sequence of ICE states when a connection is established,
1235 // broken, and re-established.
1236 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001237 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1238 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001240
stefanc1aeaf02015-10-15 07:26:07 -07001241 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001243 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001244 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245
1246 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1247 observer_.ice_gathering_state_);
1248 SetLocalDescriptionWithoutError(offer);
1249 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1250 observer_.ice_connection_state_);
1251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001252 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1254 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001255 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256
1257 std::string sdp;
1258 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001259 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1260 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 ASSERT_TRUE(desc != NULL);
1262 SetRemoteDescriptionWithoutError(desc);
1263
1264 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001265 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001266
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001267 // The ice connection state is "Connected" too briefly to catch in a test.
1268 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001269 observer_.ice_connection_state_, kIceCandidatesTimeout);
1270 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271
stefanc1aeaf02015-10-15 07:26:07 -07001272 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1273 LoopbackNetworkManager loopback_network_manager(this, config);
1274 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 // Adding firewall rule to block ping requests, which should cause
1277 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001278
1279 loopback_network_manager.ApplyFirewallRules(fss_.get());
1280
1281 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1283 observer_.ice_connection_state_,
1284 kIceCandidatesTimeout);
1285
jbauchac8869e2015-07-03 01:36:14 -07001286 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001289 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001292 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 observer_.ice_connection_state_,
1294 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001295
1296 // Now we block ping requests and wait until the ICE connection transitions
1297 // to the Failed state. This will take at least 30 seconds because it must
1298 // wait for the Port to timeout.
1299 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001300
1301 loopback_network_manager.ApplyFirewallRules(fss_.get());
1302 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001303 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304 observer_.ice_connection_state_,
1305 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 }
1307
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308 void TestLoopbackCall() {
1309 LoopbackNetworkConfiguration config;
1310 TestLoopbackCall(config);
1311 }
1312
stefanc1aeaf02015-10-15 07:26:07 -07001313 void TestPacketOptions() {
1314 media_controller_.reset(
1315 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1316 LoopbackNetworkConfiguration config;
1317 LoopbackNetworkManager loopback_network_manager(this, config);
1318
1319 SetupLoopbackCall();
1320
1321 uint8_t test_packet[15] = {0};
1322 rtc::PacketOptions options;
1323 options.packet_id = 10;
1324 media_engine_->GetVideoChannel(0)
1325 ->SendRtp(test_packet, sizeof(test_packet), options);
1326
1327 const int kPacketTimeout = 2000;
1328 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1329 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1330 }
1331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1333 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001334 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1335 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1336
1337 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1339 codecs.push_back(kCNCodec1);
1340 codecs.push_back(kCNCodec2);
1341 media_engine_->SetAudioCodecs(codecs);
1342 desc_factory_->set_audio_codecs(codecs);
1343 }
1344
1345 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1346 const cricket::ContentDescription* description = content->description;
1347 ASSERT(description != NULL);
1348 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001349 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 ASSERT(audio_content_desc != NULL);
1351 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1352 if (audio_content_desc->codecs()[i].name == "CN")
1353 return false;
1354 }
1355 return true;
1356 }
1357
deadbeefab9b2d12015-10-14 11:33:11 -07001358 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001359 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001360 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1361 data_channel_ = DataChannel::Create(
1362 session_.get(), session_->data_channel_type(), "datachannel", dci);
1363 }
1364
1365 void SetLocalDescriptionWithDataChannel() {
1366 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001367 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 SetLocalDescriptionWithoutError(offer);
1369 }
1370
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001372 RTCCertificateGenerationMethod cert_gen_method,
1373 CreateSessionDescriptionRequest::Type type) {
1374 InitWithDtls(cert_gen_method);
1375 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1376 }
1377
1378 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1379 CreateSessionDescriptionRequest::Type type) {
1380 InitWithDtlsIdentityGenFail();
1381 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1382 }
1383
1384 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001385 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001386 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001387 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001388 if (type == CreateSessionDescriptionRequest::kAnswer) {
1389 cricket::MediaSessionOptions options;
1390 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001391 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001392 ASSERT_TRUE(offer.get() != NULL);
1393 SetRemoteDescriptionWithoutError(offer.release());
1394 }
1395
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001396 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001397 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001398 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001399 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001400 observers[kNumber];
1401 for (int i = 0; i < kNumber; ++i) {
1402 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1403 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001404 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001406 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001407 }
1408 }
1409
1410 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1411 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1412 WebRtcSessionCreateSDPObserverForTest::kFailed;
1413
1414 for (int i = 0; i < kNumber; ++i) {
1415 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1416 if (success) {
1417 EXPECT_TRUE(observers[i]->description() != NULL);
1418 } else {
1419 EXPECT_TRUE(observers[i]->description() == NULL);
1420 }
1421 }
1422 }
1423
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001424 void ConfigureAllocatorWithTurn() {
1425 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1426 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1427 relay_server.credentials = credentials;
1428 relay_server.ports.push_back(cricket::ProtocolAddress(
1429 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1430 allocator_->AddRelay(relay_server);
1431 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001432 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001433 }
1434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 cricket::FakeMediaEngine* media_engine_;
1436 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001437 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001438 cricket::FakeCall fake_call_;
1439 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001440 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001441 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1442 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1443 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1444 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1445 rtc::SocketServerScope ss_scope_;
1446 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001447 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001448 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001449 rtc::FakeNetworkManager network_manager_;
1450 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001451 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001452 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001453 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 MockIceObserver observer_;
1455 cricket::FakeVideoMediaChannel* video_channel_;
1456 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001457 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001458 // The following flags affect options created for CreateOffer/CreateAnswer.
1459 bool send_stream_1_ = false;
1460 bool send_stream_2_ = false;
1461 bool send_audio_ = false;
1462 bool send_video_ = false;
1463 rtc::scoped_refptr<DataChannel> data_channel_;
1464 // Last values received from data channel creation signal.
1465 std::string last_data_channel_label_;
1466 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467};
1468
Henrik Boström87713d02015-08-25 09:53:21 +02001469TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1470 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001471 // SDES is disabled when DTLS is on.
1472 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473}
1474
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001476 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 // SDES is required if DTLS is off.
1478 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001479}
1480
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1482 TestSessionCandidatesWithBundleRtcpMux(false, false);
1483}
1484
1485// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1486// with rtcp-mux and/or bundle.
1487TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1488 TestSessionCandidatesWithBundleRtcpMux(false, true);
1489}
1490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1492 TestSessionCandidatesWithBundleRtcpMux(true, true);
1493}
1494
1495TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001496 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1497 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001498 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001499 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 InitiateCall();
1501 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1502 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1503 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1504}
1505
1506TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001507 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1508 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001509 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001510 rtc::FP_UDP,
1511 rtc::FD_ANY,
1512 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001513 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001514 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001516 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1518 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1519 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1520}
1521
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001522// Test session delivers no candidates gathered when constraint set to "none".
1523TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1524 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001525 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001526 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001527 InitiateCall();
1528 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1529 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1530 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1531}
1532
1533// Test session delivers only relay candidates gathered when constaint set to
1534// "relay".
1535TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1536 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1537 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001538 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001539 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001540 InitiateCall();
1541 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1542 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1543 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1544 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1545 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1546 observer_.mline_0_candidates_[i].type());
1547 }
1548 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1549 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1550 observer_.mline_1_candidates_[i].type());
1551 }
1552}
1553
1554// Test session delivers all candidates gathered when constaint set to "all".
1555TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1556 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 InitWithIceTransport(PeerConnectionInterface::kAll);
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 // Host + STUN. By default allocator is disabled to gather relay candidates.
1562 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1563 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1564}
1565
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001566TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001567 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001568 SessionDescriptionInterface* offer = NULL;
1569 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1570 std::string unknown_action;
1571 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1572 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1573}
1574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575// Test creating offers and receive answers and make sure the
1576// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001577TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001578 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001579 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001580 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 const std::string session_id_orig = offer->session_id();
1582 const std::string session_version_orig = offer->session_version();
1583 SetLocalDescriptionWithoutError(offer);
1584
deadbeefab9b2d12015-10-14 11:33:11 -07001585 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 SessionDescriptionInterface* answer =
1587 CreateRemoteAnswer(session_->local_description());
1588 SetRemoteDescriptionWithoutError(answer);
1589
1590 video_channel_ = media_engine_->GetVideoChannel(0);
1591 voice_channel_ = media_engine_->GetVoiceChannel(0);
1592
1593 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1594 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1595
1596 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1597 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1598
1599 ASSERT_EQ(1u, video_channel_->send_streams().size());
1600 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1601 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1602 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1603
1604 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001605 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001606 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607
1608 // Verify the session id is the same and the session version is
1609 // increased.
1610 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001611 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1612 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613
1614 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001615 EXPECT_EQ(0u, video_channel_->send_streams().size());
1616 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617
deadbeefab9b2d12015-10-14 11:33:11 -07001618 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 answer = CreateRemoteAnswer(session_->local_description());
1620 SetRemoteDescriptionWithoutError(answer);
1621
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 // Make sure the receive streams have not changed.
1623 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1624 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1625 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1626 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1627}
1628
1629// Test receiving offers and creating answers and make sure the
1630// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001631TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001632 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001633 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001634 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001635 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 SetRemoteDescriptionWithoutError(offer);
1637
deadbeefab9b2d12015-10-14 11:33:11 -07001638 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001639 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001640 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 SetLocalDescriptionWithoutError(answer);
1642
1643 const std::string session_id_orig = answer->session_id();
1644 const std::string session_version_orig = answer->session_version();
1645
1646 video_channel_ = media_engine_->GetVideoChannel(0);
1647 voice_channel_ = media_engine_->GetVoiceChannel(0);
1648
1649 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1650 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1651
1652 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1653 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1654
1655 ASSERT_EQ(1u, video_channel_->send_streams().size());
1656 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1657 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1658 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1659
deadbeefab9b2d12015-10-14 11:33:11 -07001660 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 SetRemoteDescriptionWithoutError(offer);
1663
1664 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001665 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001666 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667
1668 // Verify the session id is the same and the session version is
1669 // increased.
1670 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001671 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1672 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 SetLocalDescriptionWithoutError(answer);
1674
1675 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1676 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1677 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1678 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1679 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1680 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1681
1682 // Make sure we have no send streams.
1683 EXPECT_EQ(0u, video_channel_->send_streams().size());
1684 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1685}
1686
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001687TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001688 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001689 media_engine_->set_fail_create_channel(true);
1690
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001691 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001692 ASSERT_TRUE(offer != NULL);
1693 // SetRemoteDescription and SetLocalDescription will take the ownership of
1694 // the offer.
1695 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001696 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001697 ASSERT_TRUE(offer != NULL);
1698 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1699}
1700
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001701//
1702// Tests for creating/setting SDP under different SDES/DTLS polices:
1703//
1704// --DTLS off and SDES on
1705// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1706// set local/remote offer/answer with crypto --> success
1707// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1708// failure
1709// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1710// failure
1711// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1712// failure
1713//
1714// --DTLS on and SDES off
1715// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1716// set local/remote offer/answer with DTLS fingerprint --> success
1717// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1718// fingerprint --> failure
1719// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1720// --> failure
1721// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1722// --> failure
1723//
1724// --Encryption disabled: DTLS off and SDES off
1725// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1726// answer without SDES or DTLS --> success
1727// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1728// answer without SDES or DTLS --> success
1729//
1730
1731// Test that we return a failure when applying a remote/local offer that doesn't
1732// have cryptos enabled when DTLS is off.
1733TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001734 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001736 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 JsepSessionDescription* offer = CreateRemoteOffer(
1738 options, cricket::SEC_DISABLED);
1739 ASSERT_TRUE(offer != NULL);
1740 VerifyNoCryptoParams(offer->description(), false);
1741 // SetRemoteDescription and SetLocalDescription will take the ownership of
1742 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1745 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747}
1748
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001749// Test that we return a failure when applying a local answer that doesn't have
1750// cryptos enabled when DTLS is off.
1751TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001752 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 SessionDescriptionInterface* offer = NULL;
1754 SessionDescriptionInterface* answer = NULL;
1755 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1756 // SetRemoteDescription and SetLocalDescription will take the ownership of
1757 // the offer.
1758 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760}
1761
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001762// Test we will return fail when apply an remote answer that doesn't have
1763// crypto enabled when DTLS is off.
1764TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001765 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 SessionDescriptionInterface* offer = NULL;
1767 SessionDescriptionInterface* answer = NULL;
1768 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1769 // SetRemoteDescription and SetLocalDescription will take the ownership of
1770 // the offer.
1771 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773}
1774
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001775// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1776// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001777TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001778 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001779 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001780 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 SetFactoryDtlsSrtp();
1782 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001783 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784 JsepSessionDescription* offer =
1785 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 ASSERT_TRUE(offer != NULL);
1787 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789
1790 // SetRemoteDescription will take the ownership of the offer.
1791 SetRemoteDescriptionWithoutError(offer);
1792
1793 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001794 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 ASSERT_TRUE(answer != NULL);
1796 VerifyFingerprintStatus(answer->description(), true);
1797 // Check that we don't have an a=crypto line in the answer.
1798 VerifyNoCryptoParams(answer->description(), true);
1799
1800 // Now set the local description, which should work, even without a=crypto.
1801 SetLocalDescriptionWithoutError(answer);
1802}
1803
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1805// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001806TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001807 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001808 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001809 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001810 SetFactoryDtlsSrtp();
1811
1812 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001813 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001814 ASSERT_TRUE(offer != NULL);
1815 VerifyFingerprintStatus(offer->description(), true);
1816 // Check that we don't have an a=crypto line in the offer.
1817 VerifyNoCryptoParams(offer->description(), true);
1818
1819 // Now set the local description, which should work, even without a=crypto.
1820 SetLocalDescriptionWithoutError(offer);
1821
1822 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001823 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824 JsepSessionDescription* answer =
1825 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1826 ASSERT_TRUE(answer != NULL);
1827 VerifyFingerprintStatus(answer->description(), true);
1828 VerifyNoCryptoParams(answer->description(), true);
1829
1830 // SetRemoteDescription will take the ownership of the answer.
1831 SetRemoteDescriptionWithoutError(answer);
1832}
1833
1834// Test that if we support DTLS and the other side didn't offer a fingerprint,
1835// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001836TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001837 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001838 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001840 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001841 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 JsepSessionDescription* offer = CreateRemoteOffer(
1843 options, cricket::SEC_REQUIRED);
1844 ASSERT_TRUE(offer != NULL);
1845 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001846 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848 // SetRemoteDescription will take the ownership of the offer.
1849 SetRemoteDescriptionOfferExpectError(
1850 kSdpWithoutDtlsFingerprint, offer);
1851
1852 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1853 // SetLocalDescription will take the ownership of the offer.
1854 SetLocalDescriptionOfferExpectError(
1855 kSdpWithoutDtlsFingerprint, offer);
1856}
1857
1858// Test that we return a failure when applying a local answer that doesn't have
1859// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001860TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001861 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001862 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 SessionDescriptionInterface* offer = NULL;
1864 SessionDescriptionInterface* answer = NULL;
1865 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1866
1867 // SetRemoteDescription and SetLocalDescription will take the ownership of
1868 // the offer and answer.
1869 SetRemoteDescriptionWithoutError(offer);
1870 SetLocalDescriptionAnswerExpectError(
1871 kSdpWithoutDtlsFingerprint, answer);
1872}
1873
1874// Test that we return a failure when applying a remote answer that doesn't have
1875// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001876TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001877 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001878 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001879 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001881 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001882 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1883 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001884 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001885 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001886
1887 // SetRemoteDescription and SetLocalDescription will take the ownership of
1888 // the offer and answer.
1889 SetLocalDescriptionWithoutError(offer);
1890 SetRemoteDescriptionAnswerExpectError(
1891 kSdpWithoutDtlsFingerprint, answer);
1892}
1893
1894// Test that we create a local offer without SDES or DTLS and accept a remote
1895// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001896TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001897 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001899 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900
1901 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001902 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903 ASSERT_TRUE(offer != NULL);
1904 VerifyFingerprintStatus(offer->description(), false);
1905 // Check that we don't have an a=crypto line in the offer.
1906 VerifyNoCryptoParams(offer->description(), false);
1907
1908 // Now set the local description, which should work, even without a=crypto.
1909 SetLocalDescriptionWithoutError(offer);
1910
1911 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001912 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 JsepSessionDescription* answer =
1914 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1915 ASSERT_TRUE(answer != NULL);
1916 VerifyFingerprintStatus(answer->description(), false);
1917 VerifyNoCryptoParams(answer->description(), false);
1918
1919 // SetRemoteDescription will take the ownership of the answer.
1920 SetRemoteDescriptionWithoutError(answer);
1921}
1922
1923// Test that we create a local answer without SDES or DTLS and accept a remote
1924// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001925TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001926 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001927 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928
1929 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001930 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001931 JsepSessionDescription* offer =
1932 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1933 ASSERT_TRUE(offer != NULL);
1934 VerifyFingerprintStatus(offer->description(), false);
1935 VerifyNoCryptoParams(offer->description(), false);
1936
1937 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 SetRemoteDescriptionWithoutError(offer);
1939
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001941 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 ASSERT_TRUE(answer != NULL);
1943 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001944 // Check that we don't have an a=crypto line in the answer.
1945 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001947 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 SetLocalDescriptionWithoutError(answer);
1949}
1950
1951TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001952 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001953 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001955 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 SetLocalDescriptionWithoutError(offer);
1957
1958 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001959 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 SetLocalDescriptionWithoutError(offer2);
1961}
1962
1963TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001964 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001965 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001967 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 SetRemoteDescriptionWithoutError(offer);
1969
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001970 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 SetRemoteDescriptionWithoutError(offer2);
1972}
1973
1974TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001975 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001976 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001977 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001979 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001980 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
1981 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982}
1983
1984TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001985 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001986 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001987 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001989 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001990 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07001991 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992}
1993
1994TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001998 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999
2000 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002001 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002003 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004
deadbeefab9b2d12015-10-14 11:33:11 -07002005 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002007 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2009
deadbeefd59daf82015-10-14 15:02:44 -07002010 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011
deadbeefab9b2d12015-10-14 11:33:11 -07002012 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002013 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002014 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015}
2016
2017TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002018 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002019 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002021 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
2023 JsepSessionDescription* pranswer =
2024 CreateRemoteAnswer(session_->local_description());
2025 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2026
2027 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002028 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029
deadbeefab9b2d12015-10-14 11:33:11 -07002030 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 JsepSessionDescription* pranswer2 =
2032 CreateRemoteAnswer(session_->local_description());
2033 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2034
2035 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002036 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037
deadbeefab9b2d12015-10-14 11:33:11 -07002038 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 SessionDescriptionInterface* answer =
2040 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042}
2043
2044TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2048
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SessionDescriptionInterface* answer =
2050 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002051 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2052 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053}
2054
2055TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002056 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002057 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2059
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 SessionDescriptionInterface* answer =
2061 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002062 SetRemoteDescriptionAnswerExpectError(
2063 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064}
2065
2066TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002067 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002068 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069
2070 cricket::Candidate candidate;
2071 candidate.set_component(1);
2072 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2073
deadbeefd59daf82015-10-14 15:02:44 -07002074 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2076
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002077 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002079
2080 // Fail since we have not set a remote description.
2081 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
2083 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2084 session_->local_description());
2085 SetRemoteDescriptionWithoutError(answer);
2086
deadbeefd59daf82015-10-14 15:02:44 -07002087 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2088 candidate.set_component(2);
2089 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2090 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2091
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 // Verifying the candidates are copied properly from internal vector.
2093 const SessionDescriptionInterface* remote_desc =
2094 session_->remote_description();
2095 ASSERT_TRUE(remote_desc != NULL);
2096 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2097 const IceCandidateCollection* candidates =
2098 remote_desc->candidates(kMediaContentIndex0);
2099 ASSERT_EQ(2u, candidates->count());
2100 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2101 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2102 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2103 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2104
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002105 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2106 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 candidate.set_component(2);
2108 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2109 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002110 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111
2112 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2113 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2114}
2115
2116// Test that a remote candidate is added to the remote session description and
2117// that it is retained if the remote session description is changed.
2118TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002119 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 cricket::Candidate candidate1;
2121 candidate1.set_component(1);
2122 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2123 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002124 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 CreateAndSetRemoteOfferAndLocalAnswer();
2126
2127 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2128 const SessionDescriptionInterface* remote_desc =
2129 session_->remote_description();
2130 ASSERT_TRUE(remote_desc != NULL);
2131 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2132 const IceCandidateCollection* candidates =
2133 remote_desc->candidates(kMediaContentIndex0);
2134 ASSERT_EQ(1u, candidates->count());
2135 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2136
2137 // Update the RemoteSessionDescription with a new session description and
2138 // a candidate and check that the new remote session description contains both
2139 // candidates.
2140 SessionDescriptionInterface* offer = CreateRemoteOffer();
2141 cricket::Candidate candidate2;
2142 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2143 candidate2);
2144 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2145 SetRemoteDescriptionWithoutError(offer);
2146
2147 remote_desc = session_->remote_description();
2148 ASSERT_TRUE(remote_desc != NULL);
2149 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2150 candidates = remote_desc->candidates(kMediaContentIndex0);
2151 ASSERT_EQ(2u, candidates->count());
2152 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2153 // Username and password have be updated with the TransportInfo of the
2154 // SessionDescription, won't be equal to the original one.
2155 candidate2.set_username(candidates->at(0)->candidate().username());
2156 candidate2.set_password(candidates->at(0)->candidate().password());
2157 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2158 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2159 // No need to verify the username and password.
2160 candidate1.set_username(candidates->at(1)->candidate().username());
2161 candidate1.set_password(candidates->at(1)->candidate().password());
2162 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2163
2164 // Test that the candidate is ignored if we can add the same candidate again.
2165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2166}
2167
2168// Test that local candidates are added to the local session description and
2169// that they are retained if the local session description is changed.
2170TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002171 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002172 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002173 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 CreateAndSetRemoteOfferAndLocalAnswer();
2175
2176 const SessionDescriptionInterface* local_desc = session_->local_description();
2177 const IceCandidateCollection* candidates =
2178 local_desc->candidates(kMediaContentIndex0);
2179 ASSERT_TRUE(candidates != NULL);
2180 EXPECT_EQ(0u, candidates->count());
2181
2182 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2183
2184 local_desc = session_->local_description();
2185 candidates = local_desc->candidates(kMediaContentIndex0);
2186 ASSERT_TRUE(candidates != NULL);
2187 EXPECT_LT(0u, candidates->count());
2188 candidates = local_desc->candidates(1);
2189 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002190 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191
2192 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002193 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 CreateAndSetRemoteOfferAndLocalAnswer();
2195
2196 local_desc = session_->local_description();
2197 candidates = local_desc->candidates(kMediaContentIndex0);
2198 ASSERT_TRUE(candidates != NULL);
2199 EXPECT_LT(0u, candidates->count());
2200 candidates = local_desc->candidates(1);
2201 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002202 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203}
2204
2205// Test that we can set a remote session description with remote candidates.
2206TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002207 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208
2209 cricket::Candidate candidate1;
2210 candidate1.set_component(1);
2211 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2212 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002213 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002214 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215
2216 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2217 SetRemoteDescriptionWithoutError(offer);
2218
2219 const SessionDescriptionInterface* remote_desc =
2220 session_->remote_description();
2221 ASSERT_TRUE(remote_desc != NULL);
2222 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2223 const IceCandidateCollection* candidates =
2224 remote_desc->candidates(kMediaContentIndex0);
2225 ASSERT_EQ(1u, candidates->count());
2226 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2227
wu@webrtc.org91053e72013-08-10 07:18:04 +00002228 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 SetLocalDescriptionWithoutError(answer);
2230}
2231
2232// Test that offers and answers contains ice candidates when Ice candidates have
2233// been gathered.
2234TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002235 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002236 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002237 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 // Ice is started but candidates are not provided until SetLocalDescription
2239 // is called.
2240 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2241 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2242 CreateAndSetRemoteOfferAndLocalAnswer();
2243 // Wait until at least one local candidate has been collected.
2244 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2245 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002247 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2250 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251
2252 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2253 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002254 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2256 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 SetLocalDescriptionWithoutError(answer);
2258}
2259
2260// Verifies TransportProxy and media channels are created with content names
2261// present in the SessionDescription.
2262TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002263 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002264 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002265 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266
2267 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002268 // "video". Goal is to modify these content names and verify transport
2269 // channels
2270 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 // present in SDP.
2272 std::string sdp;
2273 EXPECT_TRUE(offer->ToString(&sdp));
2274 const std::string kAudioMid = "a=mid:audio";
2275 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2276 const std::string kVideoMid = "a=mid:video";
2277 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2278
2279 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 kAudioMidReplaceStr.c_str(),
2282 kAudioMidReplaceStr.length(),
2283 &sdp);
2284 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002285 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 kVideoMidReplaceStr.c_str(),
2287 kVideoMidReplaceStr.length(),
2288 &sdp);
2289
2290 SessionDescriptionInterface* modified_offer =
2291 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2292
2293 SetRemoteDescriptionWithoutError(modified_offer);
2294
2295 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002296 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 SetLocalDescriptionWithoutError(answer);
2298
deadbeefcbecd352015-09-23 11:50:27 -07002299 cricket::TransportChannel* voice_transport_channel =
2300 session_->voice_rtp_transport_channel();
2301 EXPECT_TRUE(voice_transport_channel != NULL);
2302 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2303 cricket::TransportChannel* video_transport_channel =
2304 session_->video_rtp_transport_channel();
2305 EXPECT_TRUE(video_transport_channel != NULL);
2306 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2308 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2309}
2310
2311// Test that an offer contains the correct media content descriptions based on
2312// the send streams when no constraints have been set.
2313TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002314 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002315 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 ASSERT_TRUE(offer != NULL);
2318 const cricket::ContentInfo* content =
2319 cricket::GetFirstAudioContent(offer->description());
2320 EXPECT_TRUE(content != NULL);
2321 content = cricket::GetFirstVideoContent(offer->description());
2322 EXPECT_TRUE(content == NULL);
2323}
2324
2325// Test that an offer contains the correct media content descriptions based on
2326// the send streams when no constraints have been set.
2327TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002328 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002330 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002331 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2332
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 const cricket::ContentInfo* content =
2334 cricket::GetFirstAudioContent(offer->description());
2335 EXPECT_TRUE(content != NULL);
2336 content = cricket::GetFirstVideoContent(offer->description());
2337 EXPECT_TRUE(content == NULL);
2338
2339 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002340 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002341 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 content = cricket::GetFirstAudioContent(offer->description());
2343 EXPECT_TRUE(content != NULL);
2344 content = cricket::GetFirstVideoContent(offer->description());
2345 EXPECT_TRUE(content != NULL);
2346}
2347
2348// Test that an offer contains no media content descriptions if
2349// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2350TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002351 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002352 PeerConnectionInterface::RTCOfferAnswerOptions options;
2353 options.offer_to_receive_audio = 0;
2354 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002357 CreateOffer(options));
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 ASSERT_TRUE(offer != NULL);
2360 const cricket::ContentInfo* content =
2361 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 only audio media content descriptions if
2368// kOfferToReceiveAudio constraints are set to true.
2369TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
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 =
2373 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2374
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));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377
2378 const cricket::ContentInfo* content =
2379 cricket::GetFirstAudioContent(offer->description());
2380 EXPECT_TRUE(content != NULL);
2381 content = cricket::GetFirstVideoContent(offer->description());
2382 EXPECT_TRUE(content == NULL);
2383}
2384
2385// Test that an offer contains audio and video media content descriptions if
2386// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2387TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002388 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002390 PeerConnectionInterface::RTCOfferAnswerOptions options;
2391 options.offer_to_receive_audio =
2392 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2393 options.offer_to_receive_video =
2394 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2395
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002396 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397 CreateOffer(options));
2398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 const cricket::ContentInfo* content =
2400 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002401 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 content = cricket::GetFirstVideoContent(offer->description());
2404 EXPECT_TRUE(content != NULL);
2405
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002406 // Sets constraints to false and verifies that audio/video contents are
2407 // removed.
2408 options.offer_to_receive_audio = 0;
2409 options.offer_to_receive_video = 0;
2410 offer.reset(CreateOffer(options));
2411
2412 content = cricket::GetFirstAudioContent(offer->description());
2413 EXPECT_TRUE(content == NULL);
2414 content = cricket::GetFirstVideoContent(offer->description());
2415 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416}
2417
2418// Test that an answer can not be created if the last remote description is not
2419// an offer.
2420TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002421 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002422 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 SetLocalDescriptionWithoutError(offer);
2424 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2425 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002426 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427}
2428
2429// Test that an answer contains the correct media content descriptions when no
2430// constraints have been set.
2431TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002432 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002436 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002437 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 const cricket::ContentInfo* content =
2439 cricket::GetFirstAudioContent(answer->description());
2440 ASSERT_TRUE(content != NULL);
2441 EXPECT_FALSE(content->rejected);
2442
2443 content = cricket::GetFirstVideoContent(answer->description());
2444 ASSERT_TRUE(content != NULL);
2445 EXPECT_FALSE(content->rejected);
2446}
2447
2448// Test that an answer contains the correct media content descriptions when no
2449// constraints have been set and the offer only contain audio.
2450TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
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 only.
2453 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002454
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002455 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 CreateRemoteOffer(options));
2457 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2458 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2459
2460 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002461 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002462 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 const cricket::ContentInfo* content =
2464 cricket::GetFirstAudioContent(answer->description());
2465 ASSERT_TRUE(content != NULL);
2466 EXPECT_FALSE(content->rejected);
2467
2468 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2469}
2470
2471// Test that an answer contains the correct media content descriptions when no
2472// constraints have been set.
2473TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002474 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002476 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 SetRemoteDescriptionWithoutError(offer.release());
2478 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002479 SendAudioVideoStream1();
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 content = cricket::GetFirstVideoContent(answer->description());
2488 ASSERT_TRUE(content != NULL);
2489 EXPECT_FALSE(content->rejected);
2490}
2491
2492// Test that an answer contains the correct media content descriptions when
2493// constraints have been set but no stream is sent.
2494TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002497 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 SetRemoteDescriptionWithoutError(offer.release());
2499
2500 webrtc::FakeConstraints constraints_no_receive;
2501 constraints_no_receive.SetMandatoryReceiveAudio(false);
2502 constraints_no_receive.SetMandatoryReceiveVideo(false);
2503
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002504 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002505 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 const cricket::ContentInfo* content =
2507 cricket::GetFirstAudioContent(answer->description());
2508 ASSERT_TRUE(content != NULL);
2509 EXPECT_TRUE(content->rejected);
2510
2511 content = cricket::GetFirstVideoContent(answer->description());
2512 ASSERT_TRUE(content != NULL);
2513 EXPECT_TRUE(content->rejected);
2514}
2515
2516// Test that an answer contains the correct media content descriptions when
2517// constraints have been set and streams are sent.
2518TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002519 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002521 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 SetRemoteDescriptionWithoutError(offer.release());
2523
2524 webrtc::FakeConstraints constraints_no_receive;
2525 constraints_no_receive.SetMandatoryReceiveAudio(false);
2526 constraints_no_receive.SetMandatoryReceiveVideo(false);
2527
2528 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002529 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002530 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002531 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532
2533 // TODO(perkj): Should the direction be set to SEND_ONLY?
2534 const cricket::ContentInfo* content =
2535 cricket::GetFirstAudioContent(answer->description());
2536 ASSERT_TRUE(content != NULL);
2537 EXPECT_FALSE(content->rejected);
2538
2539 // TODO(perkj): Should the direction be set to SEND_ONLY?
2540 content = cricket::GetFirstVideoContent(answer->description());
2541 ASSERT_TRUE(content != NULL);
2542 EXPECT_FALSE(content->rejected);
2543}
2544
2545TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2546 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002547 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002548 PeerConnectionInterface::RTCOfferAnswerOptions options;
2549 options.offer_to_receive_audio =
2550 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2551 options.voice_activity_detection = false;
2552
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002553 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002554 CreateOffer(options));
2555
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 const cricket::ContentInfo* content =
2557 cricket::GetFirstAudioContent(offer->description());
2558 EXPECT_TRUE(content != NULL);
2559 EXPECT_TRUE(VerifyNoCNCodecs(content));
2560}
2561
2562TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2563 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002564 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002566 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 SetRemoteDescriptionWithoutError(offer.release());
2568
2569 webrtc::FakeConstraints constraints;
2570 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002571 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002572 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 const cricket::ContentInfo* content =
2574 cricket::GetFirstAudioContent(answer->description());
2575 ASSERT_TRUE(content != NULL);
2576 EXPECT_TRUE(VerifyNoCNCodecs(content));
2577}
2578
2579// This test verifies the call setup when remote answer with audio only and
2580// later updates with video.
2581TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002582 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2584 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2585
deadbeefab9b2d12015-10-14 11:33:11 -07002586 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002587 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588
2589 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2591
2592 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2593 // and answer;
2594 SetLocalDescriptionWithoutError(offer);
2595 SetRemoteDescriptionWithoutError(answer);
2596
2597 video_channel_ = media_engine_->GetVideoChannel(0);
2598 voice_channel_ = media_engine_->GetVoiceChannel(0);
2599
2600 ASSERT_TRUE(video_channel_ == NULL);
2601
2602 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2603 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2604 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2605
2606 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002607 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 CreateAndSetRemoteOfferAndLocalAnswer();
2609
2610 video_channel_ = media_engine_->GetVideoChannel(0);
2611 voice_channel_ = media_engine_->GetVoiceChannel(0);
2612
2613 ASSERT_TRUE(video_channel_ != NULL);
2614 ASSERT_TRUE(voice_channel_ != NULL);
2615
2616 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2617 ASSERT_EQ(1u, video_channel_->send_streams().size());
2618 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2619 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2620 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2621 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2622 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2623 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2624
2625 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002626 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 CreateAndSetRemoteOfferAndLocalAnswer();
2628
2629 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2630 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2631 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2632 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2633 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2634}
2635
2636// This test verifies the call setup when remote answer with video only and
2637// later updates with audio.
2638TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002639 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2641 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002642 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002643 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644
2645 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002646 options.recv_audio = false;
2647 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2649 offer, options, cricket::SEC_ENABLED);
2650
2651 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2652 // and answer.
2653 SetLocalDescriptionWithoutError(offer);
2654 SetRemoteDescriptionWithoutError(answer);
2655
2656 video_channel_ = media_engine_->GetVideoChannel(0);
2657 voice_channel_ = media_engine_->GetVoiceChannel(0);
2658
2659 ASSERT_TRUE(voice_channel_ == NULL);
2660 ASSERT_TRUE(video_channel_ != NULL);
2661
2662 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2663 ASSERT_EQ(1u, video_channel_->send_streams().size());
2664 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2665
2666 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002667 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 CreateAndSetRemoteOfferAndLocalAnswer();
2669
2670 voice_channel_ = media_engine_->GetVoiceChannel(0);
2671 ASSERT_TRUE(voice_channel_ != NULL);
2672
2673 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2674 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2675 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2676 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2677
2678 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002679 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 CreateAndSetRemoteOfferAndLocalAnswer();
2681
2682 video_channel_ = media_engine_->GetVideoChannel(0);
2683 voice_channel_ = media_engine_->GetVoiceChannel(0);
2684
2685 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2686 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2687 ASSERT_EQ(1u, video_channel_->send_streams().size());
2688 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2689}
2690
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002692 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002693 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002694 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 VerifyCryptoParams(offer->description());
2696 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002697 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 VerifyCryptoParams(answer->description());
2699}
2700
2701TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002702 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002703 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002704 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002705 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 VerifyNoCryptoParams(offer->description(), false);
2707}
2708
2709TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002710 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 VerifyAnswerFromNonCryptoOffer();
2712}
2713
2714TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002715 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 VerifyAnswerFromCryptoOffer();
2717}
2718
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002719// This test verifies that setLocalDescription fails if
2720// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2721TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
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 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2725
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002726 std::string sdp;
2727 RemoveIceUfragPwdLines(offer.get(), &sdp);
2728 SessionDescriptionInterface* modified_offer =
2729 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002730 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002731}
2732
2733// This test verifies that setRemoteDescription fails if
2734// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2735TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002736 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002737 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002738 std::string sdp;
2739 RemoveIceUfragPwdLines(offer.get(), &sdp);
2740 SessionDescriptionInterface* modified_offer =
2741 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002742 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002743}
2744
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002745// This test verifies that setLocalDescription fails if local offer has
2746// too short ice ufrag and pwd strings.
2747TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002748 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002750 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2751
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002752 std::string sdp;
2753 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2754 // recommended values of 4 and 22 bytes respectively.
2755 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2756 SessionDescriptionInterface* modified_offer =
2757 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2758 std::string error;
2759 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2760
2761 // Test with string greater than 256.
2762 sdp.clear();
2763 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2764 &sdp);
2765 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2766 NULL);
2767 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2768}
2769
2770// This test verifies that setRemoteDescription fails if remote offer has
2771// too short ice ufrag and pwd strings.
2772TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002773 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002774 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002775 std::string sdp;
2776 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2777 // recommended values of 4 and 22 bytes respectively.
2778 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2779 SessionDescriptionInterface* modified_offer =
2780 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2781 std::string error;
2782 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2783
2784 sdp.clear();
2785 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2786 &sdp);
2787 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2788 NULL);
2789 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2790}
2791
honghaiz503726c2015-07-31 12:37:38 -07002792// Test that if the remote description indicates the peer requested ICE restart
2793// (via a new ufrag or pwd), the old ICE candidates are not copied,
2794// and vice versa.
2795TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2796 Init();
2797 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2798
2799 // Create the first offer.
2800 std::string sdp;
2801 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2802 "abcdefghijklmnopqrstuvwx", &sdp);
2803 SessionDescriptionInterface* offer1 =
2804 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2805 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2806 0, "", "", "relay", 0, "");
2807 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2808 candidate1);
2809 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2810 SetRemoteDescriptionWithoutError(offer1);
2811 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2812
2813 // The second offer has the same ufrag and pwd but different address.
2814 sdp.clear();
2815 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2816 "abcdefghijklmnopqrstuvwx", &sdp);
2817 SessionDescriptionInterface* offer2 =
2818 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2819 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2820 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2821 candidate1);
2822 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2823 SetRemoteDescriptionWithoutError(offer2);
2824 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2825
2826 // The third offer has a different ufrag and different address.
2827 sdp.clear();
2828 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2829 "abcdefghijklmnopqrstuvwx", &sdp);
2830 SessionDescriptionInterface* offer3 =
2831 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2832 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2833 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2834 candidate1);
2835 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2836 SetRemoteDescriptionWithoutError(offer3);
2837 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2838
2839 // The fourth offer has no candidate but a different ufrag/pwd.
2840 sdp.clear();
2841 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2842 "abcdefghijklmnopqrstuvyz", &sdp);
2843 SessionDescriptionInterface* offer4 =
2844 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2845 SetRemoteDescriptionWithoutError(offer4);
2846 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2847}
2848
Donald Curtisd4f769d2015-05-28 09:48:21 -07002849// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002850// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002851TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2852 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2853
2854 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002855 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002856
2857 PeerConnectionInterface::RTCOfferAnswerOptions options;
2858 options.use_rtp_mux = true;
2859
2860 SessionDescriptionInterface* offer = CreateRemoteOffer();
2861 SetRemoteDescriptionWithoutError(offer);
2862
2863 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2864 SetLocalDescriptionWithoutError(answer);
2865
deadbeefcbecd352015-09-23 11:50:27 -07002866 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2867 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002868
deadbeefcbecd352015-09-23 11:50:27 -07002869 cricket::BaseChannel* voice_channel = session_->voice_channel();
2870 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002871
2872 // Checks if one of the transport channels contains a connection using a given
2873 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002874 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002875 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002876 session_->GetChannelTransportStats(voice_channel, &stats);
2877 for (auto& kv : stats.transport_stats) {
2878 for (auto& chan_stat : kv.second.channel_stats) {
2879 for (auto& conn_info : chan_stat.connection_infos) {
2880 if (conn_info.remote_candidate.address().port() == port) {
2881 return true;
2882 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002883 }
2884 }
2885 }
2886 return false;
2887 };
2888
2889 EXPECT_FALSE(connection_with_remote_port(5000));
2890 EXPECT_FALSE(connection_with_remote_port(5001));
2891 EXPECT_FALSE(connection_with_remote_port(6000));
2892
2893 // The way the *_WAIT checks work is they only wait if the condition fails,
2894 // which does not help in the case where state is not changing. This is
2895 // problematic in this test since we want to verify that adding a video
2896 // candidate does _not_ change state. So we interleave candidates and assume
2897 // that messages are executed in the order they were posted.
2898
2899 // First audio candidate.
2900 cricket::Candidate candidate0;
2901 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2902 candidate0.set_component(1);
2903 candidate0.set_protocol("udp");
2904 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2905 candidate0);
2906 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2907
2908 // Video candidate.
2909 cricket::Candidate candidate1;
2910 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2911 candidate1.set_component(1);
2912 candidate1.set_protocol("udp");
2913 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2914 candidate1);
2915 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2916
2917 // Second audio candidate.
2918 cricket::Candidate candidate2;
2919 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2920 candidate2.set_component(1);
2921 candidate2.set_protocol("udp");
2922 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2923 candidate2);
2924 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2925
2926 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2927 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2928
2929 // No need here for a _WAIT check since we are checking that state hasn't
2930 // changed: if this is false we would be doing waits for nothing and if this
2931 // is true then there will be no messages processed anyways.
2932 EXPECT_FALSE(connection_with_remote_port(6000));
2933}
2934
deadbeefcbecd352015-09-23 11:50:27 -07002935// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002936TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2937 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002938 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002939
2940 PeerConnectionInterface::RTCOfferAnswerOptions options;
2941 options.use_rtp_mux = true;
2942
2943 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002944 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002945
deadbeefcbecd352015-09-23 11:50:27 -07002946 EXPECT_NE(session_->voice_rtp_transport_channel(),
2947 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002948
deadbeefab9b2d12015-10-14 11:33:11 -07002949 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002950 SessionDescriptionInterface* answer =
2951 CreateRemoteAnswer(session_->local_description());
2952 SetRemoteDescriptionWithoutError(answer);
2953
deadbeefcbecd352015-09-23 11:50:27 -07002954 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2955 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002956}
2957
deadbeefcbecd352015-09-23 11:50:27 -07002958// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002959TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2960 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002961 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002962
Donald Curtis0e209b02015-03-24 09:29:54 -07002963 PeerConnectionInterface::RTCOfferAnswerOptions options;
2964 options.use_rtp_mux = true;
2965
2966 SessionDescriptionInterface* offer = CreateOffer(options);
2967 SetLocalDescriptionWithoutError(offer);
2968
deadbeefcbecd352015-09-23 11:50:27 -07002969 EXPECT_NE(session_->voice_rtp_transport_channel(),
2970 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002971
deadbeefab9b2d12015-10-14 11:33:11 -07002972 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002973
2974 // Remove BUNDLE from the answer.
2975 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2976 CreateRemoteAnswer(session_->local_description()));
2977 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2978 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2979 JsepSessionDescription* modified_answer =
2980 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2981 modified_answer->Initialize(answer_copy, "1", "1");
2982 SetRemoteDescriptionWithoutError(modified_answer); //
2983
deadbeefcbecd352015-09-23 11:50:27 -07002984 EXPECT_NE(session_->voice_rtp_transport_channel(),
2985 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002986}
2987
2988// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2989TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2990 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002991 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07002992
2993 PeerConnectionInterface::RTCOfferAnswerOptions options;
2994 options.use_rtp_mux = true;
2995
2996 SessionDescriptionInterface* offer = CreateOffer(options);
2997 SetLocalDescriptionWithoutError(offer);
2998
deadbeefcbecd352015-09-23 11:50:27 -07002999 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3000 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003001
deadbeefab9b2d12015-10-14 11:33:11 -07003002 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003003 SessionDescriptionInterface* answer =
3004 CreateRemoteAnswer(session_->local_description());
3005 SetRemoteDescriptionWithoutError(answer);
3006
deadbeefcbecd352015-09-23 11:50:27 -07003007 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3008 session_->video_rtp_transport_channel());
3009}
3010
3011// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3012// audio content in the answer.
3013TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3014 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003015 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003016
3017 PeerConnectionInterface::RTCOfferAnswerOptions options;
3018 options.use_rtp_mux = true;
3019
3020 SessionDescriptionInterface* offer = CreateOffer(options);
3021 SetLocalDescriptionWithoutError(offer);
3022
3023 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3024 session_->video_rtp_transport_channel());
3025
deadbeefab9b2d12015-10-14 11:33:11 -07003026 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003027 cricket::MediaSessionOptions recv_options;
3028 recv_options.recv_audio = false;
3029 recv_options.recv_video = true;
3030 SessionDescriptionInterface* answer =
3031 CreateRemoteAnswer(session_->local_description(), recv_options);
3032 SetRemoteDescriptionWithoutError(answer);
3033
deadbeefd59daf82015-10-14 15:02:44 -07003034 EXPECT_TRUE(nullptr == session_->voice_channel());
3035 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003036
deadbeefd59daf82015-10-14 15:02:44 -07003037 session_->Close();
3038 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3039 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3040 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3041 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003042}
3043
3044// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3045TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3046 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003047 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003048
Donald Curtis0e209b02015-03-24 09:29:54 -07003049 PeerConnectionInterface::RTCOfferAnswerOptions options;
3050 options.use_rtp_mux = true;
3051
3052 SessionDescriptionInterface* offer = CreateOffer(options);
3053 SetLocalDescriptionWithoutError(offer);
3054
deadbeefcbecd352015-09-23 11:50:27 -07003055 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3056 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003057
deadbeefab9b2d12015-10-14 11:33:11 -07003058 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003059
3060 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003061 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003062 CreateRemoteAnswer(session_->local_description()));
3063 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3064 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3065 JsepSessionDescription* modified_answer =
3066 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3067 modified_answer->Initialize(answer_copy, "1", "1");
3068 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069
deadbeefcbecd352015-09-23 11:50:27 -07003070 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3071 session_->video_rtp_transport_channel());
3072}
3073
3074// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3075TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3076 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003077 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003078
3079 SessionDescriptionInterface* offer = CreateRemoteOffer();
3080 SetRemoteDescriptionWithoutError(offer);
3081
3082 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3083 session_->video_rtp_transport_channel());
3084
deadbeefab9b2d12015-10-14 11:33:11 -07003085 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003086 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3087 SetLocalDescriptionWithoutError(answer);
3088
3089 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3090 session_->video_rtp_transport_channel());
3091}
3092
3093// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3094TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3095 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003096 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003097
3098 // Remove BUNDLE from the offer.
3099 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3100 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3101 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3102 JsepSessionDescription* modified_offer =
3103 new JsepSessionDescription(JsepSessionDescription::kOffer);
3104 modified_offer->Initialize(offer_copy, "1", "1");
3105
3106 // Expect an error when applying the remote description
3107 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3108 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003109}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003110
Peter Thatcher4eddf182015-04-30 10:55:59 -07003111// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003112TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3113 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003114 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003115
Donald Curtis0e209b02015-03-24 09:29:54 -07003116 PeerConnectionInterface::RTCOfferAnswerOptions options;
3117 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118
Donald Curtis0e209b02015-03-24 09:29:54 -07003119 SessionDescriptionInterface* offer = CreateOffer(options);
3120 SetLocalDescriptionWithoutError(offer);
3121
deadbeefcbecd352015-09-23 11:50:27 -07003122 EXPECT_NE(session_->voice_rtp_transport_channel(),
3123 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
deadbeefab9b2d12015-10-14 11:33:11 -07003125 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003126 SessionDescriptionInterface* answer =
3127 CreateRemoteAnswer(session_->local_description());
3128 SetRemoteDescriptionWithoutError(answer);
3129
3130 // This should lead to an audio-only call but isn't implemented
3131 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003132 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3133 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003134}
3135
deadbeefcbecd352015-09-23 11:50:27 -07003136// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003137TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3138 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003139 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003140 PeerConnectionInterface::RTCOfferAnswerOptions options;
3141 options.use_rtp_mux = true;
3142
3143 SessionDescriptionInterface* offer = CreateOffer(options);
3144 SetLocalDescriptionWithoutError(offer);
3145
deadbeefcbecd352015-09-23 11:50:27 -07003146 EXPECT_NE(session_->voice_rtp_transport_channel(),
3147 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003148
deadbeefab9b2d12015-10-14 11:33:11 -07003149 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003150
3151 // Remove BUNDLE from the answer.
3152 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3153 CreateRemoteAnswer(session_->local_description()));
3154 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3155 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3156 JsepSessionDescription* modified_answer =
3157 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3158 modified_answer->Initialize(answer_copy, "1", "1");
3159 SetRemoteDescriptionWithoutError(modified_answer); //
3160
deadbeefcbecd352015-09-23 11:50:27 -07003161 EXPECT_NE(session_->voice_rtp_transport_channel(),
3162 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003163}
3164
Peter Thatcher4eddf182015-04-30 10:55:59 -07003165// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3166TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3167 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003168 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003169
3170 PeerConnectionInterface::RTCOfferAnswerOptions options;
3171 options.use_rtp_mux = true;
3172
3173 SessionDescriptionInterface* offer = CreateOffer(options);
3174 SetRemoteDescriptionWithoutError(offer);
3175
deadbeefcbecd352015-09-23 11:50:27 -07003176 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3177 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003178}
3179
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003180TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3181 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003182 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003183
3184 PeerConnectionInterface::RTCOfferAnswerOptions options;
3185 SessionDescriptionInterface* offer = CreateOffer(options);
3186 SetLocalDescriptionWithoutError(offer);
3187
deadbeefcbecd352015-09-23 11:50:27 -07003188 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3189 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003190
deadbeefab9b2d12015-10-14 11:33:11 -07003191 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003192 SessionDescriptionInterface* answer =
3193 CreateRemoteAnswer(session_->local_description());
3194 SetRemoteDescriptionWithoutError(answer);
3195
deadbeefcbecd352015-09-23 11:50:27 -07003196 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3197 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003198}
3199
3200TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3201 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003202 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003203
3204 PeerConnectionInterface::RTCOfferAnswerOptions options;
3205 SessionDescriptionInterface* offer = CreateOffer(options);
3206 SetLocalDescriptionWithoutError(offer);
3207
deadbeefcbecd352015-09-23 11:50:27 -07003208 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3209 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003210
deadbeefab9b2d12015-10-14 11:33:11 -07003211 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003212 SessionDescriptionInterface* answer =
3213 CreateRemoteAnswer(session_->local_description());
3214 SetRemoteDescriptionWithoutError(answer);
3215
deadbeefcbecd352015-09-23 11:50:27 -07003216 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3217 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003218}
3219
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003220// This test verifies that SetLocalDescription and SetRemoteDescription fails
3221// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3222TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003223 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003224 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003225
3226 PeerConnectionInterface::RTCOfferAnswerOptions options;
3227 options.use_rtp_mux = true;
3228
3229 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003230 std::string offer_str;
3231 offer->ToString(&offer_str);
3232 // Disable rtcp-mux
3233 const std::string rtcp_mux = "rtcp-mux";
3234 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003235 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003236 xrtcp_mux.c_str(), xrtcp_mux.length(),
3237 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003238 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003239 new JsepSessionDescription(JsepSessionDescription::kOffer);
3240 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003241 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003242 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003243 new JsepSessionDescription(JsepSessionDescription::kOffer);
3244 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003245 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003246 // Trying unmodified SDP.
3247 SetLocalDescriptionWithoutError(offer);
3248}
3249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003251 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253 CreateAndSetRemoteOfferAndLocalAnswer();
3254 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3255 ASSERT_TRUE(channel != NULL);
3256 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003257 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003258 double volume;
3259 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3260 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003261 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003262 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3263 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003264 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003265 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3266 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267}
3268
3269TEST_F(WebRtcSessionTest, SetAudioSend) {
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->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003276 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3278
3279 cricket::AudioOptions options;
3280 options.echo_cancellation.Set(true);
3281
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003282 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003283 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3285 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003286 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003288 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003289 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3291 bool value;
3292 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3293 EXPECT_TRUE(value);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003294 EXPECT_TRUE(renderer->sink() == NULL);
3295}
3296
3297TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003298 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003299 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003300 CreateAndSetRemoteOfferAndLocalAnswer();
3301 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3302 ASSERT_TRUE(channel != NULL);
3303 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003304 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003305
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003306 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003307 cricket::AudioOptions options;
3308 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3309 EXPECT_TRUE(renderer->sink() != NULL);
3310
3311 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3312 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3313 // SetSink(NULL) callback afterwards.
3314 renderer.reset();
3315
3316 // This will trigger SetSink(NULL) if no OnClose() callback.
3317 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318}
3319
3320TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003321 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003322 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323 CreateAndSetRemoteOfferAndLocalAnswer();
3324 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3325 ASSERT_TRUE(channel != NULL);
3326 ASSERT_LT(0u, channel->renderers().size());
3327 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3328 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003329 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 cricket::FakeVideoRenderer renderer;
3331 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3332 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3333 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3334 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3335}
3336
3337TEST_F(WebRtcSessionTest, SetVideoSend) {
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_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003344 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3346 cricket::VideoOptions* options = NULL;
3347 session_->SetVideoSend(send_ssrc, false, options);
3348 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3349 session_->SetVideoSend(send_ssrc, true, options);
3350 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3351}
3352
3353TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3354 TestCanInsertDtmf(false);
3355}
3356
3357TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3358 TestCanInsertDtmf(true);
3359}
3360
3361TEST_F(WebRtcSessionTest, InsertDtmf) {
3362 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003363 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003364 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 CreateAndSetRemoteOfferAndLocalAnswer();
3366 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3367 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3368
3369 // Insert DTMF
3370 const int expected_flags = DF_SEND;
3371 const int expected_duration = 90;
3372 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3373 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3374 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3375
3376 // Verify
3377 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003378 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3380 expected_duration, expected_flags));
3381 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3382 expected_duration, expected_flags));
3383 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3384 expected_duration, expected_flags));
3385}
3386
deadbeefd59daf82015-10-14 15:02:44 -07003387// This test verifies the |initial_offerer| flag when session initiates the
3388// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003390 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003391 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003392 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003393 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3394 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003395 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003397 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398}
3399
deadbeefd59daf82015-10-14 15:02:44 -07003400// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003401TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003402 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003403 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 SessionDescriptionInterface* offer = CreateRemoteOffer();
3405 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003406 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407
deadbeefd59daf82015-10-14 15:02:44 -07003408 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003410 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411}
3412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3414TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003415 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003416 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003417 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003419 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 CreateRemoteAnswer(session_->local_description()));
3421
3422 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3423 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003424 JsepSessionDescription* modified_answer =
3425 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426
3427 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3428 answer->session_id(),
3429 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003430 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431
wu@webrtc.org4e393072014-04-07 17:04:35 +00003432 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 std::string sdp;
3434 EXPECT_TRUE(answer->ToString(&sdp));
3435 const std::string kAudioMid = "a=mid:audio";
3436 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003437 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 kAudioMidReplaceStr.c_str(),
3439 kAudioMidReplaceStr.length(),
3440 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003441 SessionDescriptionInterface* modified_answer1 =
3442 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003443 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444
wu@webrtc.org4e393072014-04-07 17:04:35 +00003445 // Different media types.
3446 EXPECT_TRUE(answer->ToString(&sdp));
3447 const std::string kAudioMline = "m=audio";
3448 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003449 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003450 kAudioMlineReplaceStr.c_str(),
3451 kAudioMlineReplaceStr.length(),
3452 &sdp);
3453 SessionDescriptionInterface* modified_answer2 =
3454 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3455 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 SetRemoteDescriptionWithoutError(answer.release());
3458}
3459
3460// Verifying remote offer and local answer have matching m-lines as per
3461// RFC 3264.
3462TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003463 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003464 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 SessionDescriptionInterface* offer = CreateRemoteOffer();
3466 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003467 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468
3469 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3470 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003471 JsepSessionDescription* modified_answer =
3472 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473
3474 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3475 answer->session_id(),
3476 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003477 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 SetLocalDescriptionWithoutError(answer);
3479}
3480
3481// This test verifies that WebRtcSession does not start candidate allocation
3482// before SetLocalDescription is called.
3483TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003484 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003485 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 SessionDescriptionInterface* offer = CreateRemoteOffer();
3487 cricket::Candidate candidate;
3488 candidate.set_component(1);
3489 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3490 candidate);
3491 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3492 cricket::Candidate candidate1;
3493 candidate1.set_component(1);
3494 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3495 candidate1);
3496 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3497 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003498 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3499 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500
3501 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003502 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3504 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3505
wu@webrtc.org91053e72013-08-10 07:18:04 +00003506 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3509}
3510
3511// This test verifies that crypto parameter is updated in local session
3512// description as per security policy set in MediaSessionDescriptionFactory.
3513TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003514 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003515 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003516 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517
3518 // Making sure SetLocalDescription correctly sets crypto value in
3519 // SessionDescription object after de-serialization of sdp string. The value
3520 // will be set as per MediaSessionDescriptionFactory.
3521 std::string offer_str;
3522 offer->ToString(&offer_str);
3523 SessionDescriptionInterface* jsep_offer_str =
3524 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3525 SetLocalDescriptionWithoutError(jsep_offer_str);
3526 EXPECT_TRUE(session_->voice_channel()->secure_required());
3527 EXPECT_TRUE(session_->video_channel()->secure_required());
3528}
3529
3530// This test verifies the crypto parameter when security is disabled.
3531TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003532 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003533 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003534 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003535 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536
3537 // Making sure SetLocalDescription correctly sets crypto value in
3538 // SessionDescription object after de-serialization of sdp string. The value
3539 // will be set as per MediaSessionDescriptionFactory.
3540 std::string offer_str;
3541 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003542 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003543 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3544 SetLocalDescriptionWithoutError(jsep_offer_str);
3545 EXPECT_FALSE(session_->voice_channel()->secure_required());
3546 EXPECT_FALSE(session_->video_channel()->secure_required());
3547}
3548
3549// This test verifies that an answer contains new ufrag and password if an offer
3550// with new ufrag and password is received.
3551TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003552 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003554 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003555 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556 CreateRemoteOffer(options));
3557 SetRemoteDescriptionWithoutError(offer.release());
3558
deadbeefab9b2d12015-10-14 11:33:11 -07003559 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003560 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003561 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SetLocalDescriptionWithoutError(answer.release());
3563
3564 // Receive an offer with new ufrag and password.
3565 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003566 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003567 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 SetRemoteDescriptionWithoutError(updated_offer1.release());
3569
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003570 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003571 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572
3573 CompareIceUfragAndPassword(updated_answer1->description(),
3574 session_->local_description()->description(),
3575 false);
3576
3577 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003578}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579
wu@webrtc.org91053e72013-08-10 07:18:04 +00003580// This test verifies that an answer contains old ufrag and password if an offer
3581// with old ufrag and password is received.
3582TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003583 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003584 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003585 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003586 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003587 CreateRemoteOffer(options));
3588 SetRemoteDescriptionWithoutError(offer.release());
3589
deadbeefab9b2d12015-10-14 11:33:11 -07003590 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003591 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003592 CreateAnswer(NULL));
3593 SetLocalDescriptionWithoutError(answer.release());
3594
3595 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003597 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003598 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599 SetRemoteDescriptionWithoutError(updated_offer2.release());
3600
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003601 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003602 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603
3604 CompareIceUfragAndPassword(updated_answer2->description(),
3605 session_->local_description()->description(),
3606 true);
3607
3608 SetLocalDescriptionWithoutError(updated_answer2.release());
3609}
3610
3611TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003612 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003613 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003614 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003615 const std::string session_id_orig = offer->session_id();
3616 const std::string session_version_orig = offer->session_version();
3617 SetLocalDescriptionWithoutError(offer);
3618
3619 video_channel_ = media_engine_->GetVideoChannel(0);
3620 video_channel_->set_fail_set_send_codecs(true);
3621
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003622 SessionDescriptionInterface* answer =
3623 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003624 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003625
3626 // Test that after a content error, setting any description will
3627 // result in an error.
3628 video_channel_->set_fail_set_send_codecs(false);
3629 answer = CreateRemoteAnswer(session_->local_description());
3630 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3631 offer = CreateRemoteOffer();
3632 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633}
3634
3635// Runs the loopback call test with BUNDLE and STUN disabled.
3636TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3637 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003638 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003639 cricket::PORTALLOCATOR_DISABLE_STUN |
3640 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641 TestLoopbackCall();
3642}
3643
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003644TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003645 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003646 cricket::PORTALLOCATOR_DISABLE_STUN |
3647 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3648 cricket::PORTALLOCATOR_DISABLE_RELAY);
3649
3650 // best connection is IPv6 since it has higher network preference.
3651 LoopbackNetworkConfiguration config;
3652 config.test_ipv6_network_ = true;
3653 config.best_connection_after_initial_ice_converged_ =
3654 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3655
3656 TestLoopbackCall(config);
3657}
3658
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003659// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003660TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003661 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3662 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003663 TestLoopbackCall();
3664}
3665
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3667 constraints_.reset(new FakeConstraints());
3668 constraints_->AddOptional(
3669 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003670 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671
3672 SetLocalDescriptionWithDataChannel();
3673 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3674}
3675
Henrik Boström87713d02015-08-25 09:53:21 +02003676TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003677 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003678
3679 constraints_.reset(new FakeConstraints());
3680 constraints_->AddOptional(
3681 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003682 options_.disable_sctp_data_channels = false;
3683
Henrik Boström87713d02015-08-25 09:53:21 +02003684 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003685
3686 SetLocalDescriptionWithDataChannel();
3687 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3688}
3689
Henrik Boström87713d02015-08-25 09:53:21 +02003690TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003691 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003692
Henrik Boström87713d02015-08-25 09:53:21 +02003693 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003694
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003695 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003696 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003697 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3698}
3699
Henrik Boström87713d02015-08-25 09:53:21 +02003700TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003701 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003702 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003703 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003704
3705 // Create remote offer with SCTP.
3706 cricket::MediaSessionOptions options;
3707 options.data_channel_type = cricket::DCT_SCTP;
3708 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003709 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003710 SetRemoteDescriptionWithoutError(offer);
3711
3712 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003713 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003714 EXPECT_TRUE(answer != NULL);
3715 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3716 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003717}
3718
Henrik Boström87713d02015-08-25 09:53:21 +02003719TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003720 constraints_.reset(new FakeConstraints());
3721 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003722 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003723 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003724
3725 SetLocalDescriptionWithDataChannel();
3726 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3727}
3728
Henrik Boström87713d02015-08-25 09:53:21 +02003729TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003730 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003731
Henrik Boström87713d02015-08-25 09:53:21 +02003732 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003733
3734 SetLocalDescriptionWithDataChannel();
3735 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3736}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003737
Henrik Boström87713d02015-08-25 09:53:21 +02003738TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003739 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003740 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003741 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003742
3743 SetLocalDescriptionWithDataChannel();
3744 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3745}
3746
Henrik Boström87713d02015-08-25 09:53:21 +02003747TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003748 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003749 const int new_send_port = 9998;
3750 const int new_recv_port = 7775;
3751
Henrik Boström87713d02015-08-25 09:53:21 +02003752 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003753 SetFactoryDtlsSrtp();
3754
3755 // By default, don't actually add the codecs to desc_factory_; they don't
3756 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3757 // let the session description get parsed. That'll get the proper codecs
3758 // into the stream.
3759 cricket::MediaSessionOptions options;
3760 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3761 "stream1", new_send_port, options);
3762
3763 // SetRemoteDescription will take the ownership of the offer.
3764 SetRemoteDescriptionWithoutError(offer);
3765
3766 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3767 new_recv_port, CreateAnswer(NULL));
3768 ASSERT_TRUE(answer != NULL);
3769
3770 // Now set the local description, which'll take ownership of the answer.
3771 SetLocalDescriptionWithoutError(answer);
3772
3773 // TEST PLAN: Set the port number to something new, set it in the SDP,
3774 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003775 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003776 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003777
3778 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3779 int portnum = -1;
3780 ASSERT_TRUE(ch != NULL);
3781 ASSERT_EQ(1UL, ch->send_codecs().size());
3782 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003783 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003784 ch->send_codecs()[0].name.c_str()));
3785 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3786 &portnum));
3787 EXPECT_EQ(new_send_port, portnum);
3788
3789 ASSERT_EQ(1UL, ch->recv_codecs().size());
3790 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003791 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003792 ch->recv_codecs()[0].name.c_str()));
3793 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3794 &portnum));
3795 EXPECT_EQ(new_recv_port, portnum);
3796}
3797
deadbeefab9b2d12015-10-14 11:33:11 -07003798// Verifies that when a session's DataChannel receives an OPEN message,
3799// WebRtcSession signals the DataChannel creation request with the expected
3800// config.
3801TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3803
3804 InitWithDtls(GetParam());
3805
3806 SetLocalDescriptionWithDataChannel();
3807 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3808
3809 webrtc::DataChannelInit config;
3810 config.id = 1;
3811 rtc::Buffer payload;
3812 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3813 cricket::ReceiveDataParams params;
3814 params.ssrc = config.id;
3815 params.type = cricket::DMT_CONTROL;
3816
3817 cricket::DataChannel* data_channel = session_->data_channel();
3818 data_channel->SignalDataReceived(data_channel, params, payload);
3819
3820 EXPECT_EQ("a", last_data_channel_label_);
3821 EXPECT_EQ(config.id, last_data_channel_config_.id);
3822 EXPECT_FALSE(last_data_channel_config_.negotiated);
3823 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3824 last_data_channel_config_.open_handshake_role);
3825}
3826
3827TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003828 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3829 FakeDtlsIdentityStore::GenerateCertificate();
3830
3831 PeerConnectionInterface::RTCConfiguration configuration;
3832 configuration.certificates.push_back(certificate);
3833 Init(nullptr, configuration);
3834 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3835
3836 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3837}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003838
Henrik Boström87713d02015-08-25 09:53:21 +02003839// Verifies that CreateOffer succeeds when CreateOffer is called before async
3840// identity generation is finished (even if a certificate is provided this is
3841// an async op).
3842TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3843 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3844 InitWithDtls(GetParam());
3845
Henrik Boströmd8281982015-08-27 10:12:24 +02003846 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003847 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003848 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3849
wu@webrtc.org91053e72013-08-10 07:18:04 +00003850 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003851 VerifyNoCryptoParams(offer->description(), true);
3852 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003853}
3854
3855// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003856// identity generation is finished (even if a certificate is provided this is
3857// an async op).
3858TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003859 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003860 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003861 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003862
3863 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003864 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003865 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003866 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003867 ASSERT_TRUE(offer.get() != NULL);
3868 SetRemoteDescriptionWithoutError(offer.release());
3869
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003870 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003871 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003872 VerifyNoCryptoParams(answer->description(), true);
3873 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003874}
3875
3876// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003877// identity generation is finished (even if a certificate is provided this is
3878// an async op).
3879TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003880 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003881 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003882
Henrik Boströmd8281982015-08-27 10:12:24 +02003883 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003884
3885 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003886 EXPECT_TRUE(offer != NULL);
3887}
3888
3889// Verifies that CreateOffer fails when CreateOffer is called after async
3890// identity generation fails.
3891TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003892 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003893 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003894
Henrik Boströmd8281982015-08-27 10:12:24 +02003895 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003896
3897 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003898 EXPECT_TRUE(offer == NULL);
3899}
3900
3901// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3902// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003903TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003904 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003905 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003906 VerifyMultipleAsyncCreateDescription(GetParam(),
3907 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003908}
3909
3910// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3911// before async identity generation fails.
3912TEST_F(WebRtcSessionTest,
3913 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003914 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003915 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3916 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003917}
3918
3919// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3920// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003921TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003922 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003923 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003924 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003925 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003926}
3927
3928// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3929// before async identity generation fails.
3930TEST_F(WebRtcSessionTest,
3931 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003932 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003933 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3934 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003935}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003936
3937// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3938// offer has no SDES crypto but only DTLS fingerprint.
3939TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3940 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003941 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003942 // Create a remote offer with secured transport disabled.
3943 cricket::MediaSessionOptions options;
3944 JsepSessionDescription* offer(CreateRemoteOffer(
3945 options, cricket::SEC_DISABLED));
3946 // Adds a DTLS fingerprint to the remote offer.
3947 cricket::SessionDescription* sdp = offer->description();
3948 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3949 ASSERT_TRUE(audio != NULL);
3950 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3951 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003952 rtc::SSLFingerprint::CreateFromRfc4572(
3953 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003954 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003955 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003956}
3957
wu@webrtc.orgde305012013-10-31 15:40:38 +00003958// This test verifies DSCP is properly applied on the media channels.
3959TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3960 constraints_.reset(new FakeConstraints());
3961 constraints_->AddOptional(
3962 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003963 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003964 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003965 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003966
3967 SetLocalDescriptionWithoutError(offer);
3968
3969 video_channel_ = media_engine_->GetVideoChannel(0);
3970 voice_channel_ = media_engine_->GetVoiceChannel(0);
3971
3972 ASSERT_TRUE(video_channel_ != NULL);
3973 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003974 const cricket::AudioOptions& audio_options = voice_channel_->options();
3975 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003976 EXPECT_TRUE(audio_options.dscp.IsSet());
3977 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3978 EXPECT_TRUE(video_options.dscp.IsSet());
3979 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3980}
3981
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003982TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3983 constraints_.reset(new FakeConstraints());
3984 constraints_->AddOptional(
3985 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3986 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003987 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003988 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003989 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003990
3991 SetLocalDescriptionWithoutError(offer);
3992
3993 video_channel_ = media_engine_->GetVideoChannel(0);
3994
3995 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003996 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003997 EXPECT_TRUE(
3998 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3999}
4000
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004001TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4002 // Number of unsignalled receiving streams should be between 0 and
4003 // kMaxUnsignalledRecvStreams.
4004 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4005 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4006 kMaxUnsignalledRecvStreams);
4007 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4008}
4009
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004010TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4011 constraints_.reset(new FakeConstraints());
4012 constraints_->AddOptional(
4013 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4014 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004015 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004016 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004017 SessionDescriptionInterface* offer = CreateOffer();
4018
4019 SetLocalDescriptionWithoutError(offer);
4020
4021 voice_channel_ = media_engine_->GetVoiceChannel(0);
4022
4023 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004024 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004025 EXPECT_TRUE(
4026 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
4027}
4028
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004029// Tests that we can renegotiate new media content with ICE candidates in the
4030// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004031TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004033 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004034 SetFactoryDtlsSrtp();
4035
deadbeefab9b2d12015-10-14 11:33:11 -07004036 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004037 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004038 SetLocalDescriptionWithoutError(offer);
4039
4040 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4041 SetRemoteDescriptionWithoutError(answer);
4042
4043 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004044 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004045 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4046
4047 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004048 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004049 candidate1.set_component(1);
4050 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4051 candidate1);
4052 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4053 SetRemoteDescriptionWithoutError(offer);
4054
4055 answer = CreateAnswer(NULL);
4056 SetLocalDescriptionWithoutError(answer);
4057}
4058
4059// Tests that we can renegotiate new media content with ICE candidates separated
4060// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004061TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004062 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004063 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004064 SetFactoryDtlsSrtp();
4065
deadbeefab9b2d12015-10-14 11:33:11 -07004066 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004067 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004068 SetLocalDescriptionWithoutError(offer);
4069
4070 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4071 SetRemoteDescriptionWithoutError(answer);
4072
4073 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004074 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004075 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4076 SetRemoteDescriptionWithoutError(offer);
4077
4078 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004079 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004080 candidate1.set_component(1);
4081 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4082 candidate1);
4083 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4084
4085 answer = CreateAnswer(NULL);
4086 SetLocalDescriptionWithoutError(answer);
4087}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004088// Tests that RTX codec is removed from the answer when it isn't supported
4089// by local side.
4090TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004092 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004093 std::string offer_sdp(kSdpWithRtx);
4094
4095 SessionDescriptionInterface* offer =
4096 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4097 EXPECT_TRUE(offer->ToString(&offer_sdp));
4098
4099 // Offer SDP contains the RTX codec.
4100 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4101 SetRemoteDescriptionWithoutError(offer);
4102
4103 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4104 std::string answer_sdp;
4105 answer->ToString(&answer_sdp);
4106 // Answer SDP removes the unsupported RTX codec.
4107 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4108 SetLocalDescriptionWithoutError(answer);
4109}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004110
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004111// This verifies that the voice channel after bundle has both options from video
4112// and voice channels.
4113TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4114 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004115 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004116
4117 PeerConnectionInterface::RTCOfferAnswerOptions options;
4118 options.use_rtp_mux = true;
4119
4120 SessionDescriptionInterface* offer = CreateOffer(options);
4121 SetLocalDescriptionWithoutError(offer);
4122
4123 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4124 rtc::Socket::Option::OPT_SNDBUF, 4000);
4125
4126 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4127 rtc::Socket::Option::OPT_RCVBUF, 8000);
4128
4129 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004130 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004131 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4132 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004133 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004134 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4135
deadbeefcbecd352015-09-23 11:50:27 -07004136 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004137 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4138 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004139 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004140 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4141
deadbeefcbecd352015-09-23 11:50:27 -07004142 EXPECT_NE(session_->voice_rtp_transport_channel(),
4143 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004144
deadbeefab9b2d12015-10-14 11:33:11 -07004145 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004146 SessionDescriptionInterface* answer =
4147 CreateRemoteAnswer(session_->local_description());
4148 SetRemoteDescriptionWithoutError(answer);
4149
deadbeefcbecd352015-09-23 11:50:27 -07004150 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004151 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4152 EXPECT_EQ(4000, option_val);
4153
deadbeefcbecd352015-09-23 11:50:27 -07004154 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004155 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4156 EXPECT_EQ(8000, option_val);
4157}
4158
tommi0f620f42015-07-09 03:25:02 -07004159// Test creating a session, request multiple offers, destroy the session
4160// and make sure we got success/failure callbacks for all of the requests.
4161// Background: crbug.com/507307
4162TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4163 Init();
4164
4165 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4166 PeerConnectionInterface::RTCOfferAnswerOptions options;
4167 options.offer_to_receive_audio =
4168 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004169 cricket::MediaSessionOptions session_options;
4170 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004171
4172 for (auto& o : observers) {
4173 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004174 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004175 }
4176
4177 session_.reset();
4178
tommi0f620f42015-07-09 03:25:02 -07004179 for (auto& o : observers) {
4180 // We expect to have received a notification now even if the session was
4181 // terminated. The offer creation may or may not have succeeded, but we
4182 // must have received a notification which, so the only invalid state
4183 // is kInit.
4184 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4185 }
4186}
4187
stefanc1aeaf02015-10-15 07:26:07 -07004188TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4189 TestPacketOptions();
4190}
4191
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004192// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4193// currently fails because upon disconnection and reconnection OnIceComplete is
4194// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004195
deadbeefcbecd352015-09-23 11:50:27 -07004196INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4197 WebRtcSessionTest,
4198 testing::Values(ALREADY_GENERATED,
4199 DTLS_IDENTITY_STORE));