blob: 3eb46f1d3c187f5b548b862c4478fd8f8a7969b5 [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) {
deadbeefab9b2d12015-10-14 11:33:11 -0700574 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
575
deadbeefc80741f2015-10-22 13:14:45 -0700576 AddStreamsToOptions(session_options);
577 if (rtc_options.offer_to_receive_audio ==
578 RTCOfferAnswerOptions::kUndefined) {
579 session_options->recv_audio =
580 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
581 }
582 if (rtc_options.offer_to_receive_video ==
583 RTCOfferAnswerOptions::kUndefined) {
584 session_options->recv_video =
585 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
586 }
587 session_options->bundle_enabled =
588 session_options->bundle_enabled &&
589 (session_options->has_audio() || session_options->has_video() ||
590 session_options->has_data());
591
deadbeefab9b2d12015-10-14 11:33:11 -0700592 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
593 session_options->data_channel_type = cricket::DCT_SCTP;
594 }
595 }
596
597 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
598 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700599 session_options->recv_audio = false;
600 session_options->recv_video = false;
601 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
602
deadbeefc80741f2015-10-22 13:14:45 -0700603 AddStreamsToOptions(session_options);
604 session_options->bundle_enabled =
605 session_options->bundle_enabled &&
606 (session_options->has_audio() || session_options->has_video() ||
607 session_options->has_data());
608
deadbeefab9b2d12015-10-14 11:33:11 -0700609 if (session_->data_channel_type() == cricket::DCT_SCTP) {
610 session_options->data_channel_type = cricket::DCT_SCTP;
611 }
612 }
613
614 // Creates a local offer and applies it. Starts ICE.
615 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 // to decide which streams to create.
617 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000618 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 SetLocalDescriptionWithoutError(offer);
620 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
621 observer_.ice_gathering_state_,
622 kIceCandidatesTimeout);
623 }
624
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000625 SessionDescriptionInterface* CreateOffer() {
626 PeerConnectionInterface::RTCOfferAnswerOptions options;
627 options.offer_to_receive_audio =
628 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
629
630 return CreateOffer(options);
631 }
632
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000634 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000635 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000636 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700637 cricket::MediaSessionOptions session_options;
638 GetOptionsForOffer(options, &session_options);
639 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000640 EXPECT_TRUE_WAIT(
641 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000642 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000643 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000644 }
645
646 SessionDescriptionInterface* CreateAnswer(
647 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000648 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000649 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700650 cricket::MediaSessionOptions session_options;
651 GetOptionsForAnswer(constraints, &session_options);
652 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000653 EXPECT_TRUE_WAIT(
654 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000655 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000656 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000657 }
658
wu@webrtc.org364f2042013-11-20 21:49:41 +0000659 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 return (session_->voice_channel() != NULL &&
661 session_->video_channel() != NULL);
662 }
663
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
665 ASSERT_TRUE(session_.get() != NULL);
666 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
667 ASSERT_TRUE(content != NULL);
668 const cricket::AudioContentDescription* audio_content =
669 static_cast<const cricket::AudioContentDescription*>(
670 content->description);
671 ASSERT_TRUE(audio_content != NULL);
672 ASSERT_EQ(1U, audio_content->cryptos().size());
673 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
674 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
675 audio_content->cryptos()[0].cipher_suite);
676 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
677 audio_content->protocol());
678
679 content = cricket::GetFirstVideoContent(sdp);
680 ASSERT_TRUE(content != NULL);
681 const cricket::VideoContentDescription* video_content =
682 static_cast<const cricket::VideoContentDescription*>(
683 content->description);
684 ASSERT_TRUE(video_content != NULL);
685 ASSERT_EQ(1U, video_content->cryptos().size());
686 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
687 video_content->cryptos()[0].cipher_suite);
688 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
689 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
690 video_content->protocol());
691 }
692
693 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
694 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
695 ASSERT_TRUE(content != NULL);
696 const cricket::AudioContentDescription* audio_content =
697 static_cast<const cricket::AudioContentDescription*>(
698 content->description);
699 ASSERT_TRUE(audio_content != NULL);
700 ASSERT_EQ(0U, audio_content->cryptos().size());
701
702 content = cricket::GetFirstVideoContent(sdp);
703 ASSERT_TRUE(content != NULL);
704 const cricket::VideoContentDescription* video_content =
705 static_cast<const cricket::VideoContentDescription*>(
706 content->description);
707 ASSERT_TRUE(video_content != NULL);
708 ASSERT_EQ(0U, video_content->cryptos().size());
709
710 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700711 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700713 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 video_content->protocol());
715 } else {
716 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
717 audio_content->protocol());
718 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
719 video_content->protocol());
720 }
721 }
722
723 // Set the internal fake description factories to do DTLS-SRTP.
724 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000725 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000727 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200728 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200729 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700730 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
731 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
733 }
734
735 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
736 bool expected) {
737 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
738 ASSERT_TRUE(audio != NULL);
739 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 const TransportInfo* video = sdp->GetTransportInfoByName("video");
741 ASSERT_TRUE(video != NULL);
742 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 }
744
745 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000746 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000748 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000749 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000751 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000753 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
754 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000755 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 // Answer should be NULL as no crypto params in offer.
757 ASSERT_TRUE(answer == NULL);
758 }
759
760 void VerifyAnswerFromCryptoOffer() {
761 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000762 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 options.bundle_enabled = true;
764 scoped_ptr<JsepSessionDescription> offer(
765 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
766 ASSERT_TRUE(offer.get() != NULL);
767 VerifyCryptoParams(offer->description());
768 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000769 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 ASSERT_TRUE(answer.get() != NULL);
771 VerifyCryptoParams(answer->description());
772 }
773
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000774 void SetAndVerifyNumUnsignalledRecvStreams(
775 int value_set, int value_expected) {
776 constraints_.reset(new FakeConstraints());
777 constraints_->AddOptional(
778 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
779 value_set);
780 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000781 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700782 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000783 SessionDescriptionInterface* offer = CreateOffer();
784
785 SetLocalDescriptionWithoutError(offer);
786
787 video_channel_ = media_engine_->GetVideoChannel(0);
788
789 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700790 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000791 EXPECT_EQ(value_expected,
792 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
793 }
794
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
796 const cricket::SessionDescription* desc2,
797 bool expect_equal) {
798 if (desc1->contents().size() != desc2->contents().size()) {
799 EXPECT_FALSE(expect_equal);
800 return;
801 }
802
803 const cricket::ContentInfos& contents = desc1->contents();
804 cricket::ContentInfos::const_iterator it = contents.begin();
805
806 for (; it != contents.end(); ++it) {
807 const cricket::TransportDescription* transport_desc1 =
808 desc1->GetTransportDescriptionByName(it->name);
809 const cricket::TransportDescription* transport_desc2 =
810 desc2->GetTransportDescriptionByName(it->name);
811 if (!transport_desc1 || !transport_desc2) {
812 EXPECT_FALSE(expect_equal);
813 return;
814 }
815 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
816 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
817 EXPECT_FALSE(expect_equal);
818 return;
819 }
820 }
821 EXPECT_TRUE(expect_equal);
822 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000823
824 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
825 std::string *sdp) {
826 const cricket::SessionDescription* desc = current_desc->description();
827 EXPECT_TRUE(current_desc->ToString(sdp));
828
829 const cricket::ContentInfos& contents = desc->contents();
830 cricket::ContentInfos::const_iterator it = contents.begin();
831 // Replace ufrag and pwd lines with empty strings.
832 for (; it != contents.end(); ++it) {
833 const cricket::TransportDescription* transport_desc =
834 desc->GetTransportDescriptionByName(it->name);
835 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
836 + "\r\n";
837 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
838 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000839 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 "", 0,
841 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000842 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000843 "", 0,
844 sdp);
845 }
846 }
847
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000848 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
849 const std::string& modified_ice_ufrag,
850 const std::string& modified_ice_pwd,
851 std::string* sdp) {
852 const cricket::SessionDescription* desc = current_desc->description();
853 EXPECT_TRUE(current_desc->ToString(sdp));
854
855 const cricket::ContentInfos& contents = desc->contents();
856 cricket::ContentInfos::const_iterator it = contents.begin();
857 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
858 // |modified_ice_pwd| strings.
859 for (; it != contents.end(); ++it) {
860 const cricket::TransportDescription* transport_desc =
861 desc->GetTransportDescriptionByName(it->name);
862 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
863 + "\r\n";
864 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
865 + "\r\n";
866 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
867 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000869 mod_ufrag.c_str(), mod_ufrag.length(),
870 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000871 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000872 mod_pwd.c_str(), mod_pwd.length(),
873 sdp);
874 }
875 }
876
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 // Creates a remote offer and and applies it as a remote description,
878 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700879 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 // to decide which local and remote streams to create.
881 void CreateAndSetRemoteOfferAndLocalAnswer() {
882 SessionDescriptionInterface* offer = CreateRemoteOffer();
883 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000884 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 SetLocalDescriptionWithoutError(answer);
886 }
887 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
888 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700889 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700892 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 SetLocalDescriptionWithoutError(desc);
894 EXPECT_EQ(expected_state, session_->state());
895 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000896 void SetLocalDescriptionExpectError(const std::string& action,
897 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 SessionDescriptionInterface* desc) {
899 std::string error;
900 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000901 std::string sdp_type = "local ";
902 sdp_type.append(action);
903 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_NE(std::string::npos, error.find(expected_error));
905 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
907 SessionDescriptionInterface* desc) {
908 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
909 expected_error, desc);
910 }
911 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
912 SessionDescriptionInterface* desc) {
913 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
914 expected_error, desc);
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
917 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
918 }
919 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700920 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 SetRemoteDescriptionWithoutError(desc);
922 EXPECT_EQ(expected_state, session_->state());
923 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000924 void SetRemoteDescriptionExpectError(const std::string& action,
925 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 SessionDescriptionInterface* desc) {
927 std::string error;
928 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000929 std::string sdp_type = "remote ";
930 sdp_type.append(action);
931 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 EXPECT_NE(std::string::npos, error.find(expected_error));
933 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000934 void SetRemoteDescriptionOfferExpectError(
935 const std::string& expected_error, SessionDescriptionInterface* desc) {
936 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
937 expected_error, desc);
938 }
939 void SetRemoteDescriptionPranswerExpectError(
940 const std::string& expected_error, SessionDescriptionInterface* desc) {
941 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
942 expected_error, desc);
943 }
944 void SetRemoteDescriptionAnswerExpectError(
945 const std::string& expected_error, SessionDescriptionInterface* desc) {
946 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
947 expected_error, desc);
948 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949
950 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
951 SessionDescriptionInterface** nocrypto_answer) {
952 // Create a SDP without Crypto.
953 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000954 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 options.bundle_enabled = true;
956 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
957 ASSERT_TRUE(*offer != NULL);
958 VerifyCryptoParams((*offer)->description());
959
960 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
961 cricket::SEC_DISABLED);
962 EXPECT_TRUE(*nocrypto_answer != NULL);
963 }
964
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000965 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
966 SessionDescriptionInterface** nodtls_answer) {
967 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000968 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000969 options.bundle_enabled = true;
970
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000971 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000972 CreateRemoteOffer(options, cricket::SEC_ENABLED));
973
974 *nodtls_answer =
975 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
976 EXPECT_TRUE(*nodtls_answer != NULL);
977 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
978 VerifyCryptoParams((*nodtls_answer)->description());
979
980 SetFactoryDtlsSrtp();
981 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
982 ASSERT_TRUE(*offer != NULL);
983 VerifyFingerprintStatus((*offer)->description(), true);
984 VerifyCryptoParams((*offer)->description());
985 }
986
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 JsepSessionDescription* CreateRemoteOfferWithVersion(
988 cricket::MediaSessionOptions options,
989 cricket::SecurePolicy secure_policy,
990 const std::string& session_version,
991 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000992 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 const cricket::SessionDescription* cricket_desc = NULL;
994 if (current_desc) {
995 cricket_desc = current_desc->description();
996 session_id = current_desc->session_id();
997 }
998
999 desc_factory_->set_secure(secure_policy);
1000 JsepSessionDescription* offer(
1001 new JsepSessionDescription(JsepSessionDescription::kOffer));
1002 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1003 session_id, session_version)) {
1004 delete offer;
1005 offer = NULL;
1006 }
1007 return offer;
1008 }
1009 JsepSessionDescription* CreateRemoteOffer(
1010 cricket::MediaSessionOptions options) {
1011 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1012 kSessionVersion, NULL);
1013 }
1014 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001015 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1016 return CreateRemoteOfferWithVersion(
1017 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 }
1019 JsepSessionDescription* CreateRemoteOffer(
1020 cricket::MediaSessionOptions options,
1021 const SessionDescriptionInterface* current_desc) {
1022 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1023 kSessionVersion, current_desc);
1024 }
1025
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001026 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1027 const char* sctp_stream_name, int new_port,
1028 cricket::MediaSessionOptions options) {
1029 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001030 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1031 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001032 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1033 }
1034
1035 // Takes ownership of offer_basis (and deletes it).
1036 JsepSessionDescription* ChangeSDPSctpPort(
1037 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1038 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1039 // SessionDescription from the mutated string.
1040 const char* default_port_str = "5000";
1041 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001042 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001043 std::string offer_str;
1044 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001045 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001046 new_port_str, strlen(new_port_str),
1047 &offer_str);
1048 JsepSessionDescription* offer = new JsepSessionDescription(
1049 offer_basis->type());
1050 delete offer_basis;
1051 offer->Initialize(offer_str, NULL);
1052 return offer;
1053 }
1054
deadbeefab9b2d12015-10-14 11:33:11 -07001055 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 // before this function to decide which streams to create.
1057 JsepSessionDescription* CreateRemoteOffer() {
1058 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001059 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 return CreateRemoteOffer(options, session_->remote_description());
1061 }
1062
1063 JsepSessionDescription* CreateRemoteAnswer(
1064 const SessionDescriptionInterface* offer,
1065 cricket::MediaSessionOptions options,
1066 cricket::SecurePolicy policy) {
1067 desc_factory_->set_secure(policy);
1068 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001069 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 JsepSessionDescription* answer(
1071 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1072 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1073 options, NULL),
1074 session_id, kSessionVersion)) {
1075 delete answer;
1076 answer = NULL;
1077 }
1078 return answer;
1079 }
1080
1081 JsepSessionDescription* CreateRemoteAnswer(
1082 const SessionDescriptionInterface* offer,
1083 cricket::MediaSessionOptions options) {
1084 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1085 }
1086
deadbeefab9b2d12015-10-14 11:33:11 -07001087 // Creates an answer session description.
1088 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 // to decide which streams to create.
1090 JsepSessionDescription* CreateRemoteAnswer(
1091 const SessionDescriptionInterface* offer) {
1092 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001093 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1095 }
1096
1097 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001098 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001100 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001101
1102 PeerConnectionInterface::RTCOfferAnswerOptions options;
1103 options.use_rtp_mux = bundle;
1104
1105 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1107 // and answer.
1108 SetLocalDescriptionWithoutError(offer);
1109
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001110 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001111 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 std::string sdp;
1113 EXPECT_TRUE(answer->ToString(&sdp));
1114
1115 size_t expected_candidate_num = 2;
1116 if (!rtcp_mux) {
1117 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1118 // for rtp and rtcp.
1119 expected_candidate_num = 4;
1120 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 const std::string kRtcpMux = "a=rtcp-mux";
1122 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001123 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 kXRtcpMux.c_str(), kXRtcpMux.length(),
1125 &sdp);
1126 }
1127
1128 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1129 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130
1131 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001132 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1134 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001135 if (bundle) {
1136 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1137 } else {
1138 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 }
1140 }
1141 // Tests that we can only send DTMF when the dtmf codec is supported.
1142 void TestCanInsertDtmf(bool can) {
1143 if (can) {
1144 InitWithDtmfCodec();
1145 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001146 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 }
deadbeefab9b2d12015-10-14 11:33:11 -07001148 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 CreateAndSetRemoteOfferAndLocalAnswer();
1150 EXPECT_FALSE(session_->CanInsertDtmf(""));
1151 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1152 }
1153
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001154 // Helper class to configure loopback network and verify Best
1155 // Connection using right IP protocol for TestLoopbackCall
1156 // method. LoopbackNetworkManager applies firewall rules to block
1157 // all ping traffic once ICE completed, and remove them to observe
1158 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1159 // verifies the best connection is using the right IP protocol after
1160 // initial ICE convergences.
1161
1162 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001163 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001164 LoopbackNetworkConfiguration()
1165 : test_ipv6_network_(false),
1166 test_extra_ipv4_network_(false),
1167 best_connection_after_initial_ice_converged_(1, 0) {}
1168
1169 // Used to track the expected best connection count in each IP protocol.
1170 struct ExpectedBestConnection {
1171 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1172 : ipv4_count_(ipv4_count),
1173 ipv6_count_(ipv6_count) {}
1174
1175 int ipv4_count_;
1176 int ipv6_count_;
1177 };
1178
1179 bool test_ipv6_network_;
1180 bool test_extra_ipv4_network_;
1181 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1182
1183 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001184 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001185 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1186 }
1187
1188 private:
jbauchac8869e2015-07-03 01:36:14 -07001189 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001190 const ExpectedBestConnection& expected) const {
1191 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001192 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1193 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001194 expected.ipv4_count_);
1195 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001196 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1197 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001198 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001199 // This is used in the loopback call so there is only single host to host
1200 // candidate pair.
1201 EXPECT_EQ(metrics_observer->GetEnumCounter(
1202 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1203 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001204 0);
1205 EXPECT_EQ(metrics_observer->GetEnumCounter(
1206 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1207 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001208 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001209 }
1210 };
1211
1212 class LoopbackNetworkManager {
1213 public:
1214 LoopbackNetworkManager(WebRtcSessionTest* session,
1215 const LoopbackNetworkConfiguration& config)
1216 : config_(config) {
1217 session->AddInterface(
1218 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1219 if (config_.test_extra_ipv4_network_) {
1220 session->AddInterface(
1221 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1222 }
1223 if (config_.test_ipv6_network_) {
1224 session->AddInterface(
1225 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1226 }
1227 }
1228
1229 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1230 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1231 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1232 if (config_.test_extra_ipv4_network_) {
1233 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1234 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1235 }
1236 if (config_.test_ipv6_network_) {
1237 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1238 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1239 }
1240 }
1241
1242 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1243
1244 private:
1245 LoopbackNetworkConfiguration config_;
1246 };
1247
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 // The method sets up a call from the session to itself, in a loopback
1249 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001250 // disconnection, and then a permanent disconnection.
1251 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1253 // While running the call, this method also checks if the session goes through
1254 // the correct sequence of ICE states when a connection is established,
1255 // broken, and re-established.
1256 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001257 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1258 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001260
stefanc1aeaf02015-10-15 07:26:07 -07001261 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001262 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001263 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001264 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265
1266 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1267 observer_.ice_gathering_state_);
1268 SetLocalDescriptionWithoutError(offer);
1269 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1270 observer_.ice_connection_state_);
1271 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001272 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1274 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001275 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276
1277 std::string sdp;
1278 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001279 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1280 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 ASSERT_TRUE(desc != NULL);
1282 SetRemoteDescriptionWithoutError(desc);
1283
1284 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001285 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001286
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001287 // The ice connection state is "Connected" too briefly to catch in a test.
1288 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001289 observer_.ice_connection_state_, kIceCandidatesTimeout);
1290 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291
stefanc1aeaf02015-10-15 07:26:07 -07001292 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1293 LoopbackNetworkManager loopback_network_manager(this, config);
1294 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001295 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 // Adding firewall rule to block ping requests, which should cause
1297 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001298
1299 loopback_network_manager.ApplyFirewallRules(fss_.get());
1300
1301 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1303 observer_.ice_connection_state_,
1304 kIceCandidatesTimeout);
1305
jbauchac8869e2015-07-03 01:36:14 -07001306 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001307
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001309 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001311 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001312 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 observer_.ice_connection_state_,
1314 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001315
1316 // Now we block ping requests and wait until the ICE connection transitions
1317 // to the Failed state. This will take at least 30 seconds because it must
1318 // wait for the Port to timeout.
1319 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001320
1321 loopback_network_manager.ApplyFirewallRules(fss_.get());
1322 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001323 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001324 observer_.ice_connection_state_,
1325 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 }
1327
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001328 void TestLoopbackCall() {
1329 LoopbackNetworkConfiguration config;
1330 TestLoopbackCall(config);
1331 }
1332
stefanc1aeaf02015-10-15 07:26:07 -07001333 void TestPacketOptions() {
1334 media_controller_.reset(
1335 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1336 LoopbackNetworkConfiguration config;
1337 LoopbackNetworkManager loopback_network_manager(this, config);
1338
1339 SetupLoopbackCall();
1340
1341 uint8_t test_packet[15] = {0};
1342 rtc::PacketOptions options;
1343 options.packet_id = 10;
1344 media_engine_->GetVideoChannel(0)
1345 ->SendRtp(test_packet, sizeof(test_packet), options);
1346
1347 const int kPacketTimeout = 2000;
1348 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1349 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1350 }
1351
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1353 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001354 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1355 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1356
1357 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1359 codecs.push_back(kCNCodec1);
1360 codecs.push_back(kCNCodec2);
1361 media_engine_->SetAudioCodecs(codecs);
1362 desc_factory_->set_audio_codecs(codecs);
1363 }
1364
1365 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1366 const cricket::ContentDescription* description = content->description;
1367 ASSERT(description != NULL);
1368 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001369 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001370 ASSERT(audio_content_desc != NULL);
1371 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1372 if (audio_content_desc->codecs()[i].name == "CN")
1373 return false;
1374 }
1375 return true;
1376 }
1377
deadbeefab9b2d12015-10-14 11:33:11 -07001378 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001379 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001380 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1381 data_channel_ = DataChannel::Create(
1382 session_.get(), session_->data_channel_type(), "datachannel", dci);
1383 }
1384
1385 void SetLocalDescriptionWithDataChannel() {
1386 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001387 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 SetLocalDescriptionWithoutError(offer);
1389 }
1390
wu@webrtc.org91053e72013-08-10 07:18:04 +00001391 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001392 RTCCertificateGenerationMethod cert_gen_method,
1393 CreateSessionDescriptionRequest::Type type) {
1394 InitWithDtls(cert_gen_method);
1395 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1396 }
1397
1398 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1399 CreateSessionDescriptionRequest::Type type) {
1400 InitWithDtlsIdentityGenFail();
1401 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1402 }
1403
1404 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001406 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001407 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001408 if (type == CreateSessionDescriptionRequest::kAnswer) {
1409 cricket::MediaSessionOptions options;
1410 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001411 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001412 ASSERT_TRUE(offer.get() != NULL);
1413 SetRemoteDescriptionWithoutError(offer.release());
1414 }
1415
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001416 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001417 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001418 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001419 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001420 observers[kNumber];
1421 for (int i = 0; i < kNumber; ++i) {
1422 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1423 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001424 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001425 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001426 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001427 }
1428 }
1429
1430 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1431 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1432 WebRtcSessionCreateSDPObserverForTest::kFailed;
1433
1434 for (int i = 0; i < kNumber; ++i) {
1435 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1436 if (success) {
1437 EXPECT_TRUE(observers[i]->description() != NULL);
1438 } else {
1439 EXPECT_TRUE(observers[i]->description() == NULL);
1440 }
1441 }
1442 }
1443
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001444 void ConfigureAllocatorWithTurn() {
deadbeef18a944b2015-10-26 19:21:40 -07001445 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001446 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef18a944b2015-10-26 19:21:40 -07001447 relay_server.credentials = credentials;
1448 relay_server.ports.push_back(cricket::ProtocolAddress(
1449 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1450 allocator_->AddRelay(relay_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001451 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001452 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001453 }
1454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 cricket::FakeMediaEngine* media_engine_;
1456 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001457 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001458 cricket::FakeCall fake_call_;
1459 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001460 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001461 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1462 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1463 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1464 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1465 rtc::SocketServerScope ss_scope_;
1466 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001467 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001468 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001469 rtc::FakeNetworkManager network_manager_;
1470 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001471 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001473 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 MockIceObserver observer_;
1475 cricket::FakeVideoMediaChannel* video_channel_;
1476 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001477 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001478 // The following flags affect options created for CreateOffer/CreateAnswer.
1479 bool send_stream_1_ = false;
1480 bool send_stream_2_ = false;
1481 bool send_audio_ = false;
1482 bool send_video_ = false;
1483 rtc::scoped_refptr<DataChannel> data_channel_;
1484 // Last values received from data channel creation signal.
1485 std::string last_data_channel_label_;
1486 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487};
1488
Henrik Boström87713d02015-08-25 09:53:21 +02001489TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1490 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001491 // SDES is disabled when DTLS is on.
1492 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493}
1494
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001495TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001496 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001497 // SDES is required if DTLS is off.
1498 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001499}
1500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1502 TestSessionCandidatesWithBundleRtcpMux(false, false);
1503}
1504
1505// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1506// with rtcp-mux and/or bundle.
1507TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1508 TestSessionCandidatesWithBundleRtcpMux(false, true);
1509}
1510
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1512 TestSessionCandidatesWithBundleRtcpMux(true, true);
1513}
1514
1515TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001516 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1517 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001518 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001519 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 InitiateCall();
1521 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1522 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1523 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1524}
1525
1526TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001527 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1528 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001529 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001530 rtc::FP_UDP,
1531 rtc::FD_ANY,
1532 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001534 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001536 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1538 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1539 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1540}
1541
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001542// Test session delivers no candidates gathered when constraint set to "none".
1543TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1544 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001545 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001546 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001547 InitiateCall();
1548 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1549 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1550 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1551}
1552
1553// Test session delivers only relay candidates gathered when constaint set to
1554// "relay".
1555TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1556 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1557 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001558 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001559 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001560 InitiateCall();
1561 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1562 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1563 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1564 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1565 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1566 observer_.mline_0_candidates_[i].type());
1567 }
1568 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1569 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1570 observer_.mline_1_candidates_[i].type());
1571 }
1572}
1573
1574// Test session delivers all candidates gathered when constaint set to "all".
1575TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1576 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001577 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001578 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001579 InitiateCall();
1580 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1581 // Host + STUN. By default allocator is disabled to gather relay candidates.
1582 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1583 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1584}
1585
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001586TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001587 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001588 SessionDescriptionInterface* offer = NULL;
1589 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1590 std::string unknown_action;
1591 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1592 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1593}
1594
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595// Test creating offers and receive answers and make sure the
1596// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001597TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001599 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001600 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 const std::string session_id_orig = offer->session_id();
1602 const std::string session_version_orig = offer->session_version();
1603 SetLocalDescriptionWithoutError(offer);
1604
deadbeefab9b2d12015-10-14 11:33:11 -07001605 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 SessionDescriptionInterface* answer =
1607 CreateRemoteAnswer(session_->local_description());
1608 SetRemoteDescriptionWithoutError(answer);
1609
1610 video_channel_ = media_engine_->GetVideoChannel(0);
1611 voice_channel_ = media_engine_->GetVoiceChannel(0);
1612
1613 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1614 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1615
1616 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1617 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1618
1619 ASSERT_EQ(1u, video_channel_->send_streams().size());
1620 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1621 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1622 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1623
1624 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001625 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001626 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
1628 // Verify the session id is the same and the session version is
1629 // increased.
1630 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001631 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1632 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
1634 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001635 EXPECT_EQ(0u, video_channel_->send_streams().size());
1636 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637
deadbeefab9b2d12015-10-14 11:33:11 -07001638 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 answer = CreateRemoteAnswer(session_->local_description());
1640 SetRemoteDescriptionWithoutError(answer);
1641
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 // Make sure the receive streams have not changed.
1643 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1644 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1645 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1646 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1647}
1648
1649// Test receiving offers and creating answers and make sure the
1650// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001652 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001653 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001654 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001655 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 SetRemoteDescriptionWithoutError(offer);
1657
deadbeefab9b2d12015-10-14 11:33:11 -07001658 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001659 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001660 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 SetLocalDescriptionWithoutError(answer);
1662
1663 const std::string session_id_orig = answer->session_id();
1664 const std::string session_version_orig = answer->session_version();
1665
1666 video_channel_ = media_engine_->GetVideoChannel(0);
1667 voice_channel_ = media_engine_->GetVoiceChannel(0);
1668
1669 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1670 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1671
1672 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1673 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1674
1675 ASSERT_EQ(1u, video_channel_->send_streams().size());
1676 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1677 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1678 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1679
deadbeefab9b2d12015-10-14 11:33:11 -07001680 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001681 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 SetRemoteDescriptionWithoutError(offer);
1683
1684 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001685 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001686 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 // Verify the session id is the same and the session version is
1689 // increased.
1690 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001691 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1692 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 SetLocalDescriptionWithoutError(answer);
1694
1695 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1696 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1697 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1698 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1699 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1700 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1701
1702 // Make sure we have no send streams.
1703 EXPECT_EQ(0u, video_channel_->send_streams().size());
1704 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1705}
1706
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001707TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001708 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 media_engine_->set_fail_create_channel(true);
1710
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001711 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001712 ASSERT_TRUE(offer != NULL);
1713 // SetRemoteDescription and SetLocalDescription will take the ownership of
1714 // the offer.
1715 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001716 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001717 ASSERT_TRUE(offer != NULL);
1718 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1719}
1720
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001721//
1722// Tests for creating/setting SDP under different SDES/DTLS polices:
1723//
1724// --DTLS off and SDES on
1725// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1726// set local/remote offer/answer with crypto --> success
1727// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1728// failure
1729// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1730// failure
1731// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1732// failure
1733//
1734// --DTLS on and SDES off
1735// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1736// set local/remote offer/answer with DTLS fingerprint --> success
1737// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1738// fingerprint --> failure
1739// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1740// --> failure
1741// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1742// --> failure
1743//
1744// --Encryption disabled: DTLS off and SDES off
1745// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1746// answer without SDES or DTLS --> success
1747// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1748// answer without SDES or DTLS --> success
1749//
1750
1751// Test that we return a failure when applying a remote/local offer that doesn't
1752// have cryptos enabled when DTLS is off.
1753TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001754 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001756 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 JsepSessionDescription* offer = CreateRemoteOffer(
1758 options, cricket::SEC_DISABLED);
1759 ASSERT_TRUE(offer != NULL);
1760 VerifyNoCryptoParams(offer->description(), false);
1761 // SetRemoteDescription and SetLocalDescription will take the ownership of
1762 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001763 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1765 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767}
1768
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001769// Test that we return a failure when applying a local answer that doesn't have
1770// cryptos enabled when DTLS is off.
1771TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001772 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 SessionDescriptionInterface* offer = NULL;
1774 SessionDescriptionInterface* answer = NULL;
1775 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1776 // SetRemoteDescription and SetLocalDescription will take the ownership of
1777 // the offer.
1778 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780}
1781
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001782// Test we will return fail when apply an remote answer that doesn't have
1783// crypto enabled when DTLS is off.
1784TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 SessionDescriptionInterface* offer = NULL;
1787 SessionDescriptionInterface* answer = NULL;
1788 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1789 // SetRemoteDescription and SetLocalDescription will take the ownership of
1790 // the offer.
1791 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793}
1794
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001795// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1796// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001797TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001798 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001799 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001800 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 SetFactoryDtlsSrtp();
1802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001803 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 JsepSessionDescription* offer =
1805 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 ASSERT_TRUE(offer != NULL);
1807 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001808 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809
1810 // SetRemoteDescription will take the ownership of the offer.
1811 SetRemoteDescriptionWithoutError(offer);
1812
1813 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001814 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 ASSERT_TRUE(answer != NULL);
1816 VerifyFingerprintStatus(answer->description(), true);
1817 // Check that we don't have an a=crypto line in the answer.
1818 VerifyNoCryptoParams(answer->description(), true);
1819
1820 // Now set the local description, which should work, even without a=crypto.
1821 SetLocalDescriptionWithoutError(answer);
1822}
1823
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1825// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001826TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001827 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001828 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001829 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 SetFactoryDtlsSrtp();
1831
1832 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001833 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001834 ASSERT_TRUE(offer != NULL);
1835 VerifyFingerprintStatus(offer->description(), true);
1836 // Check that we don't have an a=crypto line in the offer.
1837 VerifyNoCryptoParams(offer->description(), true);
1838
1839 // Now set the local description, which should work, even without a=crypto.
1840 SetLocalDescriptionWithoutError(offer);
1841
1842 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001843 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844 JsepSessionDescription* answer =
1845 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1846 ASSERT_TRUE(answer != NULL);
1847 VerifyFingerprintStatus(answer->description(), true);
1848 VerifyNoCryptoParams(answer->description(), true);
1849
1850 // SetRemoteDescription will take the ownership of the answer.
1851 SetRemoteDescriptionWithoutError(answer);
1852}
1853
1854// Test that if we support DTLS and the other side didn't offer a fingerprint,
1855// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001856TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001857 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001858 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001860 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001861 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 JsepSessionDescription* offer = CreateRemoteOffer(
1863 options, cricket::SEC_REQUIRED);
1864 ASSERT_TRUE(offer != NULL);
1865 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868 // SetRemoteDescription will take the ownership of the offer.
1869 SetRemoteDescriptionOfferExpectError(
1870 kSdpWithoutDtlsFingerprint, offer);
1871
1872 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1873 // SetLocalDescription will take the ownership of the offer.
1874 SetLocalDescriptionOfferExpectError(
1875 kSdpWithoutDtlsFingerprint, offer);
1876}
1877
1878// Test that we return a failure when applying a local answer that doesn't have
1879// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001880TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001881 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001882 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 SessionDescriptionInterface* offer = NULL;
1884 SessionDescriptionInterface* answer = NULL;
1885 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1886
1887 // SetRemoteDescription and SetLocalDescription will take the ownership of
1888 // the offer and answer.
1889 SetRemoteDescriptionWithoutError(offer);
1890 SetLocalDescriptionAnswerExpectError(
1891 kSdpWithoutDtlsFingerprint, answer);
1892}
1893
1894// Test that we return a failure when applying a remote answer that doesn't have
1895// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001896TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001897 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001898 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001899 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001901 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001902 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1903 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001905 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906
1907 // SetRemoteDescription and SetLocalDescription will take the ownership of
1908 // the offer and answer.
1909 SetLocalDescriptionWithoutError(offer);
1910 SetRemoteDescriptionAnswerExpectError(
1911 kSdpWithoutDtlsFingerprint, answer);
1912}
1913
1914// Test that we create a local offer without SDES or DTLS and accept a remote
1915// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001916TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001917 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001919 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920
1921 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001922 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 ASSERT_TRUE(offer != NULL);
1924 VerifyFingerprintStatus(offer->description(), false);
1925 // Check that we don't have an a=crypto line in the offer.
1926 VerifyNoCryptoParams(offer->description(), false);
1927
1928 // Now set the local description, which should work, even without a=crypto.
1929 SetLocalDescriptionWithoutError(offer);
1930
1931 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001932 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001933 JsepSessionDescription* answer =
1934 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1935 ASSERT_TRUE(answer != NULL);
1936 VerifyFingerprintStatus(answer->description(), false);
1937 VerifyNoCryptoParams(answer->description(), false);
1938
1939 // SetRemoteDescription will take the ownership of the answer.
1940 SetRemoteDescriptionWithoutError(answer);
1941}
1942
1943// Test that we create a local answer without SDES or DTLS and accept a remote
1944// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001945TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001946 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001947 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948
1949 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001950 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001951 JsepSessionDescription* offer =
1952 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1953 ASSERT_TRUE(offer != NULL);
1954 VerifyFingerprintStatus(offer->description(), false);
1955 VerifyNoCryptoParams(offer->description(), false);
1956
1957 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 SetRemoteDescriptionWithoutError(offer);
1959
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001960 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001961 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 ASSERT_TRUE(answer != NULL);
1963 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964 // Check that we don't have an a=crypto line in the answer.
1965 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001967 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 SetLocalDescriptionWithoutError(answer);
1969}
1970
1971TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001972 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001973 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001975 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 SetLocalDescriptionWithoutError(offer);
1977
1978 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001979 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 SetLocalDescriptionWithoutError(offer2);
1981}
1982
1983TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001984 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001985 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001987 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 SetRemoteDescriptionWithoutError(offer);
1989
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 SetRemoteDescriptionWithoutError(offer2);
1992}
1993
1994TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001997 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001999 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002000 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2001 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002}
2003
2004TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002005 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002006 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002007 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002009 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002010 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002011 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012}
2013
2014TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002015 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002016 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002018 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019
2020 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002021 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002023 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024
deadbeefab9b2d12015-10-14 11:33:11 -07002025 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002027 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2029
deadbeefd59daf82015-10-14 15:02:44 -07002030 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031
deadbeefab9b2d12015-10-14 11:33:11 -07002032 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002033 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002034 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035}
2036
2037TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002040 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
2043 JsepSessionDescription* pranswer =
2044 CreateRemoteAnswer(session_->local_description());
2045 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2046
2047 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002048 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 JsepSessionDescription* pranswer2 =
2052 CreateRemoteAnswer(session_->local_description());
2053 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2054
2055 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002056 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057
deadbeefab9b2d12015-10-14 11:33:11 -07002058 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 SessionDescriptionInterface* answer =
2060 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002061 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062}
2063
2064TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002067 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 SessionDescriptionInterface* answer =
2070 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002071 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2072 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073}
2074
2075TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2079
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 SessionDescriptionInterface* answer =
2081 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002082 SetRemoteDescriptionAnswerExpectError(
2083 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084}
2085
2086TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002087 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002088 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089
2090 cricket::Candidate candidate;
2091 candidate.set_component(1);
2092 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2093
deadbeefd59daf82015-10-14 15:02:44 -07002094 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2096
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002097 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002099
2100 // Fail since we have not set a remote description.
2101 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
2103 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2104 session_->local_description());
2105 SetRemoteDescriptionWithoutError(answer);
2106
deadbeefd59daf82015-10-14 15:02:44 -07002107 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2108 candidate.set_component(2);
2109 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2110 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 // Verifying the candidates are copied properly from internal vector.
2113 const SessionDescriptionInterface* remote_desc =
2114 session_->remote_description();
2115 ASSERT_TRUE(remote_desc != NULL);
2116 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2117 const IceCandidateCollection* candidates =
2118 remote_desc->candidates(kMediaContentIndex0);
2119 ASSERT_EQ(2u, candidates->count());
2120 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2121 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2122 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2123 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2124
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002125 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2126 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 candidate.set_component(2);
2128 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2129 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002130 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131
2132 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2133 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2134}
2135
2136// Test that a remote candidate is added to the remote session description and
2137// that it is retained if the remote session description is changed.
2138TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002139 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 cricket::Candidate candidate1;
2141 candidate1.set_component(1);
2142 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2143 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002144 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 CreateAndSetRemoteOfferAndLocalAnswer();
2146
2147 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2148 const SessionDescriptionInterface* remote_desc =
2149 session_->remote_description();
2150 ASSERT_TRUE(remote_desc != NULL);
2151 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2152 const IceCandidateCollection* candidates =
2153 remote_desc->candidates(kMediaContentIndex0);
2154 ASSERT_EQ(1u, candidates->count());
2155 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2156
2157 // Update the RemoteSessionDescription with a new session description and
2158 // a candidate and check that the new remote session description contains both
2159 // candidates.
2160 SessionDescriptionInterface* offer = CreateRemoteOffer();
2161 cricket::Candidate candidate2;
2162 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2163 candidate2);
2164 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2165 SetRemoteDescriptionWithoutError(offer);
2166
2167 remote_desc = session_->remote_description();
2168 ASSERT_TRUE(remote_desc != NULL);
2169 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2170 candidates = remote_desc->candidates(kMediaContentIndex0);
2171 ASSERT_EQ(2u, candidates->count());
2172 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2173 // Username and password have be updated with the TransportInfo of the
2174 // SessionDescription, won't be equal to the original one.
2175 candidate2.set_username(candidates->at(0)->candidate().username());
2176 candidate2.set_password(candidates->at(0)->candidate().password());
2177 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2178 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2179 // No need to verify the username and password.
2180 candidate1.set_username(candidates->at(1)->candidate().username());
2181 candidate1.set_password(candidates->at(1)->candidate().password());
2182 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2183
2184 // Test that the candidate is ignored if we can add the same candidate again.
2185 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2186}
2187
2188// Test that local candidates are added to the local session description and
2189// that they are retained if the local session description is changed.
2190TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002191 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002192 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002193 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 CreateAndSetRemoteOfferAndLocalAnswer();
2195
2196 const SessionDescriptionInterface* local_desc = session_->local_description();
2197 const IceCandidateCollection* candidates =
2198 local_desc->candidates(kMediaContentIndex0);
2199 ASSERT_TRUE(candidates != NULL);
2200 EXPECT_EQ(0u, candidates->count());
2201
2202 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2203
2204 local_desc = session_->local_description();
2205 candidates = local_desc->candidates(kMediaContentIndex0);
2206 ASSERT_TRUE(candidates != NULL);
2207 EXPECT_LT(0u, candidates->count());
2208 candidates = local_desc->candidates(1);
2209 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002210 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
2212 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002213 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 CreateAndSetRemoteOfferAndLocalAnswer();
2215
2216 local_desc = session_->local_description();
2217 candidates = local_desc->candidates(kMediaContentIndex0);
2218 ASSERT_TRUE(candidates != NULL);
2219 EXPECT_LT(0u, candidates->count());
2220 candidates = local_desc->candidates(1);
2221 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002222 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223}
2224
2225// Test that we can set a remote session description with remote candidates.
2226TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002227 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228
2229 cricket::Candidate candidate1;
2230 candidate1.set_component(1);
2231 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2232 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002233 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002234 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
2236 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2237 SetRemoteDescriptionWithoutError(offer);
2238
2239 const SessionDescriptionInterface* remote_desc =
2240 session_->remote_description();
2241 ASSERT_TRUE(remote_desc != NULL);
2242 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2243 const IceCandidateCollection* candidates =
2244 remote_desc->candidates(kMediaContentIndex0);
2245 ASSERT_EQ(1u, candidates->count());
2246 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2247
wu@webrtc.org91053e72013-08-10 07:18:04 +00002248 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 SetLocalDescriptionWithoutError(answer);
2250}
2251
2252// Test that offers and answers contains ice candidates when Ice candidates have
2253// been gathered.
2254TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002255 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002256 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002257 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 // Ice is started but candidates are not provided until SetLocalDescription
2259 // is called.
2260 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2261 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2262 CreateAndSetRemoteOfferAndLocalAnswer();
2263 // Wait until at least one local candidate has been collected.
2264 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2265 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002267 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2268
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2270 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271
2272 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2273 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002274 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2276 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 SetLocalDescriptionWithoutError(answer);
2278}
2279
2280// Verifies TransportProxy and media channels are created with content names
2281// present in the SessionDescription.
2282TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002283 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002284 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002285 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286
2287 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002288 // "video". Goal is to modify these content names and verify transport
2289 // channels
2290 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 // present in SDP.
2292 std::string sdp;
2293 EXPECT_TRUE(offer->ToString(&sdp));
2294 const std::string kAudioMid = "a=mid:audio";
2295 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2296 const std::string kVideoMid = "a=mid:video";
2297 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2298
2299 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002300 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 kAudioMidReplaceStr.c_str(),
2302 kAudioMidReplaceStr.length(),
2303 &sdp);
2304 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002305 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 kVideoMidReplaceStr.c_str(),
2307 kVideoMidReplaceStr.length(),
2308 &sdp);
2309
2310 SessionDescriptionInterface* modified_offer =
2311 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2312
2313 SetRemoteDescriptionWithoutError(modified_offer);
2314
2315 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002316 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 SetLocalDescriptionWithoutError(answer);
2318
deadbeefcbecd352015-09-23 11:50:27 -07002319 cricket::TransportChannel* voice_transport_channel =
2320 session_->voice_rtp_transport_channel();
2321 EXPECT_TRUE(voice_transport_channel != NULL);
2322 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2323 cricket::TransportChannel* video_transport_channel =
2324 session_->video_rtp_transport_channel();
2325 EXPECT_TRUE(video_transport_channel != NULL);
2326 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2328 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2329}
2330
2331// Test that an offer contains the correct media content descriptions based on
2332// the send streams when no constraints have been set.
2333TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002334 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002335 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2336
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 ASSERT_TRUE(offer != NULL);
2338 const cricket::ContentInfo* content =
2339 cricket::GetFirstAudioContent(offer->description());
2340 EXPECT_TRUE(content != NULL);
2341 content = cricket::GetFirstVideoContent(offer->description());
2342 EXPECT_TRUE(content == NULL);
2343}
2344
2345// Test that an offer contains the correct media content descriptions based on
2346// the send streams when no constraints have been set.
2347TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002348 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002350 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002351 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 const cricket::ContentInfo* content =
2354 cricket::GetFirstAudioContent(offer->description());
2355 EXPECT_TRUE(content != NULL);
2356 content = cricket::GetFirstVideoContent(offer->description());
2357 EXPECT_TRUE(content == NULL);
2358
2359 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002360 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002361 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 content = cricket::GetFirstAudioContent(offer->description());
2363 EXPECT_TRUE(content != NULL);
2364 content = cricket::GetFirstVideoContent(offer->description());
2365 EXPECT_TRUE(content != NULL);
2366}
2367
2368// Test that an offer contains no media content descriptions if
2369// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2370TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002371 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002372 PeerConnectionInterface::RTCOfferAnswerOptions options;
2373 options.offer_to_receive_audio = 0;
2374 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002376 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002377 CreateOffer(options));
2378
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 ASSERT_TRUE(offer != NULL);
2380 const cricket::ContentInfo* content =
2381 cricket::GetFirstAudioContent(offer->description());
2382 EXPECT_TRUE(content == NULL);
2383 content = cricket::GetFirstVideoContent(offer->description());
2384 EXPECT_TRUE(content == NULL);
2385}
2386
2387// Test that an offer contains only audio media content descriptions if
2388// kOfferToReceiveAudio constraints are set to true.
2389TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002390 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391 PeerConnectionInterface::RTCOfferAnswerOptions options;
2392 options.offer_to_receive_audio =
2393 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2394
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002395 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002396 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397
2398 const cricket::ContentInfo* content =
2399 cricket::GetFirstAudioContent(offer->description());
2400 EXPECT_TRUE(content != NULL);
2401 content = cricket::GetFirstVideoContent(offer->description());
2402 EXPECT_TRUE(content == NULL);
2403}
2404
2405// Test that an offer contains audio and video media content descriptions if
2406// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2407TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002408 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002410 PeerConnectionInterface::RTCOfferAnswerOptions options;
2411 options.offer_to_receive_audio =
2412 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2413 options.offer_to_receive_video =
2414 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2415
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002416 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 CreateOffer(options));
2418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 const cricket::ContentInfo* content =
2420 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002421 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002422
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content != NULL);
2425
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002426 // Sets constraints to false and verifies that audio/video contents are
2427 // removed.
2428 options.offer_to_receive_audio = 0;
2429 options.offer_to_receive_video = 0;
2430 offer.reset(CreateOffer(options));
2431
2432 content = cricket::GetFirstAudioContent(offer->description());
2433 EXPECT_TRUE(content == NULL);
2434 content = cricket::GetFirstVideoContent(offer->description());
2435 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436}
2437
2438// Test that an answer can not be created if the last remote description is not
2439// an offer.
2440TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002441 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002442 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 SetLocalDescriptionWithoutError(offer);
2444 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2445 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002446 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447}
2448
2449// Test that an answer contains the correct media content descriptions when no
2450// constraints have been set.
2451TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002452 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002454 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002456 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002457 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458 const cricket::ContentInfo* content =
2459 cricket::GetFirstAudioContent(answer->description());
2460 ASSERT_TRUE(content != NULL);
2461 EXPECT_FALSE(content->rejected);
2462
2463 content = cricket::GetFirstVideoContent(answer->description());
2464 ASSERT_TRUE(content != NULL);
2465 EXPECT_FALSE(content->rejected);
2466}
2467
2468// Test that an answer contains the correct media content descriptions when no
2469// constraints have been set and the offer only contain audio.
2470TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002471 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 // Create a remote offer with audio only.
2473 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002474
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002475 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 CreateRemoteOffer(options));
2477 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2478 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2479
2480 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002481 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002482 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 const cricket::ContentInfo* content =
2484 cricket::GetFirstAudioContent(answer->description());
2485 ASSERT_TRUE(content != NULL);
2486 EXPECT_FALSE(content->rejected);
2487
2488 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2489}
2490
2491// Test that an answer contains the correct media content descriptions when no
2492// constraints have been set.
2493TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002494 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002496 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 SetRemoteDescriptionWithoutError(offer.release());
2498 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002499 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002500 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002501 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 const cricket::ContentInfo* content =
2503 cricket::GetFirstAudioContent(answer->description());
2504 ASSERT_TRUE(content != NULL);
2505 EXPECT_FALSE(content->rejected);
2506
2507 content = cricket::GetFirstVideoContent(answer->description());
2508 ASSERT_TRUE(content != NULL);
2509 EXPECT_FALSE(content->rejected);
2510}
2511
2512// Test that an answer contains the correct media content descriptions when
2513// constraints have been set but no stream is sent.
2514TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002515 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002517 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 SetRemoteDescriptionWithoutError(offer.release());
2519
2520 webrtc::FakeConstraints constraints_no_receive;
2521 constraints_no_receive.SetMandatoryReceiveAudio(false);
2522 constraints_no_receive.SetMandatoryReceiveVideo(false);
2523
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002524 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002525 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526 const cricket::ContentInfo* content =
2527 cricket::GetFirstAudioContent(answer->description());
2528 ASSERT_TRUE(content != NULL);
2529 EXPECT_TRUE(content->rejected);
2530
2531 content = cricket::GetFirstVideoContent(answer->description());
2532 ASSERT_TRUE(content != NULL);
2533 EXPECT_TRUE(content->rejected);
2534}
2535
2536// Test that an answer contains the correct media content descriptions when
2537// constraints have been set and streams are sent.
2538TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002539 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002541 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 SetRemoteDescriptionWithoutError(offer.release());
2543
2544 webrtc::FakeConstraints constraints_no_receive;
2545 constraints_no_receive.SetMandatoryReceiveAudio(false);
2546 constraints_no_receive.SetMandatoryReceiveVideo(false);
2547
2548 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002549 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002550 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002551 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552
2553 // TODO(perkj): Should the direction be set to SEND_ONLY?
2554 const cricket::ContentInfo* content =
2555 cricket::GetFirstAudioContent(answer->description());
2556 ASSERT_TRUE(content != NULL);
2557 EXPECT_FALSE(content->rejected);
2558
2559 // TODO(perkj): Should the direction be set to SEND_ONLY?
2560 content = cricket::GetFirstVideoContent(answer->description());
2561 ASSERT_TRUE(content != NULL);
2562 EXPECT_FALSE(content->rejected);
2563}
2564
2565TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2566 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002567 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002568 PeerConnectionInterface::RTCOfferAnswerOptions options;
2569 options.offer_to_receive_audio =
2570 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2571 options.voice_activity_detection = false;
2572
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002573 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002574 CreateOffer(options));
2575
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 const cricket::ContentInfo* content =
2577 cricket::GetFirstAudioContent(offer->description());
2578 EXPECT_TRUE(content != NULL);
2579 EXPECT_TRUE(VerifyNoCNCodecs(content));
2580}
2581
2582TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2583 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002586 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 SetRemoteDescriptionWithoutError(offer.release());
2588
2589 webrtc::FakeConstraints constraints;
2590 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002591 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002592 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 const cricket::ContentInfo* content =
2594 cricket::GetFirstAudioContent(answer->description());
2595 ASSERT_TRUE(content != NULL);
2596 EXPECT_TRUE(VerifyNoCNCodecs(content));
2597}
2598
2599// This test verifies the call setup when remote answer with audio only and
2600// later updates with video.
2601TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002602 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2604 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2605
deadbeefab9b2d12015-10-14 11:33:11 -07002606 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002607 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608
2609 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2611
2612 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2613 // and answer;
2614 SetLocalDescriptionWithoutError(offer);
2615 SetRemoteDescriptionWithoutError(answer);
2616
2617 video_channel_ = media_engine_->GetVideoChannel(0);
2618 voice_channel_ = media_engine_->GetVoiceChannel(0);
2619
2620 ASSERT_TRUE(video_channel_ == NULL);
2621
2622 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2623 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2624 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2625
2626 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002627 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 CreateAndSetRemoteOfferAndLocalAnswer();
2629
2630 video_channel_ = media_engine_->GetVideoChannel(0);
2631 voice_channel_ = media_engine_->GetVoiceChannel(0);
2632
2633 ASSERT_TRUE(video_channel_ != NULL);
2634 ASSERT_TRUE(voice_channel_ != NULL);
2635
2636 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2637 ASSERT_EQ(1u, video_channel_->send_streams().size());
2638 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2639 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2640 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2641 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2642 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2643 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2644
2645 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002646 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647 CreateAndSetRemoteOfferAndLocalAnswer();
2648
2649 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2650 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2651 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2652 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2653 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2654}
2655
2656// This test verifies the call setup when remote answer with video only and
2657// later updates with audio.
2658TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002659 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2661 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002662 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002663 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664
2665 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002666 options.recv_audio = false;
2667 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2669 offer, options, cricket::SEC_ENABLED);
2670
2671 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2672 // and answer.
2673 SetLocalDescriptionWithoutError(offer);
2674 SetRemoteDescriptionWithoutError(answer);
2675
2676 video_channel_ = media_engine_->GetVideoChannel(0);
2677 voice_channel_ = media_engine_->GetVoiceChannel(0);
2678
2679 ASSERT_TRUE(voice_channel_ == NULL);
2680 ASSERT_TRUE(video_channel_ != NULL);
2681
2682 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2683 ASSERT_EQ(1u, video_channel_->send_streams().size());
2684 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2685
2686 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002687 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 CreateAndSetRemoteOfferAndLocalAnswer();
2689
2690 voice_channel_ = media_engine_->GetVoiceChannel(0);
2691 ASSERT_TRUE(voice_channel_ != NULL);
2692
2693 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2694 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2695 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2696 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2697
2698 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002699 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 CreateAndSetRemoteOfferAndLocalAnswer();
2701
2702 video_channel_ = media_engine_->GetVideoChannel(0);
2703 voice_channel_ = media_engine_->GetVoiceChannel(0);
2704
2705 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2706 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2707 ASSERT_EQ(1u, video_channel_->send_streams().size());
2708 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2709}
2710
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002712 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002713 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002714 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 VerifyCryptoParams(offer->description());
2716 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002717 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 VerifyCryptoParams(answer->description());
2719}
2720
2721TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002722 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002723 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002724 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002725 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726 VerifyNoCryptoParams(offer->description(), false);
2727}
2728
2729TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002730 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731 VerifyAnswerFromNonCryptoOffer();
2732}
2733
2734TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002735 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736 VerifyAnswerFromCryptoOffer();
2737}
2738
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002739// This test verifies that setLocalDescription fails if
2740// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2741TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002742 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002743 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002744 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2745
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002746 std::string sdp;
2747 RemoveIceUfragPwdLines(offer.get(), &sdp);
2748 SessionDescriptionInterface* modified_offer =
2749 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002750 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002751}
2752
2753// This test verifies that setRemoteDescription fails if
2754// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2755TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002756 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002757 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002758 std::string sdp;
2759 RemoveIceUfragPwdLines(offer.get(), &sdp);
2760 SessionDescriptionInterface* modified_offer =
2761 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002762 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002763}
2764
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002765// This test verifies that setLocalDescription fails if local offer has
2766// too short ice ufrag and pwd strings.
2767TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002768 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002769 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002770 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2771
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002772 std::string sdp;
2773 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2774 // recommended values of 4 and 22 bytes respectively.
2775 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2776 SessionDescriptionInterface* modified_offer =
2777 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2778 std::string error;
2779 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2780
2781 // Test with string greater than 256.
2782 sdp.clear();
2783 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2784 &sdp);
2785 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2786 NULL);
2787 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2788}
2789
2790// This test verifies that setRemoteDescription fails if remote offer has
2791// too short ice ufrag and pwd strings.
2792TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002793 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002794 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002795 std::string sdp;
2796 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2797 // recommended values of 4 and 22 bytes respectively.
2798 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2799 SessionDescriptionInterface* modified_offer =
2800 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2801 std::string error;
2802 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2803
2804 sdp.clear();
2805 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2806 &sdp);
2807 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2808 NULL);
2809 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2810}
2811
honghaiz503726c2015-07-31 12:37:38 -07002812// Test that if the remote description indicates the peer requested ICE restart
2813// (via a new ufrag or pwd), the old ICE candidates are not copied,
2814// and vice versa.
2815TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2816 Init();
2817 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2818
2819 // Create the first offer.
2820 std::string sdp;
2821 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2822 "abcdefghijklmnopqrstuvwx", &sdp);
2823 SessionDescriptionInterface* offer1 =
2824 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2825 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2826 0, "", "", "relay", 0, "");
2827 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2828 candidate1);
2829 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2830 SetRemoteDescriptionWithoutError(offer1);
2831 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2832
2833 // The second offer has the same ufrag and pwd but different address.
2834 sdp.clear();
2835 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2836 "abcdefghijklmnopqrstuvwx", &sdp);
2837 SessionDescriptionInterface* offer2 =
2838 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2839 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2840 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2841 candidate1);
2842 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2843 SetRemoteDescriptionWithoutError(offer2);
2844 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2845
2846 // The third offer has a different ufrag and different address.
2847 sdp.clear();
2848 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2849 "abcdefghijklmnopqrstuvwx", &sdp);
2850 SessionDescriptionInterface* offer3 =
2851 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2852 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2853 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2854 candidate1);
2855 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2856 SetRemoteDescriptionWithoutError(offer3);
2857 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2858
2859 // The fourth offer has no candidate but a different ufrag/pwd.
2860 sdp.clear();
2861 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2862 "abcdefghijklmnopqrstuvyz", &sdp);
2863 SessionDescriptionInterface* offer4 =
2864 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2865 SetRemoteDescriptionWithoutError(offer4);
2866 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2867}
2868
Donald Curtisd4f769d2015-05-28 09:48:21 -07002869// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002870// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002871TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2872 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2873
2874 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002875 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002876
2877 PeerConnectionInterface::RTCOfferAnswerOptions options;
2878 options.use_rtp_mux = true;
2879
2880 SessionDescriptionInterface* offer = CreateRemoteOffer();
2881 SetRemoteDescriptionWithoutError(offer);
2882
2883 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2884 SetLocalDescriptionWithoutError(answer);
2885
deadbeefcbecd352015-09-23 11:50:27 -07002886 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2887 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002888
deadbeefcbecd352015-09-23 11:50:27 -07002889 cricket::BaseChannel* voice_channel = session_->voice_channel();
2890 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002891
2892 // Checks if one of the transport channels contains a connection using a given
2893 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002894 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002895 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002896 session_->GetChannelTransportStats(voice_channel, &stats);
2897 for (auto& kv : stats.transport_stats) {
2898 for (auto& chan_stat : kv.second.channel_stats) {
2899 for (auto& conn_info : chan_stat.connection_infos) {
2900 if (conn_info.remote_candidate.address().port() == port) {
2901 return true;
2902 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002903 }
2904 }
2905 }
2906 return false;
2907 };
2908
2909 EXPECT_FALSE(connection_with_remote_port(5000));
2910 EXPECT_FALSE(connection_with_remote_port(5001));
2911 EXPECT_FALSE(connection_with_remote_port(6000));
2912
2913 // The way the *_WAIT checks work is they only wait if the condition fails,
2914 // which does not help in the case where state is not changing. This is
2915 // problematic in this test since we want to verify that adding a video
2916 // candidate does _not_ change state. So we interleave candidates and assume
2917 // that messages are executed in the order they were posted.
2918
2919 // First audio candidate.
2920 cricket::Candidate candidate0;
2921 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2922 candidate0.set_component(1);
2923 candidate0.set_protocol("udp");
2924 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2925 candidate0);
2926 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2927
2928 // Video candidate.
2929 cricket::Candidate candidate1;
2930 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2931 candidate1.set_component(1);
2932 candidate1.set_protocol("udp");
2933 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2934 candidate1);
2935 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2936
2937 // Second audio candidate.
2938 cricket::Candidate candidate2;
2939 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2940 candidate2.set_component(1);
2941 candidate2.set_protocol("udp");
2942 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2943 candidate2);
2944 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2945
2946 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2947 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2948
2949 // No need here for a _WAIT check since we are checking that state hasn't
2950 // changed: if this is false we would be doing waits for nothing and if this
2951 // is true then there will be no messages processed anyways.
2952 EXPECT_FALSE(connection_with_remote_port(6000));
2953}
2954
deadbeefcbecd352015-09-23 11:50:27 -07002955// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002956TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2957 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002958 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002959
2960 PeerConnectionInterface::RTCOfferAnswerOptions options;
2961 options.use_rtp_mux = true;
2962
2963 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002965
deadbeefcbecd352015-09-23 11:50:27 -07002966 EXPECT_NE(session_->voice_rtp_transport_channel(),
2967 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002968
deadbeefab9b2d12015-10-14 11:33:11 -07002969 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002970 SessionDescriptionInterface* answer =
2971 CreateRemoteAnswer(session_->local_description());
2972 SetRemoteDescriptionWithoutError(answer);
2973
deadbeefcbecd352015-09-23 11:50:27 -07002974 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2975 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002976}
2977
deadbeefcbecd352015-09-23 11:50:27 -07002978// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002979TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2980 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002981 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002982
Donald Curtis0e209b02015-03-24 09:29:54 -07002983 PeerConnectionInterface::RTCOfferAnswerOptions options;
2984 options.use_rtp_mux = true;
2985
2986 SessionDescriptionInterface* offer = CreateOffer(options);
2987 SetLocalDescriptionWithoutError(offer);
2988
deadbeefcbecd352015-09-23 11:50:27 -07002989 EXPECT_NE(session_->voice_rtp_transport_channel(),
2990 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002991
deadbeefab9b2d12015-10-14 11:33:11 -07002992 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002993
2994 // Remove BUNDLE from the answer.
2995 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2996 CreateRemoteAnswer(session_->local_description()));
2997 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2998 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2999 JsepSessionDescription* modified_answer =
3000 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3001 modified_answer->Initialize(answer_copy, "1", "1");
3002 SetRemoteDescriptionWithoutError(modified_answer); //
3003
deadbeefcbecd352015-09-23 11:50:27 -07003004 EXPECT_NE(session_->voice_rtp_transport_channel(),
3005 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003006}
3007
3008// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3009TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3010 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003011 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003012
3013 PeerConnectionInterface::RTCOfferAnswerOptions options;
3014 options.use_rtp_mux = true;
3015
3016 SessionDescriptionInterface* offer = CreateOffer(options);
3017 SetLocalDescriptionWithoutError(offer);
3018
deadbeefcbecd352015-09-23 11:50:27 -07003019 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3020 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003021
deadbeefab9b2d12015-10-14 11:33:11 -07003022 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003023 SessionDescriptionInterface* answer =
3024 CreateRemoteAnswer(session_->local_description());
3025 SetRemoteDescriptionWithoutError(answer);
3026
deadbeefcbecd352015-09-23 11:50:27 -07003027 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3028 session_->video_rtp_transport_channel());
3029}
3030
3031// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3032// audio content in the answer.
3033TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3034 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003035 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003036
3037 PeerConnectionInterface::RTCOfferAnswerOptions options;
3038 options.use_rtp_mux = true;
3039
3040 SessionDescriptionInterface* offer = CreateOffer(options);
3041 SetLocalDescriptionWithoutError(offer);
3042
3043 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3044 session_->video_rtp_transport_channel());
3045
deadbeefab9b2d12015-10-14 11:33:11 -07003046 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003047 cricket::MediaSessionOptions recv_options;
3048 recv_options.recv_audio = false;
3049 recv_options.recv_video = true;
3050 SessionDescriptionInterface* answer =
3051 CreateRemoteAnswer(session_->local_description(), recv_options);
3052 SetRemoteDescriptionWithoutError(answer);
3053
deadbeefd59daf82015-10-14 15:02:44 -07003054 EXPECT_TRUE(nullptr == session_->voice_channel());
3055 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003056
deadbeefd59daf82015-10-14 15:02:44 -07003057 session_->Close();
3058 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3059 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3060 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3061 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003062}
3063
3064// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3065TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3066 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003067 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003068
Donald Curtis0e209b02015-03-24 09:29:54 -07003069 PeerConnectionInterface::RTCOfferAnswerOptions options;
3070 options.use_rtp_mux = true;
3071
3072 SessionDescriptionInterface* offer = CreateOffer(options);
3073 SetLocalDescriptionWithoutError(offer);
3074
deadbeefcbecd352015-09-23 11:50:27 -07003075 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3076 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003077
deadbeefab9b2d12015-10-14 11:33:11 -07003078 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003079
3080 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003081 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082 CreateRemoteAnswer(session_->local_description()));
3083 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3084 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3085 JsepSessionDescription* modified_answer =
3086 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3087 modified_answer->Initialize(answer_copy, "1", "1");
3088 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003089
deadbeefcbecd352015-09-23 11:50:27 -07003090 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3091 session_->video_rtp_transport_channel());
3092}
3093
3094// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3095TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3096 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003097 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003098
3099 SessionDescriptionInterface* offer = CreateRemoteOffer();
3100 SetRemoteDescriptionWithoutError(offer);
3101
3102 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3103 session_->video_rtp_transport_channel());
3104
deadbeefab9b2d12015-10-14 11:33:11 -07003105 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003106 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3107 SetLocalDescriptionWithoutError(answer);
3108
3109 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3110 session_->video_rtp_transport_channel());
3111}
3112
3113// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3114TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3115 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003116 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003117
3118 // Remove BUNDLE from the offer.
3119 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3120 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3121 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3122 JsepSessionDescription* modified_offer =
3123 new JsepSessionDescription(JsepSessionDescription::kOffer);
3124 modified_offer->Initialize(offer_copy, "1", "1");
3125
3126 // Expect an error when applying the remote description
3127 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3128 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003129}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130
Peter Thatcher4eddf182015-04-30 10:55:59 -07003131// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003132TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135
Donald Curtis0e209b02015-03-24 09:29:54 -07003136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003138
Donald Curtis0e209b02015-03-24 09:29:54 -07003139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_NE(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003146 SessionDescriptionInterface* answer =
3147 CreateRemoteAnswer(session_->local_description());
3148 SetRemoteDescriptionWithoutError(answer);
3149
3150 // This should lead to an audio-only call but isn't implemented
3151 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003152 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3153 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003154}
3155
deadbeefcbecd352015-09-23 11:50:27 -07003156// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003157TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3158 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003159 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003160 PeerConnectionInterface::RTCOfferAnswerOptions options;
3161 options.use_rtp_mux = true;
3162
3163 SessionDescriptionInterface* offer = CreateOffer(options);
3164 SetLocalDescriptionWithoutError(offer);
3165
deadbeefcbecd352015-09-23 11:50:27 -07003166 EXPECT_NE(session_->voice_rtp_transport_channel(),
3167 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003168
deadbeefab9b2d12015-10-14 11:33:11 -07003169 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003170
3171 // Remove BUNDLE from the answer.
3172 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3173 CreateRemoteAnswer(session_->local_description()));
3174 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3175 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3176 JsepSessionDescription* modified_answer =
3177 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3178 modified_answer->Initialize(answer_copy, "1", "1");
3179 SetRemoteDescriptionWithoutError(modified_answer); //
3180
deadbeefcbecd352015-09-23 11:50:27 -07003181 EXPECT_NE(session_->voice_rtp_transport_channel(),
3182 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183}
3184
Peter Thatcher4eddf182015-04-30 10:55:59 -07003185// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3186TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3187 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003189
3190 PeerConnectionInterface::RTCOfferAnswerOptions options;
3191 options.use_rtp_mux = true;
3192
3193 SessionDescriptionInterface* offer = CreateOffer(options);
3194 SetRemoteDescriptionWithoutError(offer);
3195
deadbeefcbecd352015-09-23 11:50:27 -07003196 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003198}
3199
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003200TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3201 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
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
3220TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3221 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003222 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003223
3224 PeerConnectionInterface::RTCOfferAnswerOptions options;
3225 SessionDescriptionInterface* offer = CreateOffer(options);
3226 SetLocalDescriptionWithoutError(offer);
3227
deadbeefcbecd352015-09-23 11:50:27 -07003228 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3229 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003230
deadbeefab9b2d12015-10-14 11:33:11 -07003231 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003232 SessionDescriptionInterface* answer =
3233 CreateRemoteAnswer(session_->local_description());
3234 SetRemoteDescriptionWithoutError(answer);
3235
deadbeefcbecd352015-09-23 11:50:27 -07003236 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3237 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003238}
3239
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003240// This test verifies that SetLocalDescription and SetRemoteDescription fails
3241// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3242TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003243 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003244 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003245
3246 PeerConnectionInterface::RTCOfferAnswerOptions options;
3247 options.use_rtp_mux = true;
3248
3249 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003250 std::string offer_str;
3251 offer->ToString(&offer_str);
3252 // Disable rtcp-mux
3253 const std::string rtcp_mux = "rtcp-mux";
3254 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003255 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003256 xrtcp_mux.c_str(), xrtcp_mux.length(),
3257 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003258 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003259 new JsepSessionDescription(JsepSessionDescription::kOffer);
3260 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003261 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003262 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003263 new JsepSessionDescription(JsepSessionDescription::kOffer);
3264 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003265 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003266 // Trying unmodified SDP.
3267 SetLocalDescriptionWithoutError(offer);
3268}
3269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003271 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273 CreateAndSetRemoteOfferAndLocalAnswer();
3274 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3275 ASSERT_TRUE(channel != NULL);
3276 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003277 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003278 double volume;
3279 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3280 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003281 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003282 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3283 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003284 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003285 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3286 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287}
3288
3289TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003290 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003291 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292 CreateAndSetRemoteOfferAndLocalAnswer();
3293 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3294 ASSERT_TRUE(channel != NULL);
3295 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003296 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3298
3299 cricket::AudioOptions options;
3300 options.echo_cancellation.Set(true);
3301
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003302 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003303 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3305 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003306 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003308 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003309 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003310 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3311 bool value;
3312 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3313 EXPECT_TRUE(value);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003314 EXPECT_TRUE(renderer->sink() == NULL);
3315}
3316
3317TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003318 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003319 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003320 CreateAndSetRemoteOfferAndLocalAnswer();
3321 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3322 ASSERT_TRUE(channel != NULL);
3323 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003324 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003325
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003326 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003327 cricket::AudioOptions options;
3328 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3329 EXPECT_TRUE(renderer->sink() != NULL);
3330
3331 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3332 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3333 // SetSink(NULL) callback afterwards.
3334 renderer.reset();
3335
3336 // This will trigger SetSink(NULL) if no OnClose() callback.
3337 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338}
3339
3340TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003341 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003342 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 CreateAndSetRemoteOfferAndLocalAnswer();
3344 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3345 ASSERT_TRUE(channel != NULL);
3346 ASSERT_LT(0u, channel->renderers().size());
3347 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3348 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003349 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 cricket::FakeVideoRenderer renderer;
3351 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3352 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3353 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3354 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3355}
3356
3357TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003358 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003359 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360 CreateAndSetRemoteOfferAndLocalAnswer();
3361 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3362 ASSERT_TRUE(channel != NULL);
3363 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003364 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3366 cricket::VideoOptions* options = NULL;
3367 session_->SetVideoSend(send_ssrc, false, options);
3368 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3369 session_->SetVideoSend(send_ssrc, true, options);
3370 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3371}
3372
3373TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3374 TestCanInsertDtmf(false);
3375}
3376
3377TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3378 TestCanInsertDtmf(true);
3379}
3380
3381TEST_F(WebRtcSessionTest, InsertDtmf) {
3382 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003383 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003384 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003385 CreateAndSetRemoteOfferAndLocalAnswer();
3386 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3387 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3388
3389 // Insert DTMF
3390 const int expected_flags = DF_SEND;
3391 const int expected_duration = 90;
3392 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3393 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3394 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3395
3396 // Verify
3397 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003398 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3400 expected_duration, expected_flags));
3401 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3402 expected_duration, expected_flags));
3403 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3404 expected_duration, expected_flags));
3405}
3406
deadbeefd59daf82015-10-14 15:02:44 -07003407// This test verifies the |initial_offerer| flag when session initiates the
3408// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003410 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003411 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003412 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3414 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003415 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003417 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418}
3419
deadbeefd59daf82015-10-14 15:02:44 -07003420// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003422 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003423 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 SessionDescriptionInterface* offer = CreateRemoteOffer();
3425 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003426 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427
deadbeefd59daf82015-10-14 15:02:44 -07003428 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003430 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431}
3432
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3434TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003435 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003437 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003439 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 CreateRemoteAnswer(session_->local_description()));
3441
3442 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3443 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003444 JsepSessionDescription* modified_answer =
3445 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446
3447 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3448 answer->session_id(),
3449 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003450 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451
wu@webrtc.org4e393072014-04-07 17:04:35 +00003452 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 std::string sdp;
3454 EXPECT_TRUE(answer->ToString(&sdp));
3455 const std::string kAudioMid = "a=mid:audio";
3456 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003457 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 kAudioMidReplaceStr.c_str(),
3459 kAudioMidReplaceStr.length(),
3460 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003461 SessionDescriptionInterface* modified_answer1 =
3462 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003463 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464
wu@webrtc.org4e393072014-04-07 17:04:35 +00003465 // Different media types.
3466 EXPECT_TRUE(answer->ToString(&sdp));
3467 const std::string kAudioMline = "m=audio";
3468 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003469 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003470 kAudioMlineReplaceStr.c_str(),
3471 kAudioMlineReplaceStr.length(),
3472 &sdp);
3473 SessionDescriptionInterface* modified_answer2 =
3474 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3475 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 SetRemoteDescriptionWithoutError(answer.release());
3478}
3479
3480// Verifying remote offer and local answer have matching m-lines as per
3481// RFC 3264.
3482TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003483 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003484 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 SessionDescriptionInterface* offer = CreateRemoteOffer();
3486 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003487 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488
3489 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3490 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003491 JsepSessionDescription* modified_answer =
3492 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493
3494 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3495 answer->session_id(),
3496 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003497 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SetLocalDescriptionWithoutError(answer);
3499}
3500
3501// This test verifies that WebRtcSession does not start candidate allocation
3502// before SetLocalDescription is called.
3503TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003504 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003505 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 SessionDescriptionInterface* offer = CreateRemoteOffer();
3507 cricket::Candidate candidate;
3508 candidate.set_component(1);
3509 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3510 candidate);
3511 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3512 cricket::Candidate candidate1;
3513 candidate1.set_component(1);
3514 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3515 candidate1);
3516 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3517 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003518 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3519 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520
3521 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003522 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3524 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3525
wu@webrtc.org91053e72013-08-10 07:18:04 +00003526 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3529}
3530
3531// This test verifies that crypto parameter is updated in local session
3532// description as per security policy set in MediaSessionDescriptionFactory.
3533TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003534 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003535 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003536 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537
3538 // Making sure SetLocalDescription correctly sets crypto value in
3539 // SessionDescription object after de-serialization of sdp string. The value
3540 // will be set as per MediaSessionDescriptionFactory.
3541 std::string offer_str;
3542 offer->ToString(&offer_str);
3543 SessionDescriptionInterface* jsep_offer_str =
3544 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3545 SetLocalDescriptionWithoutError(jsep_offer_str);
3546 EXPECT_TRUE(session_->voice_channel()->secure_required());
3547 EXPECT_TRUE(session_->video_channel()->secure_required());
3548}
3549
3550// This test verifies the crypto parameter when security is disabled.
3551TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003552 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003553 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003554 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003555 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556
3557 // Making sure SetLocalDescription correctly sets crypto value in
3558 // SessionDescription object after de-serialization of sdp string. The value
3559 // will be set as per MediaSessionDescriptionFactory.
3560 std::string offer_str;
3561 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003562 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3564 SetLocalDescriptionWithoutError(jsep_offer_str);
3565 EXPECT_FALSE(session_->voice_channel()->secure_required());
3566 EXPECT_FALSE(session_->video_channel()->secure_required());
3567}
3568
3569// This test verifies that an answer contains new ufrag and password if an offer
3570// with new ufrag and password is received.
3571TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003572 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003574 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003575 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576 CreateRemoteOffer(options));
3577 SetRemoteDescriptionWithoutError(offer.release());
3578
deadbeefab9b2d12015-10-14 11:33:11 -07003579 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003580 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003581 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582 SetLocalDescriptionWithoutError(answer.release());
3583
3584 // Receive an offer with new ufrag and password.
3585 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003586 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003587 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 SetRemoteDescriptionWithoutError(updated_offer1.release());
3589
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003590 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003591 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592
3593 CompareIceUfragAndPassword(updated_answer1->description(),
3594 session_->local_description()->description(),
3595 false);
3596
3597 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003598}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599
wu@webrtc.org91053e72013-08-10 07:18:04 +00003600// This test verifies that an answer contains old ufrag and password if an offer
3601// with old ufrag and password is received.
3602TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003603 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003604 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003605 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003606 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003607 CreateRemoteOffer(options));
3608 SetRemoteDescriptionWithoutError(offer.release());
3609
deadbeefab9b2d12015-10-14 11:33:11 -07003610 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003611 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003612 CreateAnswer(NULL));
3613 SetLocalDescriptionWithoutError(answer.release());
3614
3615 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003617 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003618 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619 SetRemoteDescriptionWithoutError(updated_offer2.release());
3620
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003621 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003622 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623
3624 CompareIceUfragAndPassword(updated_answer2->description(),
3625 session_->local_description()->description(),
3626 true);
3627
3628 SetLocalDescriptionWithoutError(updated_answer2.release());
3629}
3630
3631TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003632 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003633 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003634 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635 const std::string session_id_orig = offer->session_id();
3636 const std::string session_version_orig = offer->session_version();
3637 SetLocalDescriptionWithoutError(offer);
3638
3639 video_channel_ = media_engine_->GetVideoChannel(0);
3640 video_channel_->set_fail_set_send_codecs(true);
3641
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003642 SessionDescriptionInterface* answer =
3643 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003644 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003645
3646 // Test that after a content error, setting any description will
3647 // result in an error.
3648 video_channel_->set_fail_set_send_codecs(false);
3649 answer = CreateRemoteAnswer(session_->local_description());
3650 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3651 offer = CreateRemoteOffer();
3652 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653}
3654
3655// Runs the loopback call test with BUNDLE and STUN disabled.
3656TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3657 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003658 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003659 cricket::PORTALLOCATOR_DISABLE_STUN |
3660 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003661 TestLoopbackCall();
3662}
3663
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003664TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003665 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003666 cricket::PORTALLOCATOR_DISABLE_STUN |
3667 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3668 cricket::PORTALLOCATOR_DISABLE_RELAY);
3669
3670 // best connection is IPv6 since it has higher network preference.
3671 LoopbackNetworkConfiguration config;
3672 config.test_ipv6_network_ = true;
3673 config.best_connection_after_initial_ice_converged_ =
3674 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3675
3676 TestLoopbackCall(config);
3677}
3678
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003679// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003680TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003681 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3682 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003683 TestLoopbackCall();
3684}
3685
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3687 constraints_.reset(new FakeConstraints());
3688 constraints_->AddOptional(
3689 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003690 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003691
3692 SetLocalDescriptionWithDataChannel();
3693 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3694}
3695
Henrik Boström87713d02015-08-25 09:53:21 +02003696TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003697 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003698
3699 constraints_.reset(new FakeConstraints());
3700 constraints_->AddOptional(
3701 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003702 options_.disable_sctp_data_channels = false;
3703
Henrik Boström87713d02015-08-25 09:53:21 +02003704 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003705
3706 SetLocalDescriptionWithDataChannel();
3707 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3708}
3709
Henrik Boström87713d02015-08-25 09:53:21 +02003710TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003711 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003712
Henrik Boström87713d02015-08-25 09:53:21 +02003713 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003714
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003715 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003716 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003717 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3718}
3719
Henrik Boström87713d02015-08-25 09:53:21 +02003720TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003721 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003722 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003723 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003724
3725 // Create remote offer with SCTP.
3726 cricket::MediaSessionOptions options;
3727 options.data_channel_type = cricket::DCT_SCTP;
3728 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003729 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003730 SetRemoteDescriptionWithoutError(offer);
3731
3732 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003733 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003734 EXPECT_TRUE(answer != NULL);
3735 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3736 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003737}
3738
Henrik Boström87713d02015-08-25 09:53:21 +02003739TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 constraints_.reset(new FakeConstraints());
3741 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003742 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003743 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003744
3745 SetLocalDescriptionWithDataChannel();
3746 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3747}
3748
Henrik Boström87713d02015-08-25 09:53:21 +02003749TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003750 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751
Henrik Boström87713d02015-08-25 09:53:21 +02003752 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003753
3754 SetLocalDescriptionWithDataChannel();
3755 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3756}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003757
Henrik Boström87713d02015-08-25 09:53:21 +02003758TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003759 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003760 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003761 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003762
3763 SetLocalDescriptionWithDataChannel();
3764 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3765}
3766
Henrik Boström87713d02015-08-25 09:53:21 +02003767TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003768 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003769 const int new_send_port = 9998;
3770 const int new_recv_port = 7775;
3771
Henrik Boström87713d02015-08-25 09:53:21 +02003772 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003773 SetFactoryDtlsSrtp();
3774
3775 // By default, don't actually add the codecs to desc_factory_; they don't
3776 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3777 // let the session description get parsed. That'll get the proper codecs
3778 // into the stream.
3779 cricket::MediaSessionOptions options;
3780 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3781 "stream1", new_send_port, options);
3782
3783 // SetRemoteDescription will take the ownership of the offer.
3784 SetRemoteDescriptionWithoutError(offer);
3785
3786 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3787 new_recv_port, CreateAnswer(NULL));
3788 ASSERT_TRUE(answer != NULL);
3789
3790 // Now set the local description, which'll take ownership of the answer.
3791 SetLocalDescriptionWithoutError(answer);
3792
3793 // TEST PLAN: Set the port number to something new, set it in the SDP,
3794 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003795 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003796 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003797
3798 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3799 int portnum = -1;
3800 ASSERT_TRUE(ch != NULL);
3801 ASSERT_EQ(1UL, ch->send_codecs().size());
3802 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003803 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003804 ch->send_codecs()[0].name.c_str()));
3805 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3806 &portnum));
3807 EXPECT_EQ(new_send_port, portnum);
3808
3809 ASSERT_EQ(1UL, ch->recv_codecs().size());
3810 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003811 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003812 ch->recv_codecs()[0].name.c_str()));
3813 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3814 &portnum));
3815 EXPECT_EQ(new_recv_port, portnum);
3816}
3817
deadbeefab9b2d12015-10-14 11:33:11 -07003818// Verifies that when a session's DataChannel receives an OPEN message,
3819// WebRtcSession signals the DataChannel creation request with the expected
3820// config.
3821TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3822 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3823
3824 InitWithDtls(GetParam());
3825
3826 SetLocalDescriptionWithDataChannel();
3827 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3828
3829 webrtc::DataChannelInit config;
3830 config.id = 1;
3831 rtc::Buffer payload;
3832 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3833 cricket::ReceiveDataParams params;
3834 params.ssrc = config.id;
3835 params.type = cricket::DMT_CONTROL;
3836
3837 cricket::DataChannel* data_channel = session_->data_channel();
3838 data_channel->SignalDataReceived(data_channel, params, payload);
3839
3840 EXPECT_EQ("a", last_data_channel_label_);
3841 EXPECT_EQ(config.id, last_data_channel_config_.id);
3842 EXPECT_FALSE(last_data_channel_config_.negotiated);
3843 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3844 last_data_channel_config_.open_handshake_role);
3845}
3846
3847TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003848 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3849 FakeDtlsIdentityStore::GenerateCertificate();
3850
3851 PeerConnectionInterface::RTCConfiguration configuration;
3852 configuration.certificates.push_back(certificate);
3853 Init(nullptr, configuration);
3854 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3855
3856 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3857}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003858
Henrik Boström87713d02015-08-25 09:53:21 +02003859// Verifies that CreateOffer succeeds when CreateOffer is called before async
3860// identity generation is finished (even if a certificate is provided this is
3861// an async op).
3862TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3863 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3864 InitWithDtls(GetParam());
3865
Henrik Boströmd8281982015-08-27 10:12:24 +02003866 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003867 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003868 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3869
wu@webrtc.org91053e72013-08-10 07:18:04 +00003870 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003871 VerifyNoCryptoParams(offer->description(), true);
3872 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003873}
3874
3875// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003876// identity generation is finished (even if a certificate is provided this is
3877// an async op).
3878TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003879 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003880 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003881 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003882
3883 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003884 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003885 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003886 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003887 ASSERT_TRUE(offer.get() != NULL);
3888 SetRemoteDescriptionWithoutError(offer.release());
3889
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003890 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003891 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003892 VerifyNoCryptoParams(answer->description(), true);
3893 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003894}
3895
3896// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003897// identity generation is finished (even if a certificate is provided this is
3898// an async op).
3899TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003900 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003901 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003902
Henrik Boströmd8281982015-08-27 10:12:24 +02003903 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003904
3905 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003906 EXPECT_TRUE(offer != NULL);
3907}
3908
3909// Verifies that CreateOffer fails when CreateOffer is called after async
3910// identity generation fails.
3911TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003912 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003913 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003914
Henrik Boströmd8281982015-08-27 10:12:24 +02003915 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003916
3917 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003918 EXPECT_TRUE(offer == NULL);
3919}
3920
3921// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3922// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003923TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003924 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003925 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003926 VerifyMultipleAsyncCreateDescription(GetParam(),
3927 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003928}
3929
3930// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3931// before async identity generation fails.
3932TEST_F(WebRtcSessionTest,
3933 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003934 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003935 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3936 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003937}
3938
3939// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3940// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003941TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003942 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003944 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003945 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946}
3947
3948// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3949// before async identity generation fails.
3950TEST_F(WebRtcSessionTest,
3951 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003952 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003953 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3954 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003955}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003956
3957// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3958// offer has no SDES crypto but only DTLS fingerprint.
3959TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3960 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003961 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003962 // Create a remote offer with secured transport disabled.
3963 cricket::MediaSessionOptions options;
3964 JsepSessionDescription* offer(CreateRemoteOffer(
3965 options, cricket::SEC_DISABLED));
3966 // Adds a DTLS fingerprint to the remote offer.
3967 cricket::SessionDescription* sdp = offer->description();
3968 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3969 ASSERT_TRUE(audio != NULL);
3970 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3971 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003972 rtc::SSLFingerprint::CreateFromRfc4572(
3973 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003974 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003975 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003976}
3977
wu@webrtc.orgde305012013-10-31 15:40:38 +00003978// This test verifies DSCP is properly applied on the media channels.
3979TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3980 constraints_.reset(new FakeConstraints());
3981 constraints_->AddOptional(
3982 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003983 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003984 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003985 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003986
3987 SetLocalDescriptionWithoutError(offer);
3988
3989 video_channel_ = media_engine_->GetVideoChannel(0);
3990 voice_channel_ = media_engine_->GetVoiceChannel(0);
3991
3992 ASSERT_TRUE(video_channel_ != NULL);
3993 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003994 const cricket::AudioOptions& audio_options = voice_channel_->options();
3995 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003996 EXPECT_TRUE(audio_options.dscp.IsSet());
3997 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3998 EXPECT_TRUE(video_options.dscp.IsSet());
3999 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
4000}
4001
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004002TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4003 constraints_.reset(new FakeConstraints());
4004 constraints_->AddOptional(
4005 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4006 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004007 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004008 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004009 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004010
4011 SetLocalDescriptionWithoutError(offer);
4012
4013 video_channel_ = media_engine_->GetVideoChannel(0);
4014
4015 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004016 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004017 EXPECT_TRUE(
4018 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
4019}
4020
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004021TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4022 // Number of unsignalled receiving streams should be between 0 and
4023 // kMaxUnsignalledRecvStreams.
4024 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4025 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4026 kMaxUnsignalledRecvStreams);
4027 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4028}
4029
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004030TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4031 constraints_.reset(new FakeConstraints());
4032 constraints_->AddOptional(
4033 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4034 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004035 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004036 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004037 SessionDescriptionInterface* offer = CreateOffer();
4038
4039 SetLocalDescriptionWithoutError(offer);
4040
4041 voice_channel_ = media_engine_->GetVoiceChannel(0);
4042
4043 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004044 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004045 EXPECT_TRUE(
4046 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
4047}
4048
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004049// Tests that we can renegotiate new media content with ICE candidates in the
4050// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004051TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004052 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004053 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004054 SetFactoryDtlsSrtp();
4055
deadbeefab9b2d12015-10-14 11:33:11 -07004056 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004057 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004058 SetLocalDescriptionWithoutError(offer);
4059
4060 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4061 SetRemoteDescriptionWithoutError(answer);
4062
4063 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004064 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004065 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4066
4067 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004068 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004069 candidate1.set_component(1);
4070 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4071 candidate1);
4072 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4073 SetRemoteDescriptionWithoutError(offer);
4074
4075 answer = CreateAnswer(NULL);
4076 SetLocalDescriptionWithoutError(answer);
4077}
4078
4079// Tests that we can renegotiate new media content with ICE candidates separated
4080// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004081TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004082 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004083 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004084 SetFactoryDtlsSrtp();
4085
deadbeefab9b2d12015-10-14 11:33:11 -07004086 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004087 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004088 SetLocalDescriptionWithoutError(offer);
4089
4090 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4091 SetRemoteDescriptionWithoutError(answer);
4092
4093 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004094 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004095 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4096 SetRemoteDescriptionWithoutError(offer);
4097
4098 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004099 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004100 candidate1.set_component(1);
4101 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4102 candidate1);
4103 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4104
4105 answer = CreateAnswer(NULL);
4106 SetLocalDescriptionWithoutError(answer);
4107}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004108// Tests that RTX codec is removed from the answer when it isn't supported
4109// by local side.
4110TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4111 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004112 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004113 std::string offer_sdp(kSdpWithRtx);
4114
4115 SessionDescriptionInterface* offer =
4116 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4117 EXPECT_TRUE(offer->ToString(&offer_sdp));
4118
4119 // Offer SDP contains the RTX codec.
4120 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4121 SetRemoteDescriptionWithoutError(offer);
4122
4123 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4124 std::string answer_sdp;
4125 answer->ToString(&answer_sdp);
4126 // Answer SDP removes the unsupported RTX codec.
4127 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4128 SetLocalDescriptionWithoutError(answer);
4129}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004130
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004131// This verifies that the voice channel after bundle has both options from video
4132// and voice channels.
4133TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4134 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004135 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004136
4137 PeerConnectionInterface::RTCOfferAnswerOptions options;
4138 options.use_rtp_mux = true;
4139
4140 SessionDescriptionInterface* offer = CreateOffer(options);
4141 SetLocalDescriptionWithoutError(offer);
4142
4143 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4144 rtc::Socket::Option::OPT_SNDBUF, 4000);
4145
4146 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4147 rtc::Socket::Option::OPT_RCVBUF, 8000);
4148
4149 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004150 EXPECT_TRUE(session_->video_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);
deadbeefcbecd352015-09-23 11:50:27 -07004153 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004154 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4155
deadbeefcbecd352015-09-23 11:50:27 -07004156 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004157 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4158 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004159 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004160 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4161
deadbeefcbecd352015-09-23 11:50:27 -07004162 EXPECT_NE(session_->voice_rtp_transport_channel(),
4163 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004164
deadbeefab9b2d12015-10-14 11:33:11 -07004165 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004166 SessionDescriptionInterface* answer =
4167 CreateRemoteAnswer(session_->local_description());
4168 SetRemoteDescriptionWithoutError(answer);
4169
deadbeefcbecd352015-09-23 11:50:27 -07004170 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004171 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4172 EXPECT_EQ(4000, option_val);
4173
deadbeefcbecd352015-09-23 11:50:27 -07004174 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004175 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4176 EXPECT_EQ(8000, option_val);
4177}
4178
tommi0f620f42015-07-09 03:25:02 -07004179// Test creating a session, request multiple offers, destroy the session
4180// and make sure we got success/failure callbacks for all of the requests.
4181// Background: crbug.com/507307
4182TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4183 Init();
4184
4185 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4186 PeerConnectionInterface::RTCOfferAnswerOptions options;
4187 options.offer_to_receive_audio =
4188 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004189 cricket::MediaSessionOptions session_options;
4190 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004191
4192 for (auto& o : observers) {
4193 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004194 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004195 }
4196
4197 session_.reset();
4198
tommi0f620f42015-07-09 03:25:02 -07004199 for (auto& o : observers) {
4200 // We expect to have received a notification now even if the session was
4201 // terminated. The offer creation may or may not have succeeded, but we
4202 // must have received a notification which, so the only invalid state
4203 // is kInit.
4204 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4205 }
4206}
4207
stefanc1aeaf02015-10-15 07:26:07 -07004208TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4209 TestPacketOptions();
4210}
4211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004212// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4213// currently fails because upon disconnection and reconnection OnIceComplete is
4214// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004215
deadbeefcbecd352015-09-23 11:50:27 -07004216INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4217 WebRtcSessionTest,
4218 testing::Values(ALREADY_GENERATED,
4219 DTLS_IDENTITY_STORE));