blob: 2853ca43a7301b5e28b202f60041f35784342bb2 [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"
jbauchac8869e2015-07-03 01:36:14 -070031#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include "talk/app/webrtc/jsepicecandidate.h"
33#include "talk/app/webrtc/jsepsessiondescription.h"
34#include "talk/app/webrtc/mediastreamsignaling.h"
35#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020037#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000041#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/media/base/fakemediaengine.h"
43#include "talk/media/base/fakevideorenderer.h"
44#include "talk/media/base/mediachannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000045#include "webrtc/p2p/base/stunserver.h"
46#include "webrtc/p2p/base/teststunserver.h"
47#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000048#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000049#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000050#include "talk/session/media/channelmanager.h"
51#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052#include "webrtc/base/fakenetwork.h"
53#include "webrtc/base/firewallsocketserver.h"
54#include "webrtc/base/gunit.h"
55#include "webrtc/base/logging.h"
56#include "webrtc/base/network.h"
57#include "webrtc/base/physicalsocketserver.h"
58#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020059#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060#include "webrtc/base/sslstreamadapter.h"
61#include "webrtc/base/stringutils.h"
62#include "webrtc/base/thread.h"
63#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
65#define MAYBE_SKIP_TEST(feature) \
66 if (!(feature())) { \
67 LOG(LS_INFO) << "Feature disabled... skipping"; \
68 return; \
69 }
70
71using cricket::BaseSession;
72using cricket::DF_PLAY;
73using cricket::DF_SEND;
74using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000076using rtc::SocketAddress;
77using rtc::scoped_ptr;
78using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000080using webrtc::CreateSessionDescriptionObserver;
81using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020082using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070084using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::IceCandidateCollection;
86using webrtc::JsepIceCandidate;
87using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000088using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::PeerConnectionInterface;
90using webrtc::SessionDescriptionInterface;
91using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000092using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000093using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000094using webrtc::kCreateChannelFailed;
95using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000097using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000098using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000099using webrtc::kSdpWithoutDtlsFingerprint;
100using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000102using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000103using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000105typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
106
wu@webrtc.org364f2042013-11-20 21:49:41 +0000107static const int kClientAddrPort = 0;
108static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000109static const char kClientIPv6AddrHost1[] =
110 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111static const char kClientAddrHost2[] = "22.22.22.22";
112static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000113static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
114static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000115static const char kTurnUsername[] = "test";
116static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
118static const char kSessionVersion[] = "1";
119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120// Media index of candidates belonging to the first media content.
121static const int kMediaContentIndex0 = 0;
122static const char kMediaContentName0[] = "audio";
123
124// Media index of candidates belonging to the second media content.
125static const int kMediaContentIndex1 = 1;
126static const char kMediaContentName1[] = "video";
127
128static const int kIceCandidatesTimeout = 10000;
129
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000130static const char kFakeDtlsFingerprint[] =
131 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
132 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
133
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000134static const char kTooLongIceUfragPwd[] =
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
139
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000140static const char kSdpWithRtx[] =
141 "v=0\r\n"
142 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
143 "s=-\r\n"
144 "t=0 0\r\n"
145 "a=msid-semantic: WMS stream1\r\n"
146 "m=video 9 RTP/SAVPF 0 96\r\n"
147 "c=IN IP4 0.0.0.0\r\n"
148 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
149 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
150 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
151 "a=mid:video\r\n"
152 "a=sendrecv\r\n"
153 "a=rtcp-mux\r\n"
154 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
155 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
156 "a=rtpmap:0 fake_video_codec/90000\r\n"
157 "a=rtpmap:96 rtx/90000\r\n"
158 "a=fmtp:96 apt=0\r\n";
159
Henrik Boström87713d02015-08-25 09:53:21 +0200160enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
161
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162// Add some extra |newlines| to the |message| after |line|.
163static void InjectAfter(const std::string& line,
164 const std::string& newlines,
165 std::string* message) {
166 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700167 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
168 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169}
170
171class MockIceObserver : public webrtc::IceObserver {
172 public:
173 MockIceObserver()
174 : oncandidatesready_(false),
175 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
176 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
177 }
178
179 virtual void OnIceConnectionChange(
180 PeerConnectionInterface::IceConnectionState new_state) {
181 ice_connection_state_ = new_state;
182 }
183 virtual void OnIceGatheringChange(
184 PeerConnectionInterface::IceGatheringState new_state) {
185 // We can never transition back to "new".
186 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
187 ice_gathering_state_ = new_state;
188
189 // oncandidatesready_ really means "ICE gathering is complete".
190 // This if statement ensures that this value remains correct when we
191 // transition from kIceGatheringComplete to kIceGatheringGathering.
192 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
193 oncandidatesready_ = false;
194 }
195 }
196
197 // Found a new candidate.
198 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000199 switch (candidate->sdp_mline_index()) {
200 case kMediaContentIndex0:
201 mline_0_candidates_.push_back(candidate->candidate());
202 break;
203 case kMediaContentIndex1:
204 mline_1_candidates_.push_back(candidate->candidate());
205 break;
206 default:
207 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000209
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 // The ICE gathering state should always be Gathering when a candidate is
211 // received (or possibly Completed in the case of the final candidate).
212 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
213 }
214
215 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
216 virtual void OnIceComplete() {
217 EXPECT_FALSE(oncandidatesready_);
218 oncandidatesready_ = true;
219
220 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
221 // be called approximately simultaneously. For ease of testing, this
222 // check additionally requires that they be called in the above order.
223 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
224 ice_gathering_state_);
225 }
226
227 bool oncandidatesready_;
228 std::vector<cricket::Candidate> mline_0_candidates_;
229 std::vector<cricket::Candidate> mline_1_candidates_;
230 PeerConnectionInterface::IceConnectionState ice_connection_state_;
231 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
232};
233
234class WebRtcSessionForTest : public webrtc::WebRtcSession {
235 public:
236 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000237 rtc::Thread* signaling_thread,
238 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 cricket::PortAllocator* port_allocator,
240 webrtc::IceObserver* ice_observer,
241 webrtc::MediaStreamSignaling* mediastream_signaling)
242 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
243 mediastream_signaling) {
244 RegisterIceObserver(ice_observer);
245 }
246 virtual ~WebRtcSessionForTest() {}
247
deadbeefcbecd352015-09-23 11:50:27 -0700248 // Note that these methods are only safe to use if the signaling thread
249 // is the same as the worker thread
250 cricket::TransportChannel* voice_rtp_transport_channel() {
251 return rtp_transport_channel(voice_channel());
252 }
253
254 cricket::TransportChannel* voice_rtcp_transport_channel() {
255 return rtcp_transport_channel(voice_channel());
256 }
257
258 cricket::TransportChannel* video_rtp_transport_channel() {
259 return rtp_transport_channel(video_channel());
260 }
261
262 cricket::TransportChannel* video_rtcp_transport_channel() {
263 return rtcp_transport_channel(video_channel());
264 }
265
266 cricket::TransportChannel* data_rtp_transport_channel() {
267 return rtp_transport_channel(data_channel());
268 }
269
270 cricket::TransportChannel* data_rtcp_transport_channel() {
271 return rtcp_transport_channel(data_channel());
272 }
273
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 using webrtc::WebRtcSession::SetAudioPlayout;
275 using webrtc::WebRtcSession::SetAudioSend;
276 using webrtc::WebRtcSession::SetCaptureDevice;
277 using webrtc::WebRtcSession::SetVideoPlayout;
278 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700279
280 private:
281 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
282 if (!ch) {
283 return nullptr;
284 }
285 return ch->transport_channel();
286 }
287
288 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
289 if (!ch) {
290 return nullptr;
291 }
292 return ch->rtcp_transport_channel();
293 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294};
295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000299 enum State {
300 kInit,
301 kFailed,
302 kSucceeded,
303 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000304 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000305
306 // CreateSessionDescriptionObserver implementation.
307 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000308 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309 state_ = kSucceeded;
310 }
311 virtual void OnFailure(const std::string& error) {
312 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 }
314
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000315 SessionDescriptionInterface* description() { return description_.get(); }
316
317 SessionDescriptionInterface* ReleaseDescription() {
318 return description_.release();
319 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320
wu@webrtc.org91053e72013-08-10 07:18:04 +0000321 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322
wu@webrtc.org91053e72013-08-10 07:18:04 +0000323 protected:
324 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325
326 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000327 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000328 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329};
330
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000331class FakeAudioRenderer : public cricket::AudioRenderer {
332 public:
torbjorngeefbc3b2015-10-08 13:10:36 -0700333 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000334 virtual ~FakeAudioRenderer() {
335 if (sink_)
336 sink_->OnClose();
337 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000338
torbjorngeefbc3b2015-10-08 13:10:36 -0700339 void AddChannel(int channel_id) override {
340 ASSERT(channel_id_ == -1);
341 channel_id_ = channel_id;
342 }
343 void RemoveChannel(int channel_id) override {
344 ASSERT(channel_id == channel_id_);
345 channel_id_ = -1;
346 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000347 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000348
torbjorngeefbc3b2015-10-08 13:10:36 -0700349 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000350 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000351 private:
torbjorngeefbc3b2015-10-08 13:10:36 -0700352 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000353 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000354};
355
Henrik Boström87713d02015-08-25 09:53:21 +0200356class WebRtcSessionTest
357 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 protected:
359 // TODO Investigate why ChannelManager crashes, if it's created
360 // after stun_server.
361 WebRtcSessionTest()
362 : media_engine_(new cricket::FakeMediaEngine()),
363 data_engine_(new cricket::FakeDataEngine()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 channel_manager_(new cricket::ChannelManager(
solenbergfacbbec2015-09-24 00:41:50 -0700365 media_engine_, data_engine_, new cricket::CaptureManager(),
366 rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 tdesc_factory_(new cricket::TransportDescriptionFactory()),
368 desc_factory_(new cricket::MediaSessionDescriptionFactory(
369 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000370 pss_(new rtc::PhysicalSocketServer),
371 vss_(new rtc::VirtualSocketServer(pss_.get())),
372 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000374 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000375 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000376 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
377 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000378 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700379 mediastream_signaling_(channel_manager_.get()),
380 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000381 cricket::ServerAddresses stun_servers;
382 stun_servers.insert(stun_socket_addr_);
383 allocator_.reset(new cricket::BasicPortAllocator(
384 &network_manager_,
385 stun_servers,
386 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000387 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700388 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 EXPECT_TRUE(channel_manager_->Init());
390 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000391 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 }
393
394 void AddInterface(const SocketAddress& addr) {
395 network_manager_.AddInterface(addr);
396 }
397
Henrik Boström87713d02015-08-25 09:53:21 +0200398 // If |dtls_identity_store| != null or |rtc_configuration| contains
399 // |certificates| then DTLS will be enabled unless explicitly disabled by
400 // |rtc_configuration| options. When DTLS is enabled a certificate will be
401 // used if provided, otherwise one will be generated using the
402 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000403 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200404 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200405 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 ASSERT_TRUE(session_.get() == NULL);
407 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000408 channel_manager_.get(), rtc::Thread::Current(),
409 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 &observer_,
411 &mediastream_signaling_));
412
413 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
414 observer_.ice_connection_state_);
415 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
416 observer_.ice_gathering_state_);
417
deadbeefcbecd352015-09-23 11:50:27 -0700418 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
419 dtls_identity_store.Pass(),
420 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700421 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 }
423
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000424 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200425 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200426 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000427 }
428
429 void InitWithIceTransport(
430 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200431 PeerConnectionInterface::RTCConfiguration configuration;
432 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200433 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000434 }
435
436 void InitWithBundlePolicy(
437 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200438 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200439 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200440 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700441 }
442
443 void InitWithRtcpMuxPolicy(
444 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
445 PeerConnectionInterface::RTCConfiguration configuration;
446 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200447 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000448 }
449
Henrik Boström87713d02015-08-25 09:53:21 +0200450 // Successfully init with DTLS; with a certificate generated and supplied or
451 // with a store that generates it for us.
452 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
453 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
454 PeerConnectionInterface::RTCConfiguration configuration;
455 if (cert_gen_method == ALREADY_GENERATED) {
456 configuration.certificates.push_back(
457 FakeDtlsIdentityStore::GenerateCertificate());
458 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
459 dtls_identity_store.reset(new FakeDtlsIdentityStore());
460 dtls_identity_store->set_should_fail(false);
461 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700462 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200463 }
464 Init(dtls_identity_store.Pass(), configuration);
465 }
466
467 // Init with DTLS with a store that will fail to generate a certificate.
468 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200469 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
470 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200471 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200472 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200473 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000474 }
475
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 void InitWithDtmfCodec() {
477 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000478 const cricket::AudioCodec kTelephoneEventCodec(
479 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 std::vector<cricket::AudioCodec> codecs;
481 codecs.push_back(kTelephoneEventCodec);
482 media_engine_->SetAudioCodecs(codecs);
483 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000484 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000485 }
486
487 // Creates a local offer and applies it. Starts ice.
488 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
489 // to decide which streams to create.
490 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000491 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 SetLocalDescriptionWithoutError(offer);
493 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
494 observer_.ice_gathering_state_,
495 kIceCandidatesTimeout);
496 }
497
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000498 SessionDescriptionInterface* CreateOffer() {
499 PeerConnectionInterface::RTCOfferAnswerOptions options;
500 options.offer_to_receive_audio =
501 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
502
503 return CreateOffer(options);
504 }
505
wu@webrtc.org91053e72013-08-10 07:18:04 +0000506 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000507 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000508 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000509 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000510 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000511 EXPECT_TRUE_WAIT(
512 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000513 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000514 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000515 }
516
517 SessionDescriptionInterface* CreateAnswer(
518 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000519 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000520 = new WebRtcSessionCreateSDPObserverForTest();
521 session_->CreateAnswer(observer, constraints);
522 EXPECT_TRUE_WAIT(
523 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000524 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000525 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000526 }
527
wu@webrtc.org364f2042013-11-20 21:49:41 +0000528 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 return (session_->voice_channel() != NULL &&
530 session_->video_channel() != NULL);
531 }
532
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
534 ASSERT_TRUE(session_.get() != NULL);
535 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
536 ASSERT_TRUE(content != NULL);
537 const cricket::AudioContentDescription* audio_content =
538 static_cast<const cricket::AudioContentDescription*>(
539 content->description);
540 ASSERT_TRUE(audio_content != NULL);
541 ASSERT_EQ(1U, audio_content->cryptos().size());
542 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
543 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
544 audio_content->cryptos()[0].cipher_suite);
545 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
546 audio_content->protocol());
547
548 content = cricket::GetFirstVideoContent(sdp);
549 ASSERT_TRUE(content != NULL);
550 const cricket::VideoContentDescription* video_content =
551 static_cast<const cricket::VideoContentDescription*>(
552 content->description);
553 ASSERT_TRUE(video_content != NULL);
554 ASSERT_EQ(1U, video_content->cryptos().size());
555 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
556 video_content->cryptos()[0].cipher_suite);
557 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
558 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
559 video_content->protocol());
560 }
561
562 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
563 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
564 ASSERT_TRUE(content != NULL);
565 const cricket::AudioContentDescription* audio_content =
566 static_cast<const cricket::AudioContentDescription*>(
567 content->description);
568 ASSERT_TRUE(audio_content != NULL);
569 ASSERT_EQ(0U, audio_content->cryptos().size());
570
571 content = cricket::GetFirstVideoContent(sdp);
572 ASSERT_TRUE(content != NULL);
573 const cricket::VideoContentDescription* video_content =
574 static_cast<const cricket::VideoContentDescription*>(
575 content->description);
576 ASSERT_TRUE(video_content != NULL);
577 ASSERT_EQ(0U, video_content->cryptos().size());
578
579 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700580 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700582 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 video_content->protocol());
584 } else {
585 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
586 audio_content->protocol());
587 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
588 video_content->protocol());
589 }
590 }
591
592 // Set the internal fake description factories to do DTLS-SRTP.
593 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000594 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000596 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200597 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200598 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700599 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
600 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
602 }
603
604 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
605 bool expected) {
606 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
607 ASSERT_TRUE(audio != NULL);
608 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 const TransportInfo* video = sdp->GetTransportInfoByName("video");
610 ASSERT_TRUE(video != NULL);
611 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 }
613
614 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000615 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000617 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000618 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000620 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000622 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
623 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000624 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 // Answer should be NULL as no crypto params in offer.
626 ASSERT_TRUE(answer == NULL);
627 }
628
629 void VerifyAnswerFromCryptoOffer() {
630 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000631 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 options.bundle_enabled = true;
633 scoped_ptr<JsepSessionDescription> offer(
634 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
635 ASSERT_TRUE(offer.get() != NULL);
636 VerifyCryptoParams(offer->description());
637 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000638 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 ASSERT_TRUE(answer.get() != NULL);
640 VerifyCryptoParams(answer->description());
641 }
642
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000643 void SetAndVerifyNumUnsignalledRecvStreams(
644 int value_set, int value_expected) {
645 constraints_.reset(new FakeConstraints());
646 constraints_->AddOptional(
647 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
648 value_set);
649 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000650 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000651 mediastream_signaling_.SendAudioVideoStream1();
652 SessionDescriptionInterface* offer = CreateOffer();
653
654 SetLocalDescriptionWithoutError(offer);
655
656 video_channel_ = media_engine_->GetVideoChannel(0);
657
658 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700659 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000660 EXPECT_EQ(value_expected,
661 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
662 }
663
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
665 const cricket::SessionDescription* desc2,
666 bool expect_equal) {
667 if (desc1->contents().size() != desc2->contents().size()) {
668 EXPECT_FALSE(expect_equal);
669 return;
670 }
671
672 const cricket::ContentInfos& contents = desc1->contents();
673 cricket::ContentInfos::const_iterator it = contents.begin();
674
675 for (; it != contents.end(); ++it) {
676 const cricket::TransportDescription* transport_desc1 =
677 desc1->GetTransportDescriptionByName(it->name);
678 const cricket::TransportDescription* transport_desc2 =
679 desc2->GetTransportDescriptionByName(it->name);
680 if (!transport_desc1 || !transport_desc2) {
681 EXPECT_FALSE(expect_equal);
682 return;
683 }
684 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
685 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
686 EXPECT_FALSE(expect_equal);
687 return;
688 }
689 }
690 EXPECT_TRUE(expect_equal);
691 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000692
693 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
694 std::string *sdp) {
695 const cricket::SessionDescription* desc = current_desc->description();
696 EXPECT_TRUE(current_desc->ToString(sdp));
697
698 const cricket::ContentInfos& contents = desc->contents();
699 cricket::ContentInfos::const_iterator it = contents.begin();
700 // Replace ufrag and pwd lines with empty strings.
701 for (; it != contents.end(); ++it) {
702 const cricket::TransportDescription* transport_desc =
703 desc->GetTransportDescriptionByName(it->name);
704 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
705 + "\r\n";
706 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
707 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000708 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000709 "", 0,
710 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000711 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000712 "", 0,
713 sdp);
714 }
715 }
716
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000717 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
718 const std::string& modified_ice_ufrag,
719 const std::string& modified_ice_pwd,
720 std::string* sdp) {
721 const cricket::SessionDescription* desc = current_desc->description();
722 EXPECT_TRUE(current_desc->ToString(sdp));
723
724 const cricket::ContentInfos& contents = desc->contents();
725 cricket::ContentInfos::const_iterator it = contents.begin();
726 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
727 // |modified_ice_pwd| strings.
728 for (; it != contents.end(); ++it) {
729 const cricket::TransportDescription* transport_desc =
730 desc->GetTransportDescriptionByName(it->name);
731 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
732 + "\r\n";
733 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
734 + "\r\n";
735 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
736 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000737 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000738 mod_ufrag.c_str(), mod_ufrag.length(),
739 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000740 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000741 mod_pwd.c_str(), mod_pwd.length(),
742 sdp);
743 }
744 }
745
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 // Creates a remote offer and and applies it as a remote description,
747 // creates a local answer and applies is as a local description.
748 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
749 // to decide which local and remote streams to create.
750 void CreateAndSetRemoteOfferAndLocalAnswer() {
751 SessionDescriptionInterface* offer = CreateRemoteOffer();
752 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000753 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 SetLocalDescriptionWithoutError(answer);
755 }
756 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
757 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700758 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
761 BaseSession::State expected_state) {
762 SetLocalDescriptionWithoutError(desc);
763 EXPECT_EQ(expected_state, session_->state());
764 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 void SetLocalDescriptionExpectError(const std::string& action,
766 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 SessionDescriptionInterface* desc) {
768 std::string error;
769 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000770 std::string sdp_type = "local ";
771 sdp_type.append(action);
772 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 EXPECT_NE(std::string::npos, error.find(expected_error));
774 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000775 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
776 SessionDescriptionInterface* desc) {
777 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
778 expected_error, desc);
779 }
780 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
781 SessionDescriptionInterface* desc) {
782 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
783 expected_error, desc);
784 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
786 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
787 }
788 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
789 BaseSession::State expected_state) {
790 SetRemoteDescriptionWithoutError(desc);
791 EXPECT_EQ(expected_state, session_->state());
792 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 void SetRemoteDescriptionExpectError(const std::string& action,
794 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 SessionDescriptionInterface* desc) {
796 std::string error;
797 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000798 std::string sdp_type = "remote ";
799 sdp_type.append(action);
800 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_NE(std::string::npos, error.find(expected_error));
802 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000803 void SetRemoteDescriptionOfferExpectError(
804 const std::string& expected_error, SessionDescriptionInterface* desc) {
805 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
806 expected_error, desc);
807 }
808 void SetRemoteDescriptionPranswerExpectError(
809 const std::string& expected_error, SessionDescriptionInterface* desc) {
810 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
811 expected_error, desc);
812 }
813 void SetRemoteDescriptionAnswerExpectError(
814 const std::string& expected_error, SessionDescriptionInterface* desc) {
815 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
816 expected_error, desc);
817 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818
819 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
820 SessionDescriptionInterface** nocrypto_answer) {
821 // Create a SDP without Crypto.
822 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000823 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 options.bundle_enabled = true;
825 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
826 ASSERT_TRUE(*offer != NULL);
827 VerifyCryptoParams((*offer)->description());
828
829 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
830 cricket::SEC_DISABLED);
831 EXPECT_TRUE(*nocrypto_answer != NULL);
832 }
833
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000834 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
835 SessionDescriptionInterface** nodtls_answer) {
836 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000837 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000838 options.bundle_enabled = true;
839
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000840 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000841 CreateRemoteOffer(options, cricket::SEC_ENABLED));
842
843 *nodtls_answer =
844 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
845 EXPECT_TRUE(*nodtls_answer != NULL);
846 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
847 VerifyCryptoParams((*nodtls_answer)->description());
848
849 SetFactoryDtlsSrtp();
850 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
851 ASSERT_TRUE(*offer != NULL);
852 VerifyFingerprintStatus((*offer)->description(), true);
853 VerifyCryptoParams((*offer)->description());
854 }
855
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 JsepSessionDescription* CreateRemoteOfferWithVersion(
857 cricket::MediaSessionOptions options,
858 cricket::SecurePolicy secure_policy,
859 const std::string& session_version,
860 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000861 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 const cricket::SessionDescription* cricket_desc = NULL;
863 if (current_desc) {
864 cricket_desc = current_desc->description();
865 session_id = current_desc->session_id();
866 }
867
868 desc_factory_->set_secure(secure_policy);
869 JsepSessionDescription* offer(
870 new JsepSessionDescription(JsepSessionDescription::kOffer));
871 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
872 session_id, session_version)) {
873 delete offer;
874 offer = NULL;
875 }
876 return offer;
877 }
878 JsepSessionDescription* CreateRemoteOffer(
879 cricket::MediaSessionOptions options) {
880 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
881 kSessionVersion, NULL);
882 }
883 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000884 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
885 return CreateRemoteOfferWithVersion(
886 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 }
888 JsepSessionDescription* CreateRemoteOffer(
889 cricket::MediaSessionOptions options,
890 const SessionDescriptionInterface* current_desc) {
891 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
892 kSessionVersion, current_desc);
893 }
894
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000895 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
896 const char* sctp_stream_name, int new_port,
897 cricket::MediaSessionOptions options) {
898 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000899 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
900 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000901 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
902 }
903
904 // Takes ownership of offer_basis (and deletes it).
905 JsepSessionDescription* ChangeSDPSctpPort(
906 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
907 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
908 // SessionDescription from the mutated string.
909 const char* default_port_str = "5000";
910 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000911 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000912 std::string offer_str;
913 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000914 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000915 new_port_str, strlen(new_port_str),
916 &offer_str);
917 JsepSessionDescription* offer = new JsepSessionDescription(
918 offer_basis->type());
919 delete offer_basis;
920 offer->Initialize(offer_str, NULL);
921 return offer;
922 }
923
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
925 // before this function to decide which streams to create.
926 JsepSessionDescription* CreateRemoteOffer() {
927 cricket::MediaSessionOptions options;
928 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
929 return CreateRemoteOffer(options, session_->remote_description());
930 }
931
932 JsepSessionDescription* CreateRemoteAnswer(
933 const SessionDescriptionInterface* offer,
934 cricket::MediaSessionOptions options,
935 cricket::SecurePolicy policy) {
936 desc_factory_->set_secure(policy);
937 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000938 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 JsepSessionDescription* answer(
940 new JsepSessionDescription(JsepSessionDescription::kAnswer));
941 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
942 options, NULL),
943 session_id, kSessionVersion)) {
944 delete answer;
945 answer = NULL;
946 }
947 return answer;
948 }
949
950 JsepSessionDescription* CreateRemoteAnswer(
951 const SessionDescriptionInterface* offer,
952 cricket::MediaSessionOptions options) {
953 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
954 }
955
956 // Creates an answer session description with streams based on
957 // |mediastream_signaling_|. Call
958 // mediastream_signaling_.UseOptionsWithStreamX() before this function
959 // to decide which streams to create.
960 JsepSessionDescription* CreateRemoteAnswer(
961 const SessionDescriptionInterface* offer) {
962 cricket::MediaSessionOptions options;
963 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
964 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
965 }
966
967 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000968 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000969 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000971
972 PeerConnectionInterface::RTCOfferAnswerOptions options;
973 options.use_rtp_mux = bundle;
974
975 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
977 // and answer.
978 SetLocalDescriptionWithoutError(offer);
979
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000980 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000981 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 std::string sdp;
983 EXPECT_TRUE(answer->ToString(&sdp));
984
985 size_t expected_candidate_num = 2;
986 if (!rtcp_mux) {
987 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
988 // for rtp and rtcp.
989 expected_candidate_num = 4;
990 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 const std::string kRtcpMux = "a=rtcp-mux";
992 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000993 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 kXRtcpMux.c_str(), kXRtcpMux.length(),
995 &sdp);
996 }
997
998 SessionDescriptionInterface* new_answer = CreateSessionDescription(
999 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000
1001 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001002 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1004 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001005 if (bundle) {
1006 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1007 } else {
1008 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 }
1010 }
1011 // Tests that we can only send DTMF when the dtmf codec is supported.
1012 void TestCanInsertDtmf(bool can) {
1013 if (can) {
1014 InitWithDtmfCodec();
1015 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001016 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 }
1018 mediastream_signaling_.SendAudioVideoStream1();
1019 CreateAndSetRemoteOfferAndLocalAnswer();
1020 EXPECT_FALSE(session_->CanInsertDtmf(""));
1021 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1022 }
1023
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001024 // Helper class to configure loopback network and verify Best
1025 // Connection using right IP protocol for TestLoopbackCall
1026 // method. LoopbackNetworkManager applies firewall rules to block
1027 // all ping traffic once ICE completed, and remove them to observe
1028 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1029 // verifies the best connection is using the right IP protocol after
1030 // initial ICE convergences.
1031
1032 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001033 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001034 LoopbackNetworkConfiguration()
1035 : test_ipv6_network_(false),
1036 test_extra_ipv4_network_(false),
1037 best_connection_after_initial_ice_converged_(1, 0) {}
1038
1039 // Used to track the expected best connection count in each IP protocol.
1040 struct ExpectedBestConnection {
1041 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1042 : ipv4_count_(ipv4_count),
1043 ipv6_count_(ipv6_count) {}
1044
1045 int ipv4_count_;
1046 int ipv6_count_;
1047 };
1048
1049 bool test_ipv6_network_;
1050 bool test_extra_ipv4_network_;
1051 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1052
1053 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001054 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001055 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1056 }
1057
1058 private:
jbauchac8869e2015-07-03 01:36:14 -07001059 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001060 const ExpectedBestConnection& expected) const {
1061 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001062 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1063 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001064 expected.ipv4_count_);
1065 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001066 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1067 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001068 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001069 // This is used in the loopback call so there is only single host to host
1070 // candidate pair.
1071 EXPECT_EQ(metrics_observer->GetEnumCounter(
1072 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1073 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001074 0);
1075 EXPECT_EQ(metrics_observer->GetEnumCounter(
1076 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1077 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001078 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001079 }
1080 };
1081
1082 class LoopbackNetworkManager {
1083 public:
1084 LoopbackNetworkManager(WebRtcSessionTest* session,
1085 const LoopbackNetworkConfiguration& config)
1086 : config_(config) {
1087 session->AddInterface(
1088 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1089 if (config_.test_extra_ipv4_network_) {
1090 session->AddInterface(
1091 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1092 }
1093 if (config_.test_ipv6_network_) {
1094 session->AddInterface(
1095 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1096 }
1097 }
1098
1099 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1100 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1101 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1102 if (config_.test_extra_ipv4_network_) {
1103 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1104 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1105 }
1106 if (config_.test_ipv6_network_) {
1107 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1108 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1109 }
1110 }
1111
1112 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1113
1114 private:
1115 LoopbackNetworkConfiguration config_;
1116 };
1117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 // The method sets up a call from the session to itself, in a loopback
1119 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001120 // disconnection, and then a permanent disconnection.
1121 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1123 // While running the call, this method also checks if the session goes through
1124 // the correct sequence of ICE states when a connection is established,
1125 // broken, and re-established.
1126 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001127 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1128 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001130
1131 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1132 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001133 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001135 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136
1137 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1138 observer_.ice_gathering_state_);
1139 SetLocalDescriptionWithoutError(offer);
1140 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1141 observer_.ice_connection_state_);
1142 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1143 observer_.ice_gathering_state_,
1144 kIceCandidatesTimeout);
1145 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1146 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1147 observer_.ice_gathering_state_,
1148 kIceCandidatesTimeout);
1149
1150 std::string sdp;
1151 offer->ToString(&sdp);
1152 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001153 webrtc::CreateSessionDescription(
1154 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 ASSERT_TRUE(desc != NULL);
1156 SetRemoteDescriptionWithoutError(desc);
1157
1158 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1159 observer_.ice_connection_state_,
1160 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001161
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001162 // The ice connection state is "Connected" too briefly to catch in a test.
1163 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 observer_.ice_connection_state_,
1165 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 // Adding firewall rule to block ping requests, which should cause
1169 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170
1171 loopback_network_manager.ApplyFirewallRules(fss_.get());
1172
1173 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1175 observer_.ice_connection_state_,
1176 kIceCandidatesTimeout);
1177
jbauchac8869e2015-07-03 01:36:14 -07001178 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001179
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001181 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001184 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185 observer_.ice_connection_state_,
1186 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001187
1188 // Now we block ping requests and wait until the ICE connection transitions
1189 // to the Failed state. This will take at least 30 seconds because it must
1190 // wait for the Port to timeout.
1191 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001192
1193 loopback_network_manager.ApplyFirewallRules(fss_.get());
1194 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001195 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001196 observer_.ice_connection_state_,
1197 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 }
1199
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001200 void TestLoopbackCall() {
1201 LoopbackNetworkConfiguration config;
1202 TestLoopbackCall(config);
1203 }
1204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1206 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001207 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1208 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1209
1210 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1212 codecs.push_back(kCNCodec1);
1213 codecs.push_back(kCNCodec2);
1214 media_engine_->SetAudioCodecs(codecs);
1215 desc_factory_->set_audio_codecs(codecs);
1216 }
1217
1218 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1219 const cricket::ContentDescription* description = content->description;
1220 ASSERT(description != NULL);
1221 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001222 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 ASSERT(audio_content_desc != NULL);
1224 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1225 if (audio_content_desc->codecs()[i].name == "CN")
1226 return false;
1227 }
1228 return true;
1229 }
1230
1231 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001232 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 dci.reliable = false;
1234 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001235 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 SetLocalDescriptionWithoutError(offer);
1237 }
1238
wu@webrtc.org91053e72013-08-10 07:18:04 +00001239 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001240 RTCCertificateGenerationMethod cert_gen_method,
1241 CreateSessionDescriptionRequest::Type type) {
1242 InitWithDtls(cert_gen_method);
1243 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1244 }
1245
1246 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1247 CreateSessionDescriptionRequest::Type type) {
1248 InitWithDtlsIdentityGenFail();
1249 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1250 }
1251
1252 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001253 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001254 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001255 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001256 if (type == CreateSessionDescriptionRequest::kAnswer) {
1257 cricket::MediaSessionOptions options;
1258 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001259 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001260 ASSERT_TRUE(offer.get() != NULL);
1261 SetRemoteDescriptionWithoutError(offer.release());
1262 }
1263
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001264 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001265 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001266 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001267 observers[kNumber];
1268 for (int i = 0; i < kNumber; ++i) {
1269 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1270 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001271 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001272 } else {
1273 session_->CreateAnswer(observers[i], NULL);
1274 }
1275 }
1276
1277 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1278 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1279 WebRtcSessionCreateSDPObserverForTest::kFailed;
1280
1281 for (int i = 0; i < kNumber; ++i) {
1282 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1283 if (success) {
1284 EXPECT_TRUE(observers[i]->description() != NULL);
1285 } else {
1286 EXPECT_TRUE(observers[i]->description() == NULL);
1287 }
1288 }
1289 }
1290
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001291 void ConfigureAllocatorWithTurn() {
1292 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1293 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1294 relay_server.credentials = credentials;
1295 relay_server.ports.push_back(cricket::ProtocolAddress(
1296 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1297 allocator_->AddRelay(relay_server);
1298 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001299 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001300 }
1301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 cricket::FakeMediaEngine* media_engine_;
1303 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001304 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1305 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001306 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1307 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1308 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1309 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1310 rtc::SocketServerScope ss_scope_;
1311 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001312 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001313 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001314 rtc::FakeNetworkManager network_manager_;
1315 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001316 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001317 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001319 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 MockIceObserver observer_;
1321 cricket::FakeVideoMediaChannel* video_channel_;
1322 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001323 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324};
1325
Henrik Boström87713d02015-08-25 09:53:21 +02001326TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1327 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001328 // SDES is disabled when DTLS is on.
1329 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330}
1331
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001332TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001333 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001334 // SDES is required if DTLS is off.
1335 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001336}
1337
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1339 TestSessionCandidatesWithBundleRtcpMux(false, false);
1340}
1341
1342// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1343// with rtcp-mux and/or bundle.
1344TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1345 TestSessionCandidatesWithBundleRtcpMux(false, true);
1346}
1347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1349 TestSessionCandidatesWithBundleRtcpMux(true, true);
1350}
1351
1352TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001353 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1354 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001355 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 mediastream_signaling_.SendAudioVideoStream1();
1357 InitiateCall();
1358 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1359 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1360 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1361}
1362
1363TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001364 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1365 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001366 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001367 rtc::FP_UDP,
1368 rtc::FD_ANY,
1369 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001370 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 mediastream_signaling_.SendAudioVideoStream1();
1372 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001373 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1375 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1376 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1377}
1378
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001379// Test session delivers no candidates gathered when constraint set to "none".
1380TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1381 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001382 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001383 mediastream_signaling_.SendAudioVideoStream1();
1384 InitiateCall();
1385 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1386 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1387 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1388}
1389
1390// Test session delivers only relay candidates gathered when constaint set to
1391// "relay".
1392TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1393 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1394 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001395 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001396 mediastream_signaling_.SendAudioVideoStream1();
1397 InitiateCall();
1398 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1399 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1400 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1401 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1402 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1403 observer_.mline_0_candidates_[i].type());
1404 }
1405 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1406 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1407 observer_.mline_1_candidates_[i].type());
1408 }
1409}
1410
1411// Test session delivers all candidates gathered when constaint set to "all".
1412TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1413 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001414 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001415 mediastream_signaling_.SendAudioVideoStream1();
1416 InitiateCall();
1417 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1418 // Host + STUN. By default allocator is disabled to gather relay candidates.
1419 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1420 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1421}
1422
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001423TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001424 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001425 SessionDescriptionInterface* offer = NULL;
1426 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1427 std::string unknown_action;
1428 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1429 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1430}
1431
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432// Test creating offers and receive answers and make sure the
1433// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001434TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001435 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001437 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 const std::string session_id_orig = offer->session_id();
1439 const std::string session_version_orig = offer->session_version();
1440 SetLocalDescriptionWithoutError(offer);
1441
1442 mediastream_signaling_.SendAudioVideoStream2();
1443 SessionDescriptionInterface* answer =
1444 CreateRemoteAnswer(session_->local_description());
1445 SetRemoteDescriptionWithoutError(answer);
1446
1447 video_channel_ = media_engine_->GetVideoChannel(0);
1448 voice_channel_ = media_engine_->GetVoiceChannel(0);
1449
1450 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1451 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1452
1453 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1454 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1455
1456 ASSERT_EQ(1u, video_channel_->send_streams().size());
1457 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1458 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1459 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1460
1461 // Create new offer without send streams.
1462 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001463 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464
1465 // Verify the session id is the same and the session version is
1466 // increased.
1467 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001468 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1469 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470
1471 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001472 EXPECT_EQ(0u, video_channel_->send_streams().size());
1473 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474
1475 mediastream_signaling_.SendAudioVideoStream2();
1476 answer = CreateRemoteAnswer(session_->local_description());
1477 SetRemoteDescriptionWithoutError(answer);
1478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479 // Make sure the receive streams have not changed.
1480 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1481 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1482 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1483 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1484}
1485
1486// Test receiving offers and creating answers and make sure the
1487// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001488TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001489 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001491 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001492 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 SetRemoteDescriptionWithoutError(offer);
1494
1495 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001496 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001497 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 SetLocalDescriptionWithoutError(answer);
1499
1500 const std::string session_id_orig = answer->session_id();
1501 const std::string session_version_orig = answer->session_version();
1502
1503 video_channel_ = media_engine_->GetVideoChannel(0);
1504 voice_channel_ = media_engine_->GetVoiceChannel(0);
1505
1506 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1507 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1508
1509 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1510 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1511
1512 ASSERT_EQ(1u, video_channel_->send_streams().size());
1513 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1514 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1515 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1516
1517 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001518 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 SetRemoteDescriptionWithoutError(offer);
1520
1521 // Answer by turning off all send streams.
1522 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001523 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524
1525 // Verify the session id is the same and the session version is
1526 // increased.
1527 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001528 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1529 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 SetLocalDescriptionWithoutError(answer);
1531
1532 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1533 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1534 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1535 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1536 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1537 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1538
1539 // Make sure we have no send streams.
1540 EXPECT_EQ(0u, video_channel_->send_streams().size());
1541 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1542}
1543
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001544TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001545 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001546 media_engine_->set_fail_create_channel(true);
1547
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001548 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001549 ASSERT_TRUE(offer != NULL);
1550 // SetRemoteDescription and SetLocalDescription will take the ownership of
1551 // the offer.
1552 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001553 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001554 ASSERT_TRUE(offer != NULL);
1555 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1556}
1557
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001558//
1559// Tests for creating/setting SDP under different SDES/DTLS polices:
1560//
1561// --DTLS off and SDES on
1562// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1563// set local/remote offer/answer with crypto --> success
1564// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1565// failure
1566// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1567// failure
1568// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1569// failure
1570//
1571// --DTLS on and SDES off
1572// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1573// set local/remote offer/answer with DTLS fingerprint --> success
1574// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1575// fingerprint --> failure
1576// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1577// --> failure
1578// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1579// --> failure
1580//
1581// --Encryption disabled: DTLS off and SDES off
1582// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1583// answer without SDES or DTLS --> success
1584// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1585// answer without SDES or DTLS --> success
1586//
1587
1588// Test that we return a failure when applying a remote/local offer that doesn't
1589// have cryptos enabled when DTLS is off.
1590TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001591 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001593 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 JsepSessionDescription* offer = CreateRemoteOffer(
1595 options, cricket::SEC_DISABLED);
1596 ASSERT_TRUE(offer != NULL);
1597 VerifyNoCryptoParams(offer->description(), false);
1598 // SetRemoteDescription and SetLocalDescription will take the ownership of
1599 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001600 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1602 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604}
1605
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606// Test that we return a failure when applying a local answer that doesn't have
1607// cryptos enabled when DTLS is off.
1608TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001609 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 SessionDescriptionInterface* offer = NULL;
1611 SessionDescriptionInterface* answer = NULL;
1612 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1613 // SetRemoteDescription and SetLocalDescription will take the ownership of
1614 // the offer.
1615 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001616 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617}
1618
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619// Test we will return fail when apply an remote answer that doesn't have
1620// crypto enabled when DTLS is off.
1621TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001622 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 SessionDescriptionInterface* offer = NULL;
1624 SessionDescriptionInterface* answer = NULL;
1625 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1626 // SetRemoteDescription and SetLocalDescription will take the ownership of
1627 // the offer.
1628 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001629 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630}
1631
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001632// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1633// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001634TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001635 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001637 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 SetFactoryDtlsSrtp();
1639 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001640 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641 JsepSessionDescription* offer =
1642 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 ASSERT_TRUE(offer != NULL);
1644 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001645 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646
1647 // SetRemoteDescription will take the ownership of the offer.
1648 SetRemoteDescriptionWithoutError(offer);
1649
1650 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001651 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 ASSERT_TRUE(answer != NULL);
1653 VerifyFingerprintStatus(answer->description(), true);
1654 // Check that we don't have an a=crypto line in the answer.
1655 VerifyNoCryptoParams(answer->description(), true);
1656
1657 // Now set the local description, which should work, even without a=crypto.
1658 SetLocalDescriptionWithoutError(answer);
1659}
1660
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001661// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1662// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001663TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001664 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001665 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001666 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001667 SetFactoryDtlsSrtp();
1668
1669 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001670 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671 ASSERT_TRUE(offer != NULL);
1672 VerifyFingerprintStatus(offer->description(), true);
1673 // Check that we don't have an a=crypto line in the offer.
1674 VerifyNoCryptoParams(offer->description(), true);
1675
1676 // Now set the local description, which should work, even without a=crypto.
1677 SetLocalDescriptionWithoutError(offer);
1678
1679 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001680 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001681 JsepSessionDescription* answer =
1682 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1683 ASSERT_TRUE(answer != NULL);
1684 VerifyFingerprintStatus(answer->description(), true);
1685 VerifyNoCryptoParams(answer->description(), true);
1686
1687 // SetRemoteDescription will take the ownership of the answer.
1688 SetRemoteDescriptionWithoutError(answer);
1689}
1690
1691// Test that if we support DTLS and the other side didn't offer a fingerprint,
1692// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001693TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001694 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001695 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001697 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001698 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 JsepSessionDescription* offer = CreateRemoteOffer(
1700 options, cricket::SEC_REQUIRED);
1701 ASSERT_TRUE(offer != NULL);
1702 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001703 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001705 // SetRemoteDescription will take the ownership of the offer.
1706 SetRemoteDescriptionOfferExpectError(
1707 kSdpWithoutDtlsFingerprint, offer);
1708
1709 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1710 // SetLocalDescription will take the ownership of the offer.
1711 SetLocalDescriptionOfferExpectError(
1712 kSdpWithoutDtlsFingerprint, offer);
1713}
1714
1715// Test that we return a failure when applying a local answer that doesn't have
1716// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001717TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001718 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001719 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720 SessionDescriptionInterface* offer = NULL;
1721 SessionDescriptionInterface* answer = NULL;
1722 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1723
1724 // SetRemoteDescription and SetLocalDescription will take the ownership of
1725 // the offer and answer.
1726 SetRemoteDescriptionWithoutError(offer);
1727 SetLocalDescriptionAnswerExpectError(
1728 kSdpWithoutDtlsFingerprint, answer);
1729}
1730
1731// Test that we return a failure when applying a remote answer that doesn't have
1732// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001733TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001734 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001735 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001738 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001739 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1740 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001742 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743
1744 // SetRemoteDescription and SetLocalDescription will take the ownership of
1745 // the offer and answer.
1746 SetLocalDescriptionWithoutError(offer);
1747 SetRemoteDescriptionAnswerExpectError(
1748 kSdpWithoutDtlsFingerprint, answer);
1749}
1750
1751// Test that we create a local offer without SDES or DTLS and accept a remote
1752// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001753TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 mediastream_signaling_.SendAudioVideoStream1();
1755 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001756 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757
1758 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001759 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760 ASSERT_TRUE(offer != NULL);
1761 VerifyFingerprintStatus(offer->description(), false);
1762 // Check that we don't have an a=crypto line in the offer.
1763 VerifyNoCryptoParams(offer->description(), false);
1764
1765 // Now set the local description, which should work, even without a=crypto.
1766 SetLocalDescriptionWithoutError(offer);
1767
1768 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001769 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770 JsepSessionDescription* answer =
1771 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1772 ASSERT_TRUE(answer != NULL);
1773 VerifyFingerprintStatus(answer->description(), false);
1774 VerifyNoCryptoParams(answer->description(), false);
1775
1776 // SetRemoteDescription will take the ownership of the answer.
1777 SetRemoteDescriptionWithoutError(answer);
1778}
1779
1780// Test that we create a local answer without SDES or DTLS and accept a remote
1781// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001782TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001784 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001785
1786 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001787 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788 JsepSessionDescription* offer =
1789 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1790 ASSERT_TRUE(offer != NULL);
1791 VerifyFingerprintStatus(offer->description(), false);
1792 VerifyNoCryptoParams(offer->description(), false);
1793
1794 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 SetRemoteDescriptionWithoutError(offer);
1796
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001797 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001798 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 ASSERT_TRUE(answer != NULL);
1800 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001801 // Check that we don't have an a=crypto line in the answer.
1802 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 SetLocalDescriptionWithoutError(answer);
1806}
1807
1808TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001809 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 mediastream_signaling_.SendNothing();
1811 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001812 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 SetLocalDescriptionWithoutError(offer);
1814
1815 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001816 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 SetLocalDescriptionWithoutError(offer2);
1818}
1819
1820TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001821 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 mediastream_signaling_.SendNothing();
1823 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001824 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 SetRemoteDescriptionWithoutError(offer);
1826
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001827 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 SetRemoteDescriptionWithoutError(offer2);
1829}
1830
1831TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001832 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001834 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001836 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001837 SetRemoteDescriptionOfferExpectError(
1838 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839}
1840
1841TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001842 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001844 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001846 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001847 SetLocalDescriptionOfferExpectError(
1848 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849}
1850
1851TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001852 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 mediastream_signaling_.SendNothing();
1854 SessionDescriptionInterface* offer = CreateRemoteOffer();
1855 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1856
1857 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001858 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1860 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1861
1862 mediastream_signaling_.SendAudioVideoStream1();
1863 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001864 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1866
1867 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1868
1869 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001870 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1872}
1873
1874TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001875 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001877 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1879
1880 JsepSessionDescription* pranswer =
1881 CreateRemoteAnswer(session_->local_description());
1882 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1883
1884 SetRemoteDescriptionExpectState(pranswer,
1885 BaseSession::STATE_RECEIVEDPRACCEPT);
1886
1887 mediastream_signaling_.SendAudioVideoStream1();
1888 JsepSessionDescription* pranswer2 =
1889 CreateRemoteAnswer(session_->local_description());
1890 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1891
1892 SetRemoteDescriptionExpectState(pranswer2,
1893 BaseSession::STATE_RECEIVEDPRACCEPT);
1894
1895 mediastream_signaling_.SendAudioVideoStream2();
1896 SessionDescriptionInterface* answer =
1897 CreateRemoteAnswer(session_->local_description());
1898 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1899}
1900
1901TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001902 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001904 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 SessionDescriptionInterface* answer =
1907 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001908 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1909 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910}
1911
1912TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001913 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001915 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1916
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 SessionDescriptionInterface* answer =
1918 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001919 SetRemoteDescriptionAnswerExpectError(
1920 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921}
1922
1923TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001924 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 mediastream_signaling_.SendAudioVideoStream1();
1926
1927 cricket::Candidate candidate;
1928 candidate.set_component(1);
1929 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1930
1931 // Fail since we have not set a offer description.
1932 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1933
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001934 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 SetLocalDescriptionWithoutError(offer);
1936 // Candidate should be allowed to add before remote description.
1937 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1938 candidate.set_component(2);
1939 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1940 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1941
1942 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1943 session_->local_description());
1944 SetRemoteDescriptionWithoutError(answer);
1945
1946 // Verifying the candidates are copied properly from internal vector.
1947 const SessionDescriptionInterface* remote_desc =
1948 session_->remote_description();
1949 ASSERT_TRUE(remote_desc != NULL);
1950 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1951 const IceCandidateCollection* candidates =
1952 remote_desc->candidates(kMediaContentIndex0);
1953 ASSERT_EQ(2u, candidates->count());
1954 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1955 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1956 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1957 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1958
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001959 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1960 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 candidate.set_component(2);
1962 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1963 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001964 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
1966 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1967 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1968}
1969
1970// Test that a remote candidate is added to the remote session description and
1971// that it is retained if the remote session description is changed.
1972TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001973 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 cricket::Candidate candidate1;
1975 candidate1.set_component(1);
1976 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1977 candidate1);
1978 mediastream_signaling_.SendAudioVideoStream1();
1979 CreateAndSetRemoteOfferAndLocalAnswer();
1980
1981 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1982 const SessionDescriptionInterface* remote_desc =
1983 session_->remote_description();
1984 ASSERT_TRUE(remote_desc != NULL);
1985 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1986 const IceCandidateCollection* candidates =
1987 remote_desc->candidates(kMediaContentIndex0);
1988 ASSERT_EQ(1u, candidates->count());
1989 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1990
1991 // Update the RemoteSessionDescription with a new session description and
1992 // a candidate and check that the new remote session description contains both
1993 // candidates.
1994 SessionDescriptionInterface* offer = CreateRemoteOffer();
1995 cricket::Candidate candidate2;
1996 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1997 candidate2);
1998 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1999 SetRemoteDescriptionWithoutError(offer);
2000
2001 remote_desc = session_->remote_description();
2002 ASSERT_TRUE(remote_desc != NULL);
2003 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2004 candidates = remote_desc->candidates(kMediaContentIndex0);
2005 ASSERT_EQ(2u, candidates->count());
2006 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2007 // Username and password have be updated with the TransportInfo of the
2008 // SessionDescription, won't be equal to the original one.
2009 candidate2.set_username(candidates->at(0)->candidate().username());
2010 candidate2.set_password(candidates->at(0)->candidate().password());
2011 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2012 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2013 // No need to verify the username and password.
2014 candidate1.set_username(candidates->at(1)->candidate().username());
2015 candidate1.set_password(candidates->at(1)->candidate().password());
2016 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2017
2018 // Test that the candidate is ignored if we can add the same candidate again.
2019 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2020}
2021
2022// Test that local candidates are added to the local session description and
2023// that they are retained if the local session description is changed.
2024TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002025 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002026 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 mediastream_signaling_.SendAudioVideoStream1();
2028 CreateAndSetRemoteOfferAndLocalAnswer();
2029
2030 const SessionDescriptionInterface* local_desc = session_->local_description();
2031 const IceCandidateCollection* candidates =
2032 local_desc->candidates(kMediaContentIndex0);
2033 ASSERT_TRUE(candidates != NULL);
2034 EXPECT_EQ(0u, candidates->count());
2035
2036 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2037
2038 local_desc = session_->local_description();
2039 candidates = local_desc->candidates(kMediaContentIndex0);
2040 ASSERT_TRUE(candidates != NULL);
2041 EXPECT_LT(0u, candidates->count());
2042 candidates = local_desc->candidates(1);
2043 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002044 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045
2046 // Update the session descriptions.
2047 mediastream_signaling_.SendAudioVideoStream1();
2048 CreateAndSetRemoteOfferAndLocalAnswer();
2049
2050 local_desc = session_->local_description();
2051 candidates = local_desc->candidates(kMediaContentIndex0);
2052 ASSERT_TRUE(candidates != NULL);
2053 EXPECT_LT(0u, candidates->count());
2054 candidates = local_desc->candidates(1);
2055 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002056 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057}
2058
2059// Test that we can set a remote session description with remote candidates.
2060TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002061 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062
2063 cricket::Candidate candidate1;
2064 candidate1.set_component(1);
2065 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2066 candidate1);
2067 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002068 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069
2070 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2071 SetRemoteDescriptionWithoutError(offer);
2072
2073 const SessionDescriptionInterface* remote_desc =
2074 session_->remote_description();
2075 ASSERT_TRUE(remote_desc != NULL);
2076 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2077 const IceCandidateCollection* candidates =
2078 remote_desc->candidates(kMediaContentIndex0);
2079 ASSERT_EQ(1u, candidates->count());
2080 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2081
wu@webrtc.org91053e72013-08-10 07:18:04 +00002082 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 SetLocalDescriptionWithoutError(answer);
2084}
2085
2086// Test that offers and answers contains ice candidates when Ice candidates have
2087// been gathered.
2088TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002089 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002090 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 mediastream_signaling_.SendAudioVideoStream1();
2092 // Ice is started but candidates are not provided until SetLocalDescription
2093 // is called.
2094 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2095 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2096 CreateAndSetRemoteOfferAndLocalAnswer();
2097 // Wait until at least one local candidate has been collected.
2098 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2099 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2104 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105
2106 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2107 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002108 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2110 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 SetLocalDescriptionWithoutError(answer);
2112}
2113
2114// Verifies TransportProxy and media channels are created with content names
2115// present in the SessionDescription.
2116TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002117 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002119 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120
2121 // CreateOffer creates session description with the content names "audio" and
2122 // "video". Goal is to modify these content names and verify transport channel
2123 // proxy in the BaseSession, as proxies are created with the content names
2124 // present in SDP.
2125 std::string sdp;
2126 EXPECT_TRUE(offer->ToString(&sdp));
2127 const std::string kAudioMid = "a=mid:audio";
2128 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2129 const std::string kVideoMid = "a=mid:video";
2130 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2131
2132 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002133 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 kAudioMidReplaceStr.c_str(),
2135 kAudioMidReplaceStr.length(),
2136 &sdp);
2137 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002138 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 kVideoMidReplaceStr.c_str(),
2140 kVideoMidReplaceStr.length(),
2141 &sdp);
2142
2143 SessionDescriptionInterface* modified_offer =
2144 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2145
2146 SetRemoteDescriptionWithoutError(modified_offer);
2147
2148 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002149 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 SetLocalDescriptionWithoutError(answer);
2151
deadbeefcbecd352015-09-23 11:50:27 -07002152 cricket::TransportChannel* voice_transport_channel =
2153 session_->voice_rtp_transport_channel();
2154 EXPECT_TRUE(voice_transport_channel != NULL);
2155 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2156 cricket::TransportChannel* video_transport_channel =
2157 session_->video_rtp_transport_channel();
2158 EXPECT_TRUE(video_transport_channel != NULL);
2159 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2161 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2162}
2163
2164// Test that an offer contains the correct media content descriptions based on
2165// the send streams when no constraints have been set.
2166TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002167 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002168 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 ASSERT_TRUE(offer != NULL);
2171 const cricket::ContentInfo* content =
2172 cricket::GetFirstAudioContent(offer->description());
2173 EXPECT_TRUE(content != NULL);
2174 content = cricket::GetFirstVideoContent(offer->description());
2175 EXPECT_TRUE(content == NULL);
2176}
2177
2178// Test that an offer contains the correct media content descriptions based on
2179// the send streams when no constraints have been set.
2180TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002181 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 // Test Audio only offer.
2183 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002184 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 const cricket::ContentInfo* content =
2187 cricket::GetFirstAudioContent(offer->description());
2188 EXPECT_TRUE(content != NULL);
2189 content = cricket::GetFirstVideoContent(offer->description());
2190 EXPECT_TRUE(content == NULL);
2191
2192 // Test Audio / Video offer.
2193 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002194 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 content = cricket::GetFirstAudioContent(offer->description());
2196 EXPECT_TRUE(content != NULL);
2197 content = cricket::GetFirstVideoContent(offer->description());
2198 EXPECT_TRUE(content != NULL);
2199}
2200
2201// Test that an offer contains no media content descriptions if
2202// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2203TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002204 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002205 PeerConnectionInterface::RTCOfferAnswerOptions options;
2206 options.offer_to_receive_audio = 0;
2207 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002209 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002210 CreateOffer(options));
2211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 ASSERT_TRUE(offer != NULL);
2213 const cricket::ContentInfo* content =
2214 cricket::GetFirstAudioContent(offer->description());
2215 EXPECT_TRUE(content == NULL);
2216 content = cricket::GetFirstVideoContent(offer->description());
2217 EXPECT_TRUE(content == NULL);
2218}
2219
2220// Test that an offer contains only audio media content descriptions if
2221// kOfferToReceiveAudio constraints are set to true.
2222TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002223 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002224 PeerConnectionInterface::RTCOfferAnswerOptions options;
2225 options.offer_to_receive_audio =
2226 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2227
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002228 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002229 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230
2231 const cricket::ContentInfo* content =
2232 cricket::GetFirstAudioContent(offer->description());
2233 EXPECT_TRUE(content != NULL);
2234 content = cricket::GetFirstVideoContent(offer->description());
2235 EXPECT_TRUE(content == NULL);
2236}
2237
2238// Test that an offer contains audio and video media content descriptions if
2239// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2240TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002241 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002243 PeerConnectionInterface::RTCOfferAnswerOptions options;
2244 options.offer_to_receive_audio =
2245 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2246 options.offer_to_receive_video =
2247 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2248
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002249 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002250 CreateOffer(options));
2251
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 const cricket::ContentInfo* content =
2253 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002254 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 content = cricket::GetFirstVideoContent(offer->description());
2257 EXPECT_TRUE(content != NULL);
2258
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002259 // Sets constraints to false and verifies that audio/video contents are
2260 // removed.
2261 options.offer_to_receive_audio = 0;
2262 options.offer_to_receive_video = 0;
2263 offer.reset(CreateOffer(options));
2264
2265 content = cricket::GetFirstAudioContent(offer->description());
2266 EXPECT_TRUE(content == NULL);
2267 content = cricket::GetFirstVideoContent(offer->description());
2268 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269}
2270
2271// Test that an answer can not be created if the last remote description is not
2272// an offer.
2273TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002274 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002275 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 SetLocalDescriptionWithoutError(offer);
2277 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2278 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002279 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280}
2281
2282// Test that an answer contains the correct media content descriptions when no
2283// constraints have been set.
2284TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002285 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002287 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002289 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002290 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 const cricket::ContentInfo* content =
2292 cricket::GetFirstAudioContent(answer->description());
2293 ASSERT_TRUE(content != NULL);
2294 EXPECT_FALSE(content->rejected);
2295
2296 content = cricket::GetFirstVideoContent(answer->description());
2297 ASSERT_TRUE(content != NULL);
2298 EXPECT_FALSE(content->rejected);
2299}
2300
2301// Test that an answer contains the correct media content descriptions when no
2302// constraints have been set and the offer only contain audio.
2303TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 // Create a remote offer with audio only.
2306 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002307
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002308 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 CreateRemoteOffer(options));
2310 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2311 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2312
2313 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002314 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002315 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 const cricket::ContentInfo* content =
2317 cricket::GetFirstAudioContent(answer->description());
2318 ASSERT_TRUE(content != NULL);
2319 EXPECT_FALSE(content->rejected);
2320
2321 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2322}
2323
2324// Test that an answer contains the correct media content descriptions when no
2325// constraints have been set.
2326TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002327 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002329 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 SetRemoteDescriptionWithoutError(offer.release());
2331 // Test with a stream with tracks.
2332 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002333 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002334 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 const cricket::ContentInfo* content =
2336 cricket::GetFirstAudioContent(answer->description());
2337 ASSERT_TRUE(content != NULL);
2338 EXPECT_FALSE(content->rejected);
2339
2340 content = cricket::GetFirstVideoContent(answer->description());
2341 ASSERT_TRUE(content != NULL);
2342 EXPECT_FALSE(content->rejected);
2343}
2344
2345// Test that an answer contains the correct media content descriptions when
2346// constraints have been set but no stream is sent.
2347TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002348 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002350 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 SetRemoteDescriptionWithoutError(offer.release());
2352
2353 webrtc::FakeConstraints constraints_no_receive;
2354 constraints_no_receive.SetMandatoryReceiveAudio(false);
2355 constraints_no_receive.SetMandatoryReceiveVideo(false);
2356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002357 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002358 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 const cricket::ContentInfo* content =
2360 cricket::GetFirstAudioContent(answer->description());
2361 ASSERT_TRUE(content != NULL);
2362 EXPECT_TRUE(content->rejected);
2363
2364 content = cricket::GetFirstVideoContent(answer->description());
2365 ASSERT_TRUE(content != NULL);
2366 EXPECT_TRUE(content->rejected);
2367}
2368
2369// Test that an answer contains the correct media content descriptions when
2370// constraints have been set and streams are sent.
2371TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002372 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002374 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 SetRemoteDescriptionWithoutError(offer.release());
2376
2377 webrtc::FakeConstraints constraints_no_receive;
2378 constraints_no_receive.SetMandatoryReceiveAudio(false);
2379 constraints_no_receive.SetMandatoryReceiveVideo(false);
2380
2381 // Test with a stream with tracks.
2382 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002383 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002384 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385
2386 // TODO(perkj): Should the direction be set to SEND_ONLY?
2387 const cricket::ContentInfo* content =
2388 cricket::GetFirstAudioContent(answer->description());
2389 ASSERT_TRUE(content != NULL);
2390 EXPECT_FALSE(content->rejected);
2391
2392 // TODO(perkj): Should the direction be set to SEND_ONLY?
2393 content = cricket::GetFirstVideoContent(answer->description());
2394 ASSERT_TRUE(content != NULL);
2395 EXPECT_FALSE(content->rejected);
2396}
2397
2398TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2399 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002400 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002401 PeerConnectionInterface::RTCOfferAnswerOptions options;
2402 options.offer_to_receive_audio =
2403 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2404 options.voice_activity_detection = false;
2405
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002406 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002407 CreateOffer(options));
2408
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 const cricket::ContentInfo* content =
2410 cricket::GetFirstAudioContent(offer->description());
2411 EXPECT_TRUE(content != NULL);
2412 EXPECT_TRUE(VerifyNoCNCodecs(content));
2413}
2414
2415TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2416 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002417 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002419 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 SetRemoteDescriptionWithoutError(offer.release());
2421
2422 webrtc::FakeConstraints constraints;
2423 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002424 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002425 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 const cricket::ContentInfo* content =
2427 cricket::GetFirstAudioContent(answer->description());
2428 ASSERT_TRUE(content != NULL);
2429 EXPECT_TRUE(VerifyNoCNCodecs(content));
2430}
2431
2432// This test verifies the call setup when remote answer with audio only and
2433// later updates with video.
2434TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002435 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2437 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2438
2439 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002440 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441
2442 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2444
2445 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2446 // and answer;
2447 SetLocalDescriptionWithoutError(offer);
2448 SetRemoteDescriptionWithoutError(answer);
2449
2450 video_channel_ = media_engine_->GetVideoChannel(0);
2451 voice_channel_ = media_engine_->GetVoiceChannel(0);
2452
2453 ASSERT_TRUE(video_channel_ == NULL);
2454
2455 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2456 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2457 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2458
2459 // Let the remote end update the session descriptions, with Audio and Video.
2460 mediastream_signaling_.SendAudioVideoStream2();
2461 CreateAndSetRemoteOfferAndLocalAnswer();
2462
2463 video_channel_ = media_engine_->GetVideoChannel(0);
2464 voice_channel_ = media_engine_->GetVoiceChannel(0);
2465
2466 ASSERT_TRUE(video_channel_ != NULL);
2467 ASSERT_TRUE(voice_channel_ != NULL);
2468
2469 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2470 ASSERT_EQ(1u, video_channel_->send_streams().size());
2471 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2472 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2473 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2474 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2475 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2476 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2477
2478 // Change session back to audio only.
2479 mediastream_signaling_.UseOptionsAudioOnly();
2480 CreateAndSetRemoteOfferAndLocalAnswer();
2481
2482 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2483 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2484 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2485 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2486 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2487}
2488
2489// This test verifies the call setup when remote answer with video only and
2490// later updates with audio.
2491TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2494 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2495 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002496 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497
2498 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002499 options.recv_audio = false;
2500 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2502 offer, options, cricket::SEC_ENABLED);
2503
2504 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2505 // and answer.
2506 SetLocalDescriptionWithoutError(offer);
2507 SetRemoteDescriptionWithoutError(answer);
2508
2509 video_channel_ = media_engine_->GetVideoChannel(0);
2510 voice_channel_ = media_engine_->GetVoiceChannel(0);
2511
2512 ASSERT_TRUE(voice_channel_ == NULL);
2513 ASSERT_TRUE(video_channel_ != NULL);
2514
2515 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2516 ASSERT_EQ(1u, video_channel_->send_streams().size());
2517 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2518
2519 // Update the session descriptions, with Audio and Video.
2520 mediastream_signaling_.SendAudioVideoStream2();
2521 CreateAndSetRemoteOfferAndLocalAnswer();
2522
2523 voice_channel_ = media_engine_->GetVoiceChannel(0);
2524 ASSERT_TRUE(voice_channel_ != NULL);
2525
2526 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2527 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2528 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2529 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2530
2531 // Change session back to video only.
2532 mediastream_signaling_.UseOptionsVideoOnly();
2533 CreateAndSetRemoteOfferAndLocalAnswer();
2534
2535 video_channel_ = media_engine_->GetVideoChannel(0);
2536 voice_channel_ = media_engine_->GetVoiceChannel(0);
2537
2538 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2539 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2540 ASSERT_EQ(1u, video_channel_->send_streams().size());
2541 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2542}
2543
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002547 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 VerifyCryptoParams(offer->description());
2549 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002550 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 VerifyCryptoParams(answer->description());
2552}
2553
2554TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002555 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002556 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002558 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 VerifyNoCryptoParams(offer->description(), false);
2560}
2561
2562TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002563 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 VerifyAnswerFromNonCryptoOffer();
2565}
2566
2567TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002568 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 VerifyAnswerFromCryptoOffer();
2570}
2571
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002572// This test verifies that setLocalDescription fails if
2573// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2574TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002575 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002576 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002577 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2578
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002579 std::string sdp;
2580 RemoveIceUfragPwdLines(offer.get(), &sdp);
2581 SessionDescriptionInterface* modified_offer =
2582 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002583 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002584}
2585
2586// This test verifies that setRemoteDescription fails if
2587// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2588TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002589 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002590 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002591 std::string sdp;
2592 RemoveIceUfragPwdLines(offer.get(), &sdp);
2593 SessionDescriptionInterface* modified_offer =
2594 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002595 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002596}
2597
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002598// This test verifies that setLocalDescription fails if local offer has
2599// too short ice ufrag and pwd strings.
2600TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002601 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002602 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002603 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2604
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002605 std::string sdp;
2606 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2607 // recommended values of 4 and 22 bytes respectively.
2608 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2609 SessionDescriptionInterface* modified_offer =
2610 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2611 std::string error;
2612 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2613
2614 // Test with string greater than 256.
2615 sdp.clear();
2616 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2617 &sdp);
2618 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2619 NULL);
2620 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2621}
2622
2623// This test verifies that setRemoteDescription fails if remote offer has
2624// too short ice ufrag and pwd strings.
2625TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002626 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002627 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002628 std::string sdp;
2629 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2630 // recommended values of 4 and 22 bytes respectively.
2631 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2632 SessionDescriptionInterface* modified_offer =
2633 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2634 std::string error;
2635 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2636
2637 sdp.clear();
2638 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2639 &sdp);
2640 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2641 NULL);
2642 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2643}
2644
honghaiz503726c2015-07-31 12:37:38 -07002645// Test that if the remote description indicates the peer requested ICE restart
2646// (via a new ufrag or pwd), the old ICE candidates are not copied,
2647// and vice versa.
2648TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2649 Init();
2650 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2651
2652 // Create the first offer.
2653 std::string sdp;
2654 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2655 "abcdefghijklmnopqrstuvwx", &sdp);
2656 SessionDescriptionInterface* offer1 =
2657 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2658 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2659 0, "", "", "relay", 0, "");
2660 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2661 candidate1);
2662 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2663 SetRemoteDescriptionWithoutError(offer1);
2664 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2665
2666 // The second offer has the same ufrag and pwd but different address.
2667 sdp.clear();
2668 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2669 "abcdefghijklmnopqrstuvwx", &sdp);
2670 SessionDescriptionInterface* offer2 =
2671 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2672 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2673 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2674 candidate1);
2675 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2676 SetRemoteDescriptionWithoutError(offer2);
2677 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2678
2679 // The third offer has a different ufrag and different address.
2680 sdp.clear();
2681 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2682 "abcdefghijklmnopqrstuvwx", &sdp);
2683 SessionDescriptionInterface* offer3 =
2684 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2685 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2686 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2687 candidate1);
2688 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2689 SetRemoteDescriptionWithoutError(offer3);
2690 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2691
2692 // The fourth offer has no candidate but a different ufrag/pwd.
2693 sdp.clear();
2694 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2695 "abcdefghijklmnopqrstuvyz", &sdp);
2696 SessionDescriptionInterface* offer4 =
2697 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2698 SetRemoteDescriptionWithoutError(offer4);
2699 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2700}
2701
Donald Curtisd4f769d2015-05-28 09:48:21 -07002702// Test that candidates sent to the "video" transport do not get pushed down to
2703// the "audio" transport channel when bundling using TransportProxy.
2704TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2705 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2706
2707 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2708 mediastream_signaling_.SendAudioVideoStream1();
2709
2710 PeerConnectionInterface::RTCOfferAnswerOptions options;
2711 options.use_rtp_mux = true;
2712
2713 SessionDescriptionInterface* offer = CreateRemoteOffer();
2714 SetRemoteDescriptionWithoutError(offer);
2715
2716 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2717 SetLocalDescriptionWithoutError(answer);
2718
deadbeefcbecd352015-09-23 11:50:27 -07002719 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2720 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002721
deadbeefcbecd352015-09-23 11:50:27 -07002722 cricket::BaseChannel* voice_channel = session_->voice_channel();
2723 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002724
2725 // Checks if one of the transport channels contains a connection using a given
2726 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002727 auto connection_with_remote_port = [this, voice_channel](int port) {
2728 cricket::SessionStats stats;
2729 session_->GetChannelTransportStats(voice_channel, &stats);
2730 for (auto& kv : stats.transport_stats) {
2731 for (auto& chan_stat : kv.second.channel_stats) {
2732 for (auto& conn_info : chan_stat.connection_infos) {
2733 if (conn_info.remote_candidate.address().port() == port) {
2734 return true;
2735 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002736 }
2737 }
2738 }
2739 return false;
2740 };
2741
2742 EXPECT_FALSE(connection_with_remote_port(5000));
2743 EXPECT_FALSE(connection_with_remote_port(5001));
2744 EXPECT_FALSE(connection_with_remote_port(6000));
2745
2746 // The way the *_WAIT checks work is they only wait if the condition fails,
2747 // which does not help in the case where state is not changing. This is
2748 // problematic in this test since we want to verify that adding a video
2749 // candidate does _not_ change state. So we interleave candidates and assume
2750 // that messages are executed in the order they were posted.
2751
2752 // First audio candidate.
2753 cricket::Candidate candidate0;
2754 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2755 candidate0.set_component(1);
2756 candidate0.set_protocol("udp");
2757 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2758 candidate0);
2759 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2760
2761 // Video candidate.
2762 cricket::Candidate candidate1;
2763 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2764 candidate1.set_component(1);
2765 candidate1.set_protocol("udp");
2766 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2767 candidate1);
2768 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2769
2770 // Second audio candidate.
2771 cricket::Candidate candidate2;
2772 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2773 candidate2.set_component(1);
2774 candidate2.set_protocol("udp");
2775 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2776 candidate2);
2777 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2778
2779 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2780 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2781
2782 // No need here for a _WAIT check since we are checking that state hasn't
2783 // changed: if this is false we would be doing waits for nothing and if this
2784 // is true then there will be no messages processed anyways.
2785 EXPECT_FALSE(connection_with_remote_port(6000));
2786}
2787
deadbeefcbecd352015-09-23 11:50:27 -07002788// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002789TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2790 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002792
2793 PeerConnectionInterface::RTCOfferAnswerOptions options;
2794 options.use_rtp_mux = true;
2795
2796 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002798
deadbeefcbecd352015-09-23 11:50:27 -07002799 EXPECT_NE(session_->voice_rtp_transport_channel(),
2800 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002801
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002803 SessionDescriptionInterface* answer =
2804 CreateRemoteAnswer(session_->local_description());
2805 SetRemoteDescriptionWithoutError(answer);
2806
deadbeefcbecd352015-09-23 11:50:27 -07002807 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2808 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002809}
2810
deadbeefcbecd352015-09-23 11:50:27 -07002811// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002812TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2813 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2814 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002815
Donald Curtis0e209b02015-03-24 09:29:54 -07002816 PeerConnectionInterface::RTCOfferAnswerOptions options;
2817 options.use_rtp_mux = true;
2818
2819 SessionDescriptionInterface* offer = CreateOffer(options);
2820 SetLocalDescriptionWithoutError(offer);
2821
deadbeefcbecd352015-09-23 11:50:27 -07002822 EXPECT_NE(session_->voice_rtp_transport_channel(),
2823 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002824
2825 mediastream_signaling_.SendAudioVideoStream2();
2826
2827 // Remove BUNDLE from the answer.
2828 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2829 CreateRemoteAnswer(session_->local_description()));
2830 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2831 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2832 JsepSessionDescription* modified_answer =
2833 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2834 modified_answer->Initialize(answer_copy, "1", "1");
2835 SetRemoteDescriptionWithoutError(modified_answer); //
2836
deadbeefcbecd352015-09-23 11:50:27 -07002837 EXPECT_NE(session_->voice_rtp_transport_channel(),
2838 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002839}
2840
2841// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2842TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2843 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2844 mediastream_signaling_.SendAudioVideoStream1();
2845
2846 PeerConnectionInterface::RTCOfferAnswerOptions options;
2847 options.use_rtp_mux = true;
2848
2849 SessionDescriptionInterface* offer = CreateOffer(options);
2850 SetLocalDescriptionWithoutError(offer);
2851
deadbeefcbecd352015-09-23 11:50:27 -07002852 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2853 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002854
2855 mediastream_signaling_.SendAudioVideoStream2();
2856 SessionDescriptionInterface* answer =
2857 CreateRemoteAnswer(session_->local_description());
2858 SetRemoteDescriptionWithoutError(answer);
2859
deadbeefcbecd352015-09-23 11:50:27 -07002860 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2861 session_->video_rtp_transport_channel());
2862}
2863
2864// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
2865// audio content in the answer.
2866TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
2867 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2868 mediastream_signaling_.SendAudioVideoStream1();
2869
2870 PeerConnectionInterface::RTCOfferAnswerOptions options;
2871 options.use_rtp_mux = true;
2872
2873 SessionDescriptionInterface* offer = CreateOffer(options);
2874 SetLocalDescriptionWithoutError(offer);
2875
2876 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2877 session_->video_rtp_transport_channel());
2878
2879 mediastream_signaling_.SendAudioVideoStream2();
2880 cricket::MediaSessionOptions recv_options;
2881 recv_options.recv_audio = false;
2882 recv_options.recv_video = true;
2883 SessionDescriptionInterface* answer =
2884 CreateRemoteAnswer(session_->local_description(), recv_options);
2885 SetRemoteDescriptionWithoutError(answer);
2886
2887 EXPECT_TRUE(NULL == session_->voice_channel());
2888 EXPECT_TRUE(NULL != session_->video_rtp_transport_channel());
2889
2890 session_->Terminate();
2891 EXPECT_TRUE(NULL == session_->voice_rtp_transport_channel());
2892 EXPECT_TRUE(NULL == session_->voice_rtcp_transport_channel());
2893 EXPECT_TRUE(NULL == session_->video_rtp_transport_channel());
2894 EXPECT_TRUE(NULL == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002895}
2896
2897// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2898TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2899 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2900 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002901
Donald Curtis0e209b02015-03-24 09:29:54 -07002902 PeerConnectionInterface::RTCOfferAnswerOptions options;
2903 options.use_rtp_mux = true;
2904
2905 SessionDescriptionInterface* offer = CreateOffer(options);
2906 SetLocalDescriptionWithoutError(offer);
2907
deadbeefcbecd352015-09-23 11:50:27 -07002908 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2909 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002910
2911 mediastream_signaling_.SendAudioVideoStream2();
2912
2913 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002914 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 CreateRemoteAnswer(session_->local_description()));
2916 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2917 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2918 JsepSessionDescription* modified_answer =
2919 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2920 modified_answer->Initialize(answer_copy, "1", "1");
2921 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002922
deadbeefcbecd352015-09-23 11:50:27 -07002923 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2924 session_->video_rtp_transport_channel());
2925}
2926
2927// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
2928TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
2929 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2930 mediastream_signaling_.SendAudioVideoStream1();
2931
2932 SessionDescriptionInterface* offer = CreateRemoteOffer();
2933 SetRemoteDescriptionWithoutError(offer);
2934
2935 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2936 session_->video_rtp_transport_channel());
2937
2938 mediastream_signaling_.SendAudioVideoStream2();
2939 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
2940 SetLocalDescriptionWithoutError(answer);
2941
2942 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2943 session_->video_rtp_transport_channel());
2944}
2945
2946// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
2947TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
2948 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2949 mediastream_signaling_.SendAudioVideoStream1();
2950
2951 // Remove BUNDLE from the offer.
2952 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2953 cricket::SessionDescription* offer_copy = offer->description()->Copy();
2954 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2955 JsepSessionDescription* modified_offer =
2956 new JsepSessionDescription(JsepSessionDescription::kOffer);
2957 modified_offer->Initialize(offer_copy, "1", "1");
2958
2959 // Expect an error when applying the remote description
2960 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
2961 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002962}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963
Peter Thatcher4eddf182015-04-30 10:55:59 -07002964// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002965TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2966 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2967 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968
Donald Curtis0e209b02015-03-24 09:29:54 -07002969 PeerConnectionInterface::RTCOfferAnswerOptions options;
2970 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971
Donald Curtis0e209b02015-03-24 09:29:54 -07002972 SessionDescriptionInterface* offer = CreateOffer(options);
2973 SetLocalDescriptionWithoutError(offer);
2974
deadbeefcbecd352015-09-23 11:50:27 -07002975 EXPECT_NE(session_->voice_rtp_transport_channel(),
2976 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002977
2978 mediastream_signaling_.SendAudioVideoStream2();
2979 SessionDescriptionInterface* answer =
2980 CreateRemoteAnswer(session_->local_description());
2981 SetRemoteDescriptionWithoutError(answer);
2982
2983 // This should lead to an audio-only call but isn't implemented
2984 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07002985 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2986 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002987}
2988
deadbeefcbecd352015-09-23 11:50:27 -07002989// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002990TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2991 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2992 mediastream_signaling_.SendAudioVideoStream1();
2993 PeerConnectionInterface::RTCOfferAnswerOptions options;
2994 options.use_rtp_mux = true;
2995
2996 SessionDescriptionInterface* offer = CreateOffer(options);
2997 SetLocalDescriptionWithoutError(offer);
2998
deadbeefcbecd352015-09-23 11:50:27 -07002999 EXPECT_NE(session_->voice_rtp_transport_channel(),
3000 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003001
3002 mediastream_signaling_.SendAudioVideoStream2();
3003
3004 // Remove BUNDLE from the answer.
3005 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3006 CreateRemoteAnswer(session_->local_description()));
3007 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3008 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3009 JsepSessionDescription* modified_answer =
3010 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3011 modified_answer->Initialize(answer_copy, "1", "1");
3012 SetRemoteDescriptionWithoutError(modified_answer); //
3013
deadbeefcbecd352015-09-23 11:50:27 -07003014 EXPECT_NE(session_->voice_rtp_transport_channel(),
3015 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016}
3017
Peter Thatcher4eddf182015-04-30 10:55:59 -07003018// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3019TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3020 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
3021 mediastream_signaling_.SendAudioVideoStream1();
3022
3023 PeerConnectionInterface::RTCOfferAnswerOptions options;
3024 options.use_rtp_mux = true;
3025
3026 SessionDescriptionInterface* offer = CreateOffer(options);
3027 SetRemoteDescriptionWithoutError(offer);
3028
deadbeefcbecd352015-09-23 11:50:27 -07003029 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3030 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003031}
3032
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003033TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3034 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
3035 mediastream_signaling_.SendAudioVideoStream1();
3036
3037 PeerConnectionInterface::RTCOfferAnswerOptions options;
3038 SessionDescriptionInterface* offer = CreateOffer(options);
3039 SetLocalDescriptionWithoutError(offer);
3040
deadbeefcbecd352015-09-23 11:50:27 -07003041 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3042 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003043
3044 mediastream_signaling_.SendAudioVideoStream2();
3045 SessionDescriptionInterface* answer =
3046 CreateRemoteAnswer(session_->local_description());
3047 SetRemoteDescriptionWithoutError(answer);
3048
deadbeefcbecd352015-09-23 11:50:27 -07003049 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3050 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003051}
3052
3053TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3054 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
3055 mediastream_signaling_.SendAudioVideoStream1();
3056
3057 PeerConnectionInterface::RTCOfferAnswerOptions options;
3058 SessionDescriptionInterface* offer = CreateOffer(options);
3059 SetLocalDescriptionWithoutError(offer);
3060
deadbeefcbecd352015-09-23 11:50:27 -07003061 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3062 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003063
3064 mediastream_signaling_.SendAudioVideoStream2();
3065 SessionDescriptionInterface* answer =
3066 CreateRemoteAnswer(session_->local_description());
3067 SetRemoteDescriptionWithoutError(answer);
3068
deadbeefcbecd352015-09-23 11:50:27 -07003069 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3070 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003071}
3072
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003073// This test verifies that SetLocalDescription and SetRemoteDescription fails
3074// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3075TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003076 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003077 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003078
3079 PeerConnectionInterface::RTCOfferAnswerOptions options;
3080 options.use_rtp_mux = true;
3081
3082 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003083 std::string offer_str;
3084 offer->ToString(&offer_str);
3085 // Disable rtcp-mux
3086 const std::string rtcp_mux = "rtcp-mux";
3087 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003088 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003089 xrtcp_mux.c_str(), xrtcp_mux.length(),
3090 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003091 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003092 new JsepSessionDescription(JsepSessionDescription::kOffer);
3093 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003094 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003095 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003096 new JsepSessionDescription(JsepSessionDescription::kOffer);
3097 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003098 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003099 // Trying unmodified SDP.
3100 SetLocalDescriptionWithoutError(offer);
3101}
3102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003104 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105 mediastream_signaling_.SendAudioVideoStream1();
3106 CreateAndSetRemoteOfferAndLocalAnswer();
3107 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3108 ASSERT_TRUE(channel != NULL);
3109 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003110 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111 double left_vol, right_vol;
3112 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3113 EXPECT_EQ(1, left_vol);
3114 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003115 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003116 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3118 EXPECT_EQ(0, left_vol);
3119 EXPECT_EQ(0, right_vol);
torbjorngeefbc3b2015-10-08 13:10:36 -07003120 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003121 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003122 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3123 EXPECT_EQ(1, left_vol);
3124 EXPECT_EQ(1, right_vol);
torbjorngeefbc3b2015-10-08 13:10:36 -07003125 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126}
3127
3128TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003129 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130 mediastream_signaling_.SendAudioVideoStream1();
3131 CreateAndSetRemoteOfferAndLocalAnswer();
3132 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3133 ASSERT_TRUE(channel != NULL);
3134 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003135 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3137
3138 cricket::AudioOptions options;
3139 options.echo_cancellation.Set(true);
3140
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003141 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003142 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3144 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
torbjorngeefbc3b2015-10-08 13:10:36 -07003145 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003146 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003148 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003149 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3151 bool value;
3152 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3153 EXPECT_TRUE(value);
torbjorngeefbc3b2015-10-08 13:10:36 -07003154 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003155 EXPECT_TRUE(renderer->sink() == NULL);
3156}
3157
3158TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003159 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003160 mediastream_signaling_.SendAudioVideoStream1();
3161 CreateAndSetRemoteOfferAndLocalAnswer();
3162 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3163 ASSERT_TRUE(channel != NULL);
3164 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003165 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003166
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003167 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003168 cricket::AudioOptions options;
3169 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3170 EXPECT_TRUE(renderer->sink() != NULL);
3171
3172 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3173 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3174 // SetSink(NULL) callback afterwards.
3175 renderer.reset();
3176
3177 // This will trigger SetSink(NULL) if no OnClose() callback.
3178 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179}
3180
3181TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003182 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183 mediastream_signaling_.SendAudioVideoStream1();
3184 CreateAndSetRemoteOfferAndLocalAnswer();
3185 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3186 ASSERT_TRUE(channel != NULL);
3187 ASSERT_LT(0u, channel->renderers().size());
3188 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3189 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003190 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003191 cricket::FakeVideoRenderer renderer;
3192 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3193 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3194 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3195 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3196}
3197
3198TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003199 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003200 mediastream_signaling_.SendAudioVideoStream1();
3201 CreateAndSetRemoteOfferAndLocalAnswer();
3202 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3203 ASSERT_TRUE(channel != NULL);
3204 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003205 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3207 cricket::VideoOptions* options = NULL;
3208 session_->SetVideoSend(send_ssrc, false, options);
3209 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3210 session_->SetVideoSend(send_ssrc, true, options);
3211 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3212}
3213
3214TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3215 TestCanInsertDtmf(false);
3216}
3217
3218TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3219 TestCanInsertDtmf(true);
3220}
3221
3222TEST_F(WebRtcSessionTest, InsertDtmf) {
3223 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003224 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003225 mediastream_signaling_.SendAudioVideoStream1();
3226 CreateAndSetRemoteOfferAndLocalAnswer();
3227 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3228 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3229
3230 // Insert DTMF
3231 const int expected_flags = DF_SEND;
3232 const int expected_duration = 90;
3233 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3234 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3235 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3236
3237 // Verify
3238 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003239 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3241 expected_duration, expected_flags));
3242 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3243 expected_duration, expected_flags));
3244 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3245 expected_duration, expected_flags));
3246}
3247
3248// This test verifies the |initiator| flag when session initiates the call.
3249TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003250 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003252 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3254 SetLocalDescriptionWithoutError(offer);
3255 EXPECT_TRUE(session_->initiator());
3256 SetRemoteDescriptionWithoutError(answer);
3257 EXPECT_TRUE(session_->initiator());
3258}
3259
3260// This test verifies the |initiator| flag when session receives the call.
3261TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003262 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 EXPECT_FALSE(session_->initiator());
3264 SessionDescriptionInterface* offer = CreateRemoteOffer();
3265 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003266 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267
3268 EXPECT_FALSE(session_->initiator());
3269 SetLocalDescriptionWithoutError(answer);
3270 EXPECT_FALSE(session_->initiator());
3271}
3272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3274TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003275 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003277 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003278 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003279 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280 CreateRemoteAnswer(session_->local_description()));
3281
3282 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3283 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003284 JsepSessionDescription* modified_answer =
3285 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286
3287 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3288 answer->session_id(),
3289 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003290 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
wu@webrtc.org4e393072014-04-07 17:04:35 +00003292 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293 std::string sdp;
3294 EXPECT_TRUE(answer->ToString(&sdp));
3295 const std::string kAudioMid = "a=mid:audio";
3296 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003297 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298 kAudioMidReplaceStr.c_str(),
3299 kAudioMidReplaceStr.length(),
3300 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003301 SessionDescriptionInterface* modified_answer1 =
3302 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003303 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304
wu@webrtc.org4e393072014-04-07 17:04:35 +00003305 // Different media types.
3306 EXPECT_TRUE(answer->ToString(&sdp));
3307 const std::string kAudioMline = "m=audio";
3308 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003310 kAudioMlineReplaceStr.c_str(),
3311 kAudioMlineReplaceStr.length(),
3312 &sdp);
3313 SessionDescriptionInterface* modified_answer2 =
3314 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3315 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317 SetRemoteDescriptionWithoutError(answer.release());
3318}
3319
3320// Verifying remote offer and local answer have matching m-lines as per
3321// RFC 3264.
3322TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003323 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324 mediastream_signaling_.SendAudioVideoStream1();
3325 SessionDescriptionInterface* offer = CreateRemoteOffer();
3326 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003327 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328
3329 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3330 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003331 JsepSessionDescription* modified_answer =
3332 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333
3334 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3335 answer->session_id(),
3336 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003337 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 SetLocalDescriptionWithoutError(answer);
3339}
3340
3341// This test verifies that WebRtcSession does not start candidate allocation
3342// before SetLocalDescription is called.
3343TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003344 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 mediastream_signaling_.SendAudioVideoStream1();
3346 SessionDescriptionInterface* offer = CreateRemoteOffer();
3347 cricket::Candidate candidate;
3348 candidate.set_component(1);
3349 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3350 candidate);
3351 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3352 cricket::Candidate candidate1;
3353 candidate1.set_component(1);
3354 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3355 candidate1);
3356 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3357 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003358 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3359 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360
3361 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003362 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003363 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3364 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3365
wu@webrtc.org91053e72013-08-10 07:18:04 +00003366 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3369}
3370
3371// This test verifies that crypto parameter is updated in local session
3372// description as per security policy set in MediaSessionDescriptionFactory.
3373TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003374 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003376 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377
3378 // Making sure SetLocalDescription correctly sets crypto value in
3379 // SessionDescription object after de-serialization of sdp string. The value
3380 // will be set as per MediaSessionDescriptionFactory.
3381 std::string offer_str;
3382 offer->ToString(&offer_str);
3383 SessionDescriptionInterface* jsep_offer_str =
3384 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3385 SetLocalDescriptionWithoutError(jsep_offer_str);
3386 EXPECT_TRUE(session_->voice_channel()->secure_required());
3387 EXPECT_TRUE(session_->video_channel()->secure_required());
3388}
3389
3390// This test verifies the crypto parameter when security is disabled.
3391TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003392 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003393 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003395 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396
3397 // Making sure SetLocalDescription correctly sets crypto value in
3398 // SessionDescription object after de-serialization of sdp string. The value
3399 // will be set as per MediaSessionDescriptionFactory.
3400 std::string offer_str;
3401 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003402 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3404 SetLocalDescriptionWithoutError(jsep_offer_str);
3405 EXPECT_FALSE(session_->voice_channel()->secure_required());
3406 EXPECT_FALSE(session_->video_channel()->secure_required());
3407}
3408
3409// This test verifies that an answer contains new ufrag and password if an offer
3410// with new ufrag and password is received.
3411TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003412 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003414 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003415 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 CreateRemoteOffer(options));
3417 SetRemoteDescriptionWithoutError(offer.release());
3418
3419 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003420 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003421 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 SetLocalDescriptionWithoutError(answer.release());
3423
3424 // Receive an offer with new ufrag and password.
3425 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003426 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003427 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 SetRemoteDescriptionWithoutError(updated_offer1.release());
3429
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003430 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003431 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432
3433 CompareIceUfragAndPassword(updated_answer1->description(),
3434 session_->local_description()->description(),
3435 false);
3436
3437 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003438}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439
wu@webrtc.org91053e72013-08-10 07:18:04 +00003440// This test verifies that an answer contains old ufrag and password if an offer
3441// with old ufrag and password is received.
3442TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003443 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003444 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003445 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003446 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003447 CreateRemoteOffer(options));
3448 SetRemoteDescriptionWithoutError(offer.release());
3449
3450 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003451 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003452 CreateAnswer(NULL));
3453 SetLocalDescriptionWithoutError(answer.release());
3454
3455 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003457 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003458 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 SetRemoteDescriptionWithoutError(updated_offer2.release());
3460
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003461 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003462 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463
3464 CompareIceUfragAndPassword(updated_answer2->description(),
3465 session_->local_description()->description(),
3466 true);
3467
3468 SetLocalDescriptionWithoutError(updated_answer2.release());
3469}
3470
3471TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003472 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003474 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475 const std::string session_id_orig = offer->session_id();
3476 const std::string session_version_orig = offer->session_version();
3477 SetLocalDescriptionWithoutError(offer);
3478
3479 video_channel_ = media_engine_->GetVideoChannel(0);
3480 video_channel_->set_fail_set_send_codecs(true);
3481
3482 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003483 SessionDescriptionInterface* answer =
3484 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003485 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486}
3487
3488// Runs the loopback call test with BUNDLE and STUN disabled.
3489TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3490 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003491 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003492 cricket::PORTALLOCATOR_DISABLE_STUN |
3493 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 TestLoopbackCall();
3495}
3496
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003497TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003498 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003499 cricket::PORTALLOCATOR_DISABLE_STUN |
3500 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3501 cricket::PORTALLOCATOR_DISABLE_RELAY);
3502
3503 // best connection is IPv6 since it has higher network preference.
3504 LoopbackNetworkConfiguration config;
3505 config.test_ipv6_network_ = true;
3506 config.best_connection_after_initial_ice_converged_ =
3507 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3508
3509 TestLoopbackCall(config);
3510}
3511
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003512// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003513TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003514 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3515 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003516 TestLoopbackCall();
3517}
3518
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003519TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003520 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003522 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003524 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3525 std::string error_code_str = "ERROR_CONTENT";
3526 std::string error_desc = "Fake session error description.";
3527 session_->SetError(error_code, error_desc);
3528
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3530 SessionDescriptionInterface* answer =
3531 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003532
3533 std::string action;
3534 std::ostringstream session_error_msg;
3535 session_error_msg << kSessionError << error_code_str << ". ";
3536 session_error_msg << kSessionErrorDesc << error_desc << ".";
3537 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3538 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539}
3540
3541TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3542 constraints_.reset(new FakeConstraints());
3543 constraints_->AddOptional(
3544 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003545 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546
3547 SetLocalDescriptionWithDataChannel();
3548 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3549}
3550
Henrik Boström87713d02015-08-25 09:53:21 +02003551TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003552 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553
3554 constraints_.reset(new FakeConstraints());
3555 constraints_->AddOptional(
3556 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003557 options_.disable_sctp_data_channels = false;
3558
Henrik Boström87713d02015-08-25 09:53:21 +02003559 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560
3561 SetLocalDescriptionWithDataChannel();
3562 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3563}
3564
Henrik Boström87713d02015-08-25 09:53:21 +02003565TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003566 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003567
Henrik Boström87713d02015-08-25 09:53:21 +02003568 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003569
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003570 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003571 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003572 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3573}
3574
Henrik Boström87713d02015-08-25 09:53:21 +02003575TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003576 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003577 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003578 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003579
3580 // Create remote offer with SCTP.
3581 cricket::MediaSessionOptions options;
3582 options.data_channel_type = cricket::DCT_SCTP;
3583 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003584 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003585 SetRemoteDescriptionWithoutError(offer);
3586
3587 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003588 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003589 EXPECT_TRUE(answer != NULL);
3590 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3591 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003592}
3593
Henrik Boström87713d02015-08-25 09:53:21 +02003594TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595 constraints_.reset(new FakeConstraints());
3596 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003597 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003598 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599
3600 SetLocalDescriptionWithDataChannel();
3601 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3602}
3603
Henrik Boström87713d02015-08-25 09:53:21 +02003604TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003605 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606
Henrik Boström87713d02015-08-25 09:53:21 +02003607 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608
3609 SetLocalDescriptionWithDataChannel();
3610 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3611}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003612
Henrik Boström87713d02015-08-25 09:53:21 +02003613TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003614 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003615 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003616 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003617
3618 SetLocalDescriptionWithDataChannel();
3619 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3620}
3621
Henrik Boström87713d02015-08-25 09:53:21 +02003622TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003623 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003624 const int new_send_port = 9998;
3625 const int new_recv_port = 7775;
3626
Henrik Boström87713d02015-08-25 09:53:21 +02003627 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003628 SetFactoryDtlsSrtp();
3629
3630 // By default, don't actually add the codecs to desc_factory_; they don't
3631 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3632 // let the session description get parsed. That'll get the proper codecs
3633 // into the stream.
3634 cricket::MediaSessionOptions options;
3635 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3636 "stream1", new_send_port, options);
3637
3638 // SetRemoteDescription will take the ownership of the offer.
3639 SetRemoteDescriptionWithoutError(offer);
3640
3641 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3642 new_recv_port, CreateAnswer(NULL));
3643 ASSERT_TRUE(answer != NULL);
3644
3645 // Now set the local description, which'll take ownership of the answer.
3646 SetLocalDescriptionWithoutError(answer);
3647
3648 // TEST PLAN: Set the port number to something new, set it in the SDP,
3649 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003650 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003651 dci.reliable = true;
3652 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003653 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003654 session_->CreateDataChannel("datachannel", &dci);
3655
3656 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3657 int portnum = -1;
3658 ASSERT_TRUE(ch != NULL);
3659 ASSERT_EQ(1UL, ch->send_codecs().size());
3660 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003661 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003662 ch->send_codecs()[0].name.c_str()));
3663 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3664 &portnum));
3665 EXPECT_EQ(new_send_port, portnum);
3666
3667 ASSERT_EQ(1UL, ch->recv_codecs().size());
3668 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003669 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003670 ch->recv_codecs()[0].name.c_str()));
3671 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3672 &portnum));
3673 EXPECT_EQ(new_recv_port, portnum);
3674}
3675
Henrik Boströmd8281982015-08-27 10:12:24 +02003676TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3677 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3678 FakeDtlsIdentityStore::GenerateCertificate();
3679
3680 PeerConnectionInterface::RTCConfiguration configuration;
3681 configuration.certificates.push_back(certificate);
3682 Init(nullptr, configuration);
3683 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3684
3685 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3686}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003687
Henrik Boström87713d02015-08-25 09:53:21 +02003688// Verifies that CreateOffer succeeds when CreateOffer is called before async
3689// identity generation is finished (even if a certificate is provided this is
3690// an async op).
3691TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3692 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3693 InitWithDtls(GetParam());
3694
Henrik Boströmd8281982015-08-27 10:12:24 +02003695 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003696 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003697 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3698
wu@webrtc.org91053e72013-08-10 07:18:04 +00003699 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003700 VerifyNoCryptoParams(offer->description(), true);
3701 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003702}
3703
3704// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003705// identity generation is finished (even if a certificate is provided this is
3706// an async op).
3707TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003708 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003709 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003710 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003711
3712 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003713 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003714 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003715 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003716 ASSERT_TRUE(offer.get() != NULL);
3717 SetRemoteDescriptionWithoutError(offer.release());
3718
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003719 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003720 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003721 VerifyNoCryptoParams(answer->description(), true);
3722 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003723}
3724
3725// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003726// identity generation is finished (even if a certificate is provided this is
3727// an async op).
3728TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003729 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003730 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003731
Henrik Boströmd8281982015-08-27 10:12:24 +02003732 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003733
3734 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735 EXPECT_TRUE(offer != NULL);
3736}
3737
3738// Verifies that CreateOffer fails when CreateOffer is called after async
3739// identity generation fails.
3740TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003741 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003742 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003743
Henrik Boströmd8281982015-08-27 10:12:24 +02003744 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003745
3746 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003747 EXPECT_TRUE(offer == NULL);
3748}
3749
3750// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3751// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003752TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003753 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003754 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003755 VerifyMultipleAsyncCreateDescription(GetParam(),
3756 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003757}
3758
3759// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3760// before async identity generation fails.
3761TEST_F(WebRtcSessionTest,
3762 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003763 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003764 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3765 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003766}
3767
3768// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3769// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003770TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003771 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003772 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003773 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003774 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003775}
3776
3777// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3778// before async identity generation fails.
3779TEST_F(WebRtcSessionTest,
3780 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003781 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003782 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3783 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003784}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003785
3786// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3787// offer has no SDES crypto but only DTLS fingerprint.
3788TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3789 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003790 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003791 // Create a remote offer with secured transport disabled.
3792 cricket::MediaSessionOptions options;
3793 JsepSessionDescription* offer(CreateRemoteOffer(
3794 options, cricket::SEC_DISABLED));
3795 // Adds a DTLS fingerprint to the remote offer.
3796 cricket::SessionDescription* sdp = offer->description();
3797 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3798 ASSERT_TRUE(audio != NULL);
3799 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3800 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003801 rtc::SSLFingerprint::CreateFromRfc4572(
3802 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003803 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003804 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003805}
3806
wu@webrtc.orgde305012013-10-31 15:40:38 +00003807// This test verifies DSCP is properly applied on the media channels.
3808TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3809 constraints_.reset(new FakeConstraints());
3810 constraints_->AddOptional(
3811 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003812 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003813 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003814 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003815
3816 SetLocalDescriptionWithoutError(offer);
3817
3818 video_channel_ = media_engine_->GetVideoChannel(0);
3819 voice_channel_ = media_engine_->GetVoiceChannel(0);
3820
3821 ASSERT_TRUE(video_channel_ != NULL);
3822 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003823 const cricket::AudioOptions& audio_options = voice_channel_->options();
3824 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003825 EXPECT_TRUE(audio_options.dscp.IsSet());
3826 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3827 EXPECT_TRUE(video_options.dscp.IsSet());
3828 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3829}
3830
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003831TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3832 constraints_.reset(new FakeConstraints());
3833 constraints_->AddOptional(
3834 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3835 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003836 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003837 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003838 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003839
3840 SetLocalDescriptionWithoutError(offer);
3841
3842 video_channel_ = media_engine_->GetVideoChannel(0);
3843
3844 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003845 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003846 EXPECT_TRUE(
3847 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3848}
3849
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003850TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3851 // Number of unsignalled receiving streams should be between 0 and
3852 // kMaxUnsignalledRecvStreams.
3853 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3854 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3855 kMaxUnsignalledRecvStreams);
3856 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3857}
3858
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003859TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3860 constraints_.reset(new FakeConstraints());
3861 constraints_->AddOptional(
3862 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3863 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003864 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003865 mediastream_signaling_.SendAudioVideoStream1();
3866 SessionDescriptionInterface* offer = CreateOffer();
3867
3868 SetLocalDescriptionWithoutError(offer);
3869
3870 voice_channel_ = media_engine_->GetVoiceChannel(0);
3871
3872 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003873 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003874 EXPECT_TRUE(
3875 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3876}
3877
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003878// Tests that we can renegotiate new media content with ICE candidates in the
3879// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003880TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003881 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003882 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003883 SetFactoryDtlsSrtp();
3884
3885 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003886 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003887 SetLocalDescriptionWithoutError(offer);
3888
3889 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3890 SetRemoteDescriptionWithoutError(answer);
3891
3892 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003893 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003894 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3895
3896 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003897 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003898 candidate1.set_component(1);
3899 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3900 candidate1);
3901 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3902 SetRemoteDescriptionWithoutError(offer);
3903
3904 answer = CreateAnswer(NULL);
3905 SetLocalDescriptionWithoutError(answer);
3906}
3907
3908// Tests that we can renegotiate new media content with ICE candidates separated
3909// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003910TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003911 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003912 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003913 SetFactoryDtlsSrtp();
3914
3915 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003916 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003917 SetLocalDescriptionWithoutError(offer);
3918
3919 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3920 SetRemoteDescriptionWithoutError(answer);
3921
3922 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003923 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003924 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3925 SetRemoteDescriptionWithoutError(offer);
3926
3927 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003928 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003929 candidate1.set_component(1);
3930 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3931 candidate1);
3932 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3933
3934 answer = CreateAnswer(NULL);
3935 SetLocalDescriptionWithoutError(answer);
3936}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003937// Tests that RTX codec is removed from the answer when it isn't supported
3938// by local side.
3939TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3940 Init();
3941 mediastream_signaling_.SendAudioVideoStream1();
3942 std::string offer_sdp(kSdpWithRtx);
3943
3944 SessionDescriptionInterface* offer =
3945 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3946 EXPECT_TRUE(offer->ToString(&offer_sdp));
3947
3948 // Offer SDP contains the RTX codec.
3949 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3950 SetRemoteDescriptionWithoutError(offer);
3951
3952 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3953 std::string answer_sdp;
3954 answer->ToString(&answer_sdp);
3955 // Answer SDP removes the unsupported RTX codec.
3956 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3957 SetLocalDescriptionWithoutError(answer);
3958}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003959
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003960// This verifies that the voice channel after bundle has both options from video
3961// and voice channels.
3962TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3963 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3964 mediastream_signaling_.SendAudioVideoStream1();
3965
3966 PeerConnectionInterface::RTCOfferAnswerOptions options;
3967 options.use_rtp_mux = true;
3968
3969 SessionDescriptionInterface* offer = CreateOffer(options);
3970 SetLocalDescriptionWithoutError(offer);
3971
3972 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3973 rtc::Socket::Option::OPT_SNDBUF, 4000);
3974
3975 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3976 rtc::Socket::Option::OPT_RCVBUF, 8000);
3977
3978 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07003979 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003980 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3981 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003982 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003983 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3984
deadbeefcbecd352015-09-23 11:50:27 -07003985 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003986 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3987 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003988 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003989 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3990
deadbeefcbecd352015-09-23 11:50:27 -07003991 EXPECT_NE(session_->voice_rtp_transport_channel(),
3992 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003993
3994 mediastream_signaling_.SendAudioVideoStream2();
3995 SessionDescriptionInterface* answer =
3996 CreateRemoteAnswer(session_->local_description());
3997 SetRemoteDescriptionWithoutError(answer);
3998
deadbeefcbecd352015-09-23 11:50:27 -07003999 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004000 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4001 EXPECT_EQ(4000, option_val);
4002
deadbeefcbecd352015-09-23 11:50:27 -07004003 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004004 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4005 EXPECT_EQ(8000, option_val);
4006}
4007
tommi0f620f42015-07-09 03:25:02 -07004008// Test creating a session, request multiple offers, destroy the session
4009// and make sure we got success/failure callbacks for all of the requests.
4010// Background: crbug.com/507307
4011TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4012 Init();
4013
4014 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4015 PeerConnectionInterface::RTCOfferAnswerOptions options;
4016 options.offer_to_receive_audio =
4017 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
4018
4019 for (auto& o : observers) {
4020 o = new WebRtcSessionCreateSDPObserverForTest();
4021 session_->CreateOffer(o, options);
4022 }
4023
4024 session_.reset();
4025
tommi0f620f42015-07-09 03:25:02 -07004026 for (auto& o : observers) {
4027 // We expect to have received a notification now even if the session was
4028 // terminated. The offer creation may or may not have succeeded, but we
4029 // must have received a notification which, so the only invalid state
4030 // is kInit.
4031 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4032 }
4033}
4034
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004035// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4036// currently fails because upon disconnection and reconnection OnIceComplete is
4037// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004038
deadbeefcbecd352015-09-23 11:50:27 -07004039INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4040 WebRtcSessionTest,
4041 testing::Values(ALREADY_GENERATED,
4042 DTLS_IDENTITY_STORE));