blob: e8624761e9e699bfbb3c15faca6eaa6676ace626 [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:
solenberg98c68862015-10-09 03:27:14 -0700333 FakeAudioRenderer() : 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
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000339 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000340
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000341 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000342 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000343 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000344};
345
Henrik Boström87713d02015-08-25 09:53:21 +0200346class WebRtcSessionTest
347 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 protected:
349 // TODO Investigate why ChannelManager crashes, if it's created
350 // after stun_server.
351 WebRtcSessionTest()
352 : media_engine_(new cricket::FakeMediaEngine()),
353 data_engine_(new cricket::FakeDataEngine()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 channel_manager_(new cricket::ChannelManager(
solenbergfacbbec2015-09-24 00:41:50 -0700355 media_engine_, data_engine_, new cricket::CaptureManager(),
356 rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 tdesc_factory_(new cricket::TransportDescriptionFactory()),
358 desc_factory_(new cricket::MediaSessionDescriptionFactory(
359 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000360 pss_(new rtc::PhysicalSocketServer),
361 vss_(new rtc::VirtualSocketServer(pss_.get())),
362 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000364 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000365 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000366 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
367 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000368 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700369 mediastream_signaling_(channel_manager_.get()),
370 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000371 cricket::ServerAddresses stun_servers;
372 stun_servers.insert(stun_socket_addr_);
373 allocator_.reset(new cricket::BasicPortAllocator(
374 &network_manager_,
375 stun_servers,
376 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000377 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700378 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 EXPECT_TRUE(channel_manager_->Init());
380 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000381 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 }
383
384 void AddInterface(const SocketAddress& addr) {
385 network_manager_.AddInterface(addr);
386 }
387
Henrik Boström87713d02015-08-25 09:53:21 +0200388 // If |dtls_identity_store| != null or |rtc_configuration| contains
389 // |certificates| then DTLS will be enabled unless explicitly disabled by
390 // |rtc_configuration| options. When DTLS is enabled a certificate will be
391 // used if provided, otherwise one will be generated using the
392 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000393 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200394 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200395 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 ASSERT_TRUE(session_.get() == NULL);
397 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000398 channel_manager_.get(), rtc::Thread::Current(),
399 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 &observer_,
401 &mediastream_signaling_));
402
403 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
404 observer_.ice_connection_state_);
405 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
406 observer_.ice_gathering_state_);
407
deadbeefcbecd352015-09-23 11:50:27 -0700408 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
409 dtls_identity_store.Pass(),
410 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700411 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 }
413
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200415 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200416 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000417 }
418
419 void InitWithIceTransport(
420 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200421 PeerConnectionInterface::RTCConfiguration configuration;
422 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200423 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000424 }
425
426 void InitWithBundlePolicy(
427 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200428 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200429 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200430 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700431 }
432
433 void InitWithRtcpMuxPolicy(
434 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
435 PeerConnectionInterface::RTCConfiguration configuration;
436 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200437 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000438 }
439
Henrik Boström87713d02015-08-25 09:53:21 +0200440 // Successfully init with DTLS; with a certificate generated and supplied or
441 // with a store that generates it for us.
442 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
443 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
444 PeerConnectionInterface::RTCConfiguration configuration;
445 if (cert_gen_method == ALREADY_GENERATED) {
446 configuration.certificates.push_back(
447 FakeDtlsIdentityStore::GenerateCertificate());
448 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
449 dtls_identity_store.reset(new FakeDtlsIdentityStore());
450 dtls_identity_store->set_should_fail(false);
451 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700452 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200453 }
454 Init(dtls_identity_store.Pass(), configuration);
455 }
456
457 // Init with DTLS with a store that will fail to generate a certificate.
458 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200459 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
460 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200461 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200462 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200463 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000464 }
465
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 void InitWithDtmfCodec() {
467 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000468 const cricket::AudioCodec kTelephoneEventCodec(
469 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 std::vector<cricket::AudioCodec> codecs;
471 codecs.push_back(kTelephoneEventCodec);
472 media_engine_->SetAudioCodecs(codecs);
473 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000474 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 }
476
477 // Creates a local offer and applies it. Starts ice.
478 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
479 // to decide which streams to create.
480 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000481 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 SetLocalDescriptionWithoutError(offer);
483 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
484 observer_.ice_gathering_state_,
485 kIceCandidatesTimeout);
486 }
487
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000488 SessionDescriptionInterface* CreateOffer() {
489 PeerConnectionInterface::RTCOfferAnswerOptions options;
490 options.offer_to_receive_audio =
491 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
492
493 return CreateOffer(options);
494 }
495
wu@webrtc.org91053e72013-08-10 07:18:04 +0000496 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000497 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000498 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000499 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000500 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000501 EXPECT_TRUE_WAIT(
502 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000503 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000504 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000505 }
506
507 SessionDescriptionInterface* CreateAnswer(
508 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000509 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000510 = new WebRtcSessionCreateSDPObserverForTest();
511 session_->CreateAnswer(observer, constraints);
512 EXPECT_TRUE_WAIT(
513 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000514 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000515 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000516 }
517
wu@webrtc.org364f2042013-11-20 21:49:41 +0000518 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 return (session_->voice_channel() != NULL &&
520 session_->video_channel() != NULL);
521 }
522
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
524 ASSERT_TRUE(session_.get() != NULL);
525 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
526 ASSERT_TRUE(content != NULL);
527 const cricket::AudioContentDescription* audio_content =
528 static_cast<const cricket::AudioContentDescription*>(
529 content->description);
530 ASSERT_TRUE(audio_content != NULL);
531 ASSERT_EQ(1U, audio_content->cryptos().size());
532 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
533 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
534 audio_content->cryptos()[0].cipher_suite);
535 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
536 audio_content->protocol());
537
538 content = cricket::GetFirstVideoContent(sdp);
539 ASSERT_TRUE(content != NULL);
540 const cricket::VideoContentDescription* video_content =
541 static_cast<const cricket::VideoContentDescription*>(
542 content->description);
543 ASSERT_TRUE(video_content != NULL);
544 ASSERT_EQ(1U, video_content->cryptos().size());
545 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
546 video_content->cryptos()[0].cipher_suite);
547 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
548 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
549 video_content->protocol());
550 }
551
552 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
553 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
554 ASSERT_TRUE(content != NULL);
555 const cricket::AudioContentDescription* audio_content =
556 static_cast<const cricket::AudioContentDescription*>(
557 content->description);
558 ASSERT_TRUE(audio_content != NULL);
559 ASSERT_EQ(0U, audio_content->cryptos().size());
560
561 content = cricket::GetFirstVideoContent(sdp);
562 ASSERT_TRUE(content != NULL);
563 const cricket::VideoContentDescription* video_content =
564 static_cast<const cricket::VideoContentDescription*>(
565 content->description);
566 ASSERT_TRUE(video_content != NULL);
567 ASSERT_EQ(0U, video_content->cryptos().size());
568
569 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700570 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700572 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 video_content->protocol());
574 } else {
575 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
576 audio_content->protocol());
577 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
578 video_content->protocol());
579 }
580 }
581
582 // Set the internal fake description factories to do DTLS-SRTP.
583 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000584 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000586 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200587 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200588 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
torbjorng335204c2015-10-08 02:30:14 -0700589 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
590 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
592 }
593
594 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
595 bool expected) {
596 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
597 ASSERT_TRUE(audio != NULL);
598 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 const TransportInfo* video = sdp->GetTransportInfoByName("video");
600 ASSERT_TRUE(video != NULL);
601 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 }
603
604 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000605 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000607 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000608 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000610 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000612 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
613 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000614 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 // Answer should be NULL as no crypto params in offer.
616 ASSERT_TRUE(answer == NULL);
617 }
618
619 void VerifyAnswerFromCryptoOffer() {
620 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000621 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 options.bundle_enabled = true;
623 scoped_ptr<JsepSessionDescription> offer(
624 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
625 ASSERT_TRUE(offer.get() != NULL);
626 VerifyCryptoParams(offer->description());
627 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000628 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 ASSERT_TRUE(answer.get() != NULL);
630 VerifyCryptoParams(answer->description());
631 }
632
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000633 void SetAndVerifyNumUnsignalledRecvStreams(
634 int value_set, int value_expected) {
635 constraints_.reset(new FakeConstraints());
636 constraints_->AddOptional(
637 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
638 value_set);
639 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000640 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000641 mediastream_signaling_.SendAudioVideoStream1();
642 SessionDescriptionInterface* offer = CreateOffer();
643
644 SetLocalDescriptionWithoutError(offer);
645
646 video_channel_ = media_engine_->GetVideoChannel(0);
647
648 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700649 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000650 EXPECT_EQ(value_expected,
651 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
652 }
653
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
655 const cricket::SessionDescription* desc2,
656 bool expect_equal) {
657 if (desc1->contents().size() != desc2->contents().size()) {
658 EXPECT_FALSE(expect_equal);
659 return;
660 }
661
662 const cricket::ContentInfos& contents = desc1->contents();
663 cricket::ContentInfos::const_iterator it = contents.begin();
664
665 for (; it != contents.end(); ++it) {
666 const cricket::TransportDescription* transport_desc1 =
667 desc1->GetTransportDescriptionByName(it->name);
668 const cricket::TransportDescription* transport_desc2 =
669 desc2->GetTransportDescriptionByName(it->name);
670 if (!transport_desc1 || !transport_desc2) {
671 EXPECT_FALSE(expect_equal);
672 return;
673 }
674 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
675 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
676 EXPECT_FALSE(expect_equal);
677 return;
678 }
679 }
680 EXPECT_TRUE(expect_equal);
681 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000682
683 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
684 std::string *sdp) {
685 const cricket::SessionDescription* desc = current_desc->description();
686 EXPECT_TRUE(current_desc->ToString(sdp));
687
688 const cricket::ContentInfos& contents = desc->contents();
689 cricket::ContentInfos::const_iterator it = contents.begin();
690 // Replace ufrag and pwd lines with empty strings.
691 for (; it != contents.end(); ++it) {
692 const cricket::TransportDescription* transport_desc =
693 desc->GetTransportDescriptionByName(it->name);
694 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
695 + "\r\n";
696 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
697 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000698 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000699 "", 0,
700 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000701 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000702 "", 0,
703 sdp);
704 }
705 }
706
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000707 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
708 const std::string& modified_ice_ufrag,
709 const std::string& modified_ice_pwd,
710 std::string* sdp) {
711 const cricket::SessionDescription* desc = current_desc->description();
712 EXPECT_TRUE(current_desc->ToString(sdp));
713
714 const cricket::ContentInfos& contents = desc->contents();
715 cricket::ContentInfos::const_iterator it = contents.begin();
716 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
717 // |modified_ice_pwd| strings.
718 for (; it != contents.end(); ++it) {
719 const cricket::TransportDescription* transport_desc =
720 desc->GetTransportDescriptionByName(it->name);
721 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
722 + "\r\n";
723 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
724 + "\r\n";
725 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
726 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000727 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000728 mod_ufrag.c_str(), mod_ufrag.length(),
729 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000730 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000731 mod_pwd.c_str(), mod_pwd.length(),
732 sdp);
733 }
734 }
735
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 // Creates a remote offer and and applies it as a remote description,
737 // creates a local answer and applies is as a local description.
738 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
739 // to decide which local and remote streams to create.
740 void CreateAndSetRemoteOfferAndLocalAnswer() {
741 SessionDescriptionInterface* offer = CreateRemoteOffer();
742 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000743 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 SetLocalDescriptionWithoutError(answer);
745 }
746 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
747 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700748 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 }
750 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
751 BaseSession::State expected_state) {
752 SetLocalDescriptionWithoutError(desc);
753 EXPECT_EQ(expected_state, session_->state());
754 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000755 void SetLocalDescriptionExpectError(const std::string& action,
756 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 SessionDescriptionInterface* desc) {
758 std::string error;
759 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000760 std::string sdp_type = "local ";
761 sdp_type.append(action);
762 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 EXPECT_NE(std::string::npos, error.find(expected_error));
764 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
766 SessionDescriptionInterface* desc) {
767 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
768 expected_error, desc);
769 }
770 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
771 SessionDescriptionInterface* desc) {
772 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
773 expected_error, desc);
774 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
776 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
777 }
778 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
779 BaseSession::State expected_state) {
780 SetRemoteDescriptionWithoutError(desc);
781 EXPECT_EQ(expected_state, session_->state());
782 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000783 void SetRemoteDescriptionExpectError(const std::string& action,
784 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 SessionDescriptionInterface* desc) {
786 std::string error;
787 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000788 std::string sdp_type = "remote ";
789 sdp_type.append(action);
790 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 EXPECT_NE(std::string::npos, error.find(expected_error));
792 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 void SetRemoteDescriptionOfferExpectError(
794 const std::string& expected_error, SessionDescriptionInterface* desc) {
795 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
796 expected_error, desc);
797 }
798 void SetRemoteDescriptionPranswerExpectError(
799 const std::string& expected_error, SessionDescriptionInterface* desc) {
800 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
801 expected_error, desc);
802 }
803 void SetRemoteDescriptionAnswerExpectError(
804 const std::string& expected_error, SessionDescriptionInterface* desc) {
805 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
806 expected_error, desc);
807 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808
809 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
810 SessionDescriptionInterface** nocrypto_answer) {
811 // Create a SDP without Crypto.
812 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000813 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 options.bundle_enabled = true;
815 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
816 ASSERT_TRUE(*offer != NULL);
817 VerifyCryptoParams((*offer)->description());
818
819 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
820 cricket::SEC_DISABLED);
821 EXPECT_TRUE(*nocrypto_answer != NULL);
822 }
823
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000824 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
825 SessionDescriptionInterface** nodtls_answer) {
826 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000827 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000828 options.bundle_enabled = true;
829
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000830 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000831 CreateRemoteOffer(options, cricket::SEC_ENABLED));
832
833 *nodtls_answer =
834 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
835 EXPECT_TRUE(*nodtls_answer != NULL);
836 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
837 VerifyCryptoParams((*nodtls_answer)->description());
838
839 SetFactoryDtlsSrtp();
840 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
841 ASSERT_TRUE(*offer != NULL);
842 VerifyFingerprintStatus((*offer)->description(), true);
843 VerifyCryptoParams((*offer)->description());
844 }
845
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 JsepSessionDescription* CreateRemoteOfferWithVersion(
847 cricket::MediaSessionOptions options,
848 cricket::SecurePolicy secure_policy,
849 const std::string& session_version,
850 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 const cricket::SessionDescription* cricket_desc = NULL;
853 if (current_desc) {
854 cricket_desc = current_desc->description();
855 session_id = current_desc->session_id();
856 }
857
858 desc_factory_->set_secure(secure_policy);
859 JsepSessionDescription* offer(
860 new JsepSessionDescription(JsepSessionDescription::kOffer));
861 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
862 session_id, session_version)) {
863 delete offer;
864 offer = NULL;
865 }
866 return offer;
867 }
868 JsepSessionDescription* CreateRemoteOffer(
869 cricket::MediaSessionOptions options) {
870 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
871 kSessionVersion, NULL);
872 }
873 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000874 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
875 return CreateRemoteOfferWithVersion(
876 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 }
878 JsepSessionDescription* CreateRemoteOffer(
879 cricket::MediaSessionOptions options,
880 const SessionDescriptionInterface* current_desc) {
881 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
882 kSessionVersion, current_desc);
883 }
884
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000885 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
886 const char* sctp_stream_name, int new_port,
887 cricket::MediaSessionOptions options) {
888 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000889 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
890 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000891 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
892 }
893
894 // Takes ownership of offer_basis (and deletes it).
895 JsepSessionDescription* ChangeSDPSctpPort(
896 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
897 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
898 // SessionDescription from the mutated string.
899 const char* default_port_str = "5000";
900 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000901 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000902 std::string offer_str;
903 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000904 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000905 new_port_str, strlen(new_port_str),
906 &offer_str);
907 JsepSessionDescription* offer = new JsepSessionDescription(
908 offer_basis->type());
909 delete offer_basis;
910 offer->Initialize(offer_str, NULL);
911 return offer;
912 }
913
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
915 // before this function to decide which streams to create.
916 JsepSessionDescription* CreateRemoteOffer() {
917 cricket::MediaSessionOptions options;
918 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
919 return CreateRemoteOffer(options, session_->remote_description());
920 }
921
922 JsepSessionDescription* CreateRemoteAnswer(
923 const SessionDescriptionInterface* offer,
924 cricket::MediaSessionOptions options,
925 cricket::SecurePolicy policy) {
926 desc_factory_->set_secure(policy);
927 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000928 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 JsepSessionDescription* answer(
930 new JsepSessionDescription(JsepSessionDescription::kAnswer));
931 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
932 options, NULL),
933 session_id, kSessionVersion)) {
934 delete answer;
935 answer = NULL;
936 }
937 return answer;
938 }
939
940 JsepSessionDescription* CreateRemoteAnswer(
941 const SessionDescriptionInterface* offer,
942 cricket::MediaSessionOptions options) {
943 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
944 }
945
946 // Creates an answer session description with streams based on
947 // |mediastream_signaling_|. Call
948 // mediastream_signaling_.UseOptionsWithStreamX() before this function
949 // to decide which streams to create.
950 JsepSessionDescription* CreateRemoteAnswer(
951 const SessionDescriptionInterface* offer) {
952 cricket::MediaSessionOptions options;
953 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
954 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
955 }
956
957 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000958 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000959 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000961
962 PeerConnectionInterface::RTCOfferAnswerOptions options;
963 options.use_rtp_mux = bundle;
964
965 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
967 // and answer.
968 SetLocalDescriptionWithoutError(offer);
969
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000970 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000971 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 std::string sdp;
973 EXPECT_TRUE(answer->ToString(&sdp));
974
975 size_t expected_candidate_num = 2;
976 if (!rtcp_mux) {
977 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
978 // for rtp and rtcp.
979 expected_candidate_num = 4;
980 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 const std::string kRtcpMux = "a=rtcp-mux";
982 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000983 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 kXRtcpMux.c_str(), kXRtcpMux.length(),
985 &sdp);
986 }
987
988 SessionDescriptionInterface* new_answer = CreateSessionDescription(
989 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990
991 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000992 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
994 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -0700995 if (bundle) {
996 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
997 } else {
998 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 }
1000 }
1001 // Tests that we can only send DTMF when the dtmf codec is supported.
1002 void TestCanInsertDtmf(bool can) {
1003 if (can) {
1004 InitWithDtmfCodec();
1005 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001006 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 }
1008 mediastream_signaling_.SendAudioVideoStream1();
1009 CreateAndSetRemoteOfferAndLocalAnswer();
1010 EXPECT_FALSE(session_->CanInsertDtmf(""));
1011 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1012 }
1013
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001014 // Helper class to configure loopback network and verify Best
1015 // Connection using right IP protocol for TestLoopbackCall
1016 // method. LoopbackNetworkManager applies firewall rules to block
1017 // all ping traffic once ICE completed, and remove them to observe
1018 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1019 // verifies the best connection is using the right IP protocol after
1020 // initial ICE convergences.
1021
1022 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001023 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001024 LoopbackNetworkConfiguration()
1025 : test_ipv6_network_(false),
1026 test_extra_ipv4_network_(false),
1027 best_connection_after_initial_ice_converged_(1, 0) {}
1028
1029 // Used to track the expected best connection count in each IP protocol.
1030 struct ExpectedBestConnection {
1031 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1032 : ipv4_count_(ipv4_count),
1033 ipv6_count_(ipv6_count) {}
1034
1035 int ipv4_count_;
1036 int ipv6_count_;
1037 };
1038
1039 bool test_ipv6_network_;
1040 bool test_extra_ipv4_network_;
1041 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1042
1043 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001044 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001045 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1046 }
1047
1048 private:
jbauchac8869e2015-07-03 01:36:14 -07001049 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001050 const ExpectedBestConnection& expected) const {
1051 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001052 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1053 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001054 expected.ipv4_count_);
1055 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001056 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1057 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001058 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001059 // This is used in the loopback call so there is only single host to host
1060 // candidate pair.
1061 EXPECT_EQ(metrics_observer->GetEnumCounter(
1062 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1063 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001064 0);
1065 EXPECT_EQ(metrics_observer->GetEnumCounter(
1066 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1067 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001068 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001069 }
1070 };
1071
1072 class LoopbackNetworkManager {
1073 public:
1074 LoopbackNetworkManager(WebRtcSessionTest* session,
1075 const LoopbackNetworkConfiguration& config)
1076 : config_(config) {
1077 session->AddInterface(
1078 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1079 if (config_.test_extra_ipv4_network_) {
1080 session->AddInterface(
1081 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1082 }
1083 if (config_.test_ipv6_network_) {
1084 session->AddInterface(
1085 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1086 }
1087 }
1088
1089 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1090 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1091 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1092 if (config_.test_extra_ipv4_network_) {
1093 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1094 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1095 }
1096 if (config_.test_ipv6_network_) {
1097 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1098 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1099 }
1100 }
1101
1102 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1103
1104 private:
1105 LoopbackNetworkConfiguration config_;
1106 };
1107
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 // The method sets up a call from the session to itself, in a loopback
1109 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001110 // disconnection, and then a permanent disconnection.
1111 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1113 // While running the call, this method also checks if the session goes through
1114 // the correct sequence of ICE states when a connection is established,
1115 // broken, and re-established.
1116 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001117 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1118 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001120
1121 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1122 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001123 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001125 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126
1127 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1128 observer_.ice_gathering_state_);
1129 SetLocalDescriptionWithoutError(offer);
1130 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1131 observer_.ice_connection_state_);
1132 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1133 observer_.ice_gathering_state_,
1134 kIceCandidatesTimeout);
1135 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1136 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1137 observer_.ice_gathering_state_,
1138 kIceCandidatesTimeout);
1139
1140 std::string sdp;
1141 offer->ToString(&sdp);
1142 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001143 webrtc::CreateSessionDescription(
1144 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 ASSERT_TRUE(desc != NULL);
1146 SetRemoteDescriptionWithoutError(desc);
1147
1148 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1149 observer_.ice_connection_state_,
1150 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001151
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001152 // The ice connection state is "Connected" too briefly to catch in a test.
1153 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 observer_.ice_connection_state_,
1155 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 // Adding firewall rule to block ping requests, which should cause
1159 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001160
1161 loopback_network_manager.ApplyFirewallRules(fss_.get());
1162
1163 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1165 observer_.ice_connection_state_,
1166 kIceCandidatesTimeout);
1167
jbauchac8869e2015-07-03 01:36:14 -07001168 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001173 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001174 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 observer_.ice_connection_state_,
1176 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001177
1178 // Now we block ping requests and wait until the ICE connection transitions
1179 // to the Failed state. This will take at least 30 seconds because it must
1180 // wait for the Port to timeout.
1181 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001182
1183 loopback_network_manager.ApplyFirewallRules(fss_.get());
1184 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001185 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001186 observer_.ice_connection_state_,
1187 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 }
1189
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001190 void TestLoopbackCall() {
1191 LoopbackNetworkConfiguration config;
1192 TestLoopbackCall(config);
1193 }
1194
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1196 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001197 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1198 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1199
1200 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1202 codecs.push_back(kCNCodec1);
1203 codecs.push_back(kCNCodec2);
1204 media_engine_->SetAudioCodecs(codecs);
1205 desc_factory_->set_audio_codecs(codecs);
1206 }
1207
1208 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1209 const cricket::ContentDescription* description = content->description;
1210 ASSERT(description != NULL);
1211 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001212 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 ASSERT(audio_content_desc != NULL);
1214 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1215 if (audio_content_desc->codecs()[i].name == "CN")
1216 return false;
1217 }
1218 return true;
1219 }
1220
1221 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001222 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 dci.reliable = false;
1224 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001225 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 SetLocalDescriptionWithoutError(offer);
1227 }
1228
wu@webrtc.org91053e72013-08-10 07:18:04 +00001229 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001230 RTCCertificateGenerationMethod cert_gen_method,
1231 CreateSessionDescriptionRequest::Type type) {
1232 InitWithDtls(cert_gen_method);
1233 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1234 }
1235
1236 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1237 CreateSessionDescriptionRequest::Type type) {
1238 InitWithDtlsIdentityGenFail();
1239 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1240 }
1241
1242 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001243 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001244 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001245 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001246 if (type == CreateSessionDescriptionRequest::kAnswer) {
1247 cricket::MediaSessionOptions options;
1248 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001249 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001250 ASSERT_TRUE(offer.get() != NULL);
1251 SetRemoteDescriptionWithoutError(offer.release());
1252 }
1253
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001254 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001255 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001256 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001257 observers[kNumber];
1258 for (int i = 0; i < kNumber; ++i) {
1259 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1260 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001261 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001262 } else {
1263 session_->CreateAnswer(observers[i], NULL);
1264 }
1265 }
1266
1267 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1268 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1269 WebRtcSessionCreateSDPObserverForTest::kFailed;
1270
1271 for (int i = 0; i < kNumber; ++i) {
1272 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1273 if (success) {
1274 EXPECT_TRUE(observers[i]->description() != NULL);
1275 } else {
1276 EXPECT_TRUE(observers[i]->description() == NULL);
1277 }
1278 }
1279 }
1280
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001281 void ConfigureAllocatorWithTurn() {
1282 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1283 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1284 relay_server.credentials = credentials;
1285 relay_server.ports.push_back(cricket::ProtocolAddress(
1286 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1287 allocator_->AddRelay(relay_server);
1288 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001289 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001290 }
1291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 cricket::FakeMediaEngine* media_engine_;
1293 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001294 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1295 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001296 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1297 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1298 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1299 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1300 rtc::SocketServerScope ss_scope_;
1301 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001302 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001303 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001304 rtc::FakeNetworkManager network_manager_;
1305 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001306 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001307 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001309 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 MockIceObserver observer_;
1311 cricket::FakeVideoMediaChannel* video_channel_;
1312 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001313 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314};
1315
Henrik Boström87713d02015-08-25 09:53:21 +02001316TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1317 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001318 // SDES is disabled when DTLS is on.
1319 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320}
1321
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001322TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001323 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001324 // SDES is required if DTLS is off.
1325 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001326}
1327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1329 TestSessionCandidatesWithBundleRtcpMux(false, false);
1330}
1331
1332// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1333// with rtcp-mux and/or bundle.
1334TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1335 TestSessionCandidatesWithBundleRtcpMux(false, true);
1336}
1337
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1339 TestSessionCandidatesWithBundleRtcpMux(true, true);
1340}
1341
1342TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001343 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1344 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001345 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 mediastream_signaling_.SendAudioVideoStream1();
1347 InitiateCall();
1348 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1349 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1350 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1351}
1352
1353TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001354 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1355 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001356 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001357 rtc::FP_UDP,
1358 rtc::FD_ANY,
1359 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001360 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 mediastream_signaling_.SendAudioVideoStream1();
1362 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001363 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1365 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1366 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1367}
1368
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001369// Test session delivers no candidates gathered when constraint set to "none".
1370TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1371 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001372 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001373 mediastream_signaling_.SendAudioVideoStream1();
1374 InitiateCall();
1375 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1376 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1377 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1378}
1379
1380// Test session delivers only relay candidates gathered when constaint set to
1381// "relay".
1382TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1383 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1384 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001385 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001386 mediastream_signaling_.SendAudioVideoStream1();
1387 InitiateCall();
1388 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1389 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1390 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1391 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1392 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1393 observer_.mline_0_candidates_[i].type());
1394 }
1395 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1396 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1397 observer_.mline_1_candidates_[i].type());
1398 }
1399}
1400
1401// Test session delivers all candidates gathered when constaint set to "all".
1402TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1403 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001404 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001405 mediastream_signaling_.SendAudioVideoStream1();
1406 InitiateCall();
1407 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1408 // Host + STUN. By default allocator is disabled to gather relay candidates.
1409 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1410 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1411}
1412
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001413TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001414 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001415 SessionDescriptionInterface* offer = NULL;
1416 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1417 std::string unknown_action;
1418 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1419 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1420}
1421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422// Test creating offers and receive answers and make sure the
1423// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001424TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001425 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001427 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 const std::string session_id_orig = offer->session_id();
1429 const std::string session_version_orig = offer->session_version();
1430 SetLocalDescriptionWithoutError(offer);
1431
1432 mediastream_signaling_.SendAudioVideoStream2();
1433 SessionDescriptionInterface* answer =
1434 CreateRemoteAnswer(session_->local_description());
1435 SetRemoteDescriptionWithoutError(answer);
1436
1437 video_channel_ = media_engine_->GetVideoChannel(0);
1438 voice_channel_ = media_engine_->GetVoiceChannel(0);
1439
1440 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1441 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1442
1443 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1444 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1445
1446 ASSERT_EQ(1u, video_channel_->send_streams().size());
1447 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1448 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1449 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1450
1451 // Create new offer without send streams.
1452 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001453 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454
1455 // Verify the session id is the same and the session version is
1456 // increased.
1457 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001458 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1459 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460
1461 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001462 EXPECT_EQ(0u, video_channel_->send_streams().size());
1463 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464
1465 mediastream_signaling_.SendAudioVideoStream2();
1466 answer = CreateRemoteAnswer(session_->local_description());
1467 SetRemoteDescriptionWithoutError(answer);
1468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 // Make sure the receive streams have not changed.
1470 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1471 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1472 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1473 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1474}
1475
1476// Test receiving offers and creating answers and make sure the
1477// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001478TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001479 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001481 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001482 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 SetRemoteDescriptionWithoutError(offer);
1484
1485 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001486 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001487 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 SetLocalDescriptionWithoutError(answer);
1489
1490 const std::string session_id_orig = answer->session_id();
1491 const std::string session_version_orig = answer->session_version();
1492
1493 video_channel_ = media_engine_->GetVideoChannel(0);
1494 voice_channel_ = media_engine_->GetVoiceChannel(0);
1495
1496 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1497 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1498
1499 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1500 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1501
1502 ASSERT_EQ(1u, video_channel_->send_streams().size());
1503 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1504 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1505 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1506
1507 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001508 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 SetRemoteDescriptionWithoutError(offer);
1510
1511 // Answer by turning off all send streams.
1512 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001513 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514
1515 // Verify the session id is the same and the session version is
1516 // increased.
1517 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001518 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1519 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 SetLocalDescriptionWithoutError(answer);
1521
1522 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1523 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1524 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1525 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1526 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1527 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1528
1529 // Make sure we have no send streams.
1530 EXPECT_EQ(0u, video_channel_->send_streams().size());
1531 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1532}
1533
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001534TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001535 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001536 media_engine_->set_fail_create_channel(true);
1537
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001538 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001539 ASSERT_TRUE(offer != NULL);
1540 // SetRemoteDescription and SetLocalDescription will take the ownership of
1541 // the offer.
1542 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001543 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001544 ASSERT_TRUE(offer != NULL);
1545 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1546}
1547
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001548//
1549// Tests for creating/setting SDP under different SDES/DTLS polices:
1550//
1551// --DTLS off and SDES on
1552// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1553// set local/remote offer/answer with crypto --> success
1554// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1555// failure
1556// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1557// failure
1558// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1559// failure
1560//
1561// --DTLS on and SDES off
1562// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1563// set local/remote offer/answer with DTLS fingerprint --> success
1564// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1565// fingerprint --> failure
1566// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1567// --> failure
1568// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1569// --> failure
1570//
1571// --Encryption disabled: DTLS off and SDES off
1572// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1573// answer without SDES or DTLS --> success
1574// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1575// answer without SDES or DTLS --> success
1576//
1577
1578// Test that we return a failure when applying a remote/local offer that doesn't
1579// have cryptos enabled when DTLS is off.
1580TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001583 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 JsepSessionDescription* offer = CreateRemoteOffer(
1585 options, cricket::SEC_DISABLED);
1586 ASSERT_TRUE(offer != NULL);
1587 VerifyNoCryptoParams(offer->description(), false);
1588 // SetRemoteDescription and SetLocalDescription will take the ownership of
1589 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001590 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1592 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001593 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594}
1595
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596// Test that we return a failure when applying a local answer that doesn't have
1597// cryptos enabled when DTLS is off.
1598TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001599 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 SessionDescriptionInterface* offer = NULL;
1601 SessionDescriptionInterface* answer = NULL;
1602 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1603 // SetRemoteDescription and SetLocalDescription will take the ownership of
1604 // the offer.
1605 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607}
1608
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001609// Test we will return fail when apply an remote answer that doesn't have
1610// crypto enabled when DTLS is off.
1611TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001612 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 SessionDescriptionInterface* offer = NULL;
1614 SessionDescriptionInterface* answer = NULL;
1615 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1616 // SetRemoteDescription and SetLocalDescription will take the ownership of
1617 // the offer.
1618 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620}
1621
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1623// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001624TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001625 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001627 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 SetFactoryDtlsSrtp();
1629 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001630 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001631 JsepSessionDescription* offer =
1632 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 ASSERT_TRUE(offer != NULL);
1634 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001635 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636
1637 // SetRemoteDescription will take the ownership of the offer.
1638 SetRemoteDescriptionWithoutError(offer);
1639
1640 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001641 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 ASSERT_TRUE(answer != NULL);
1643 VerifyFingerprintStatus(answer->description(), true);
1644 // Check that we don't have an a=crypto line in the answer.
1645 VerifyNoCryptoParams(answer->description(), true);
1646
1647 // Now set the local description, which should work, even without a=crypto.
1648 SetLocalDescriptionWithoutError(answer);
1649}
1650
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1652// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001653TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001654 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001655 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001656 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657 SetFactoryDtlsSrtp();
1658
1659 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001661 ASSERT_TRUE(offer != NULL);
1662 VerifyFingerprintStatus(offer->description(), true);
1663 // Check that we don't have an a=crypto line in the offer.
1664 VerifyNoCryptoParams(offer->description(), true);
1665
1666 // Now set the local description, which should work, even without a=crypto.
1667 SetLocalDescriptionWithoutError(offer);
1668
1669 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001670 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671 JsepSessionDescription* answer =
1672 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1673 ASSERT_TRUE(answer != NULL);
1674 VerifyFingerprintStatus(answer->description(), true);
1675 VerifyNoCryptoParams(answer->description(), true);
1676
1677 // SetRemoteDescription will take the ownership of the answer.
1678 SetRemoteDescriptionWithoutError(answer);
1679}
1680
1681// Test that if we support DTLS and the other side didn't offer a fingerprint,
1682// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001683TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001684 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001685 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001687 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001688 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 JsepSessionDescription* offer = CreateRemoteOffer(
1690 options, cricket::SEC_REQUIRED);
1691 ASSERT_TRUE(offer != NULL);
1692 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001695 // SetRemoteDescription will take the ownership of the offer.
1696 SetRemoteDescriptionOfferExpectError(
1697 kSdpWithoutDtlsFingerprint, offer);
1698
1699 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1700 // SetLocalDescription will take the ownership of the offer.
1701 SetLocalDescriptionOfferExpectError(
1702 kSdpWithoutDtlsFingerprint, offer);
1703}
1704
1705// Test that we return a failure when applying a local answer that doesn't have
1706// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001707TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001708 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001709 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001710 SessionDescriptionInterface* offer = NULL;
1711 SessionDescriptionInterface* answer = NULL;
1712 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1713
1714 // SetRemoteDescription and SetLocalDescription will take the ownership of
1715 // the offer and answer.
1716 SetRemoteDescriptionWithoutError(offer);
1717 SetLocalDescriptionAnswerExpectError(
1718 kSdpWithoutDtlsFingerprint, answer);
1719}
1720
1721// Test that we return a failure when applying a remote answer that doesn't have
1722// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001723TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001724 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001725 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001726 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001728 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001729 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1730 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001732 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733
1734 // SetRemoteDescription and SetLocalDescription will take the ownership of
1735 // the offer and answer.
1736 SetLocalDescriptionWithoutError(offer);
1737 SetRemoteDescriptionAnswerExpectError(
1738 kSdpWithoutDtlsFingerprint, answer);
1739}
1740
1741// Test that we create a local offer without SDES or DTLS and accept a remote
1742// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001743TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744 mediastream_signaling_.SendAudioVideoStream1();
1745 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001746 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001747
1748 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001749 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001750 ASSERT_TRUE(offer != NULL);
1751 VerifyFingerprintStatus(offer->description(), false);
1752 // Check that we don't have an a=crypto line in the offer.
1753 VerifyNoCryptoParams(offer->description(), false);
1754
1755 // Now set the local description, which should work, even without a=crypto.
1756 SetLocalDescriptionWithoutError(offer);
1757
1758 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001759 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760 JsepSessionDescription* answer =
1761 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1762 ASSERT_TRUE(answer != NULL);
1763 VerifyFingerprintStatus(answer->description(), false);
1764 VerifyNoCryptoParams(answer->description(), false);
1765
1766 // SetRemoteDescription will take the ownership of the answer.
1767 SetRemoteDescriptionWithoutError(answer);
1768}
1769
1770// Test that we create a local answer without SDES or DTLS and accept a remote
1771// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001772TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001773 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001774 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001775
1776 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001777 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778 JsepSessionDescription* offer =
1779 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1780 ASSERT_TRUE(offer != NULL);
1781 VerifyFingerprintStatus(offer->description(), false);
1782 VerifyNoCryptoParams(offer->description(), false);
1783
1784 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 SetRemoteDescriptionWithoutError(offer);
1786
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001788 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 ASSERT_TRUE(answer != NULL);
1790 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 // Check that we don't have an a=crypto line in the answer.
1792 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 SetLocalDescriptionWithoutError(answer);
1796}
1797
1798TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001799 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 mediastream_signaling_.SendNothing();
1801 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001802 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 SetLocalDescriptionWithoutError(offer);
1804
1805 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001806 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 SetLocalDescriptionWithoutError(offer2);
1808}
1809
1810TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001811 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 mediastream_signaling_.SendNothing();
1813 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001814 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 SetRemoteDescriptionWithoutError(offer);
1816
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001817 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 SetRemoteDescriptionWithoutError(offer2);
1819}
1820
1821TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001822 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001824 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001826 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001827 SetRemoteDescriptionOfferExpectError(
1828 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829}
1830
1831TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
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 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001836 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001837 SetLocalDescriptionOfferExpectError(
1838 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839}
1840
1841TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001842 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 mediastream_signaling_.SendNothing();
1844 SessionDescriptionInterface* offer = CreateRemoteOffer();
1845 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1846
1847 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001848 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1850 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1851
1852 mediastream_signaling_.SendAudioVideoStream1();
1853 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001854 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1856
1857 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1858
1859 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001860 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1862}
1863
1864TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001865 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001867 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1869
1870 JsepSessionDescription* pranswer =
1871 CreateRemoteAnswer(session_->local_description());
1872 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1873
1874 SetRemoteDescriptionExpectState(pranswer,
1875 BaseSession::STATE_RECEIVEDPRACCEPT);
1876
1877 mediastream_signaling_.SendAudioVideoStream1();
1878 JsepSessionDescription* pranswer2 =
1879 CreateRemoteAnswer(session_->local_description());
1880 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1881
1882 SetRemoteDescriptionExpectState(pranswer2,
1883 BaseSession::STATE_RECEIVEDPRACCEPT);
1884
1885 mediastream_signaling_.SendAudioVideoStream2();
1886 SessionDescriptionInterface* answer =
1887 CreateRemoteAnswer(session_->local_description());
1888 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1889}
1890
1891TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001892 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001894 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 SessionDescriptionInterface* answer =
1897 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001898 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1899 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900}
1901
1902TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001903 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001905 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 SessionDescriptionInterface* answer =
1908 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001909 SetRemoteDescriptionAnswerExpectError(
1910 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911}
1912
1913TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001914 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 mediastream_signaling_.SendAudioVideoStream1();
1916
1917 cricket::Candidate candidate;
1918 candidate.set_component(1);
1919 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1920
1921 // Fail since we have not set a offer description.
1922 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1923
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001924 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 SetLocalDescriptionWithoutError(offer);
1926 // Candidate should be allowed to add before remote description.
1927 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1928 candidate.set_component(2);
1929 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1930 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1931
1932 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1933 session_->local_description());
1934 SetRemoteDescriptionWithoutError(answer);
1935
1936 // Verifying the candidates are copied properly from internal vector.
1937 const SessionDescriptionInterface* remote_desc =
1938 session_->remote_description();
1939 ASSERT_TRUE(remote_desc != NULL);
1940 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1941 const IceCandidateCollection* candidates =
1942 remote_desc->candidates(kMediaContentIndex0);
1943 ASSERT_EQ(2u, candidates->count());
1944 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1945 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1946 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1947 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1948
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001949 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1950 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 candidate.set_component(2);
1952 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1953 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001954 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955
1956 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1957 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1958}
1959
1960// Test that a remote candidate is added to the remote session description and
1961// that it is retained if the remote session description is changed.
1962TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001963 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 cricket::Candidate candidate1;
1965 candidate1.set_component(1);
1966 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1967 candidate1);
1968 mediastream_signaling_.SendAudioVideoStream1();
1969 CreateAndSetRemoteOfferAndLocalAnswer();
1970
1971 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1972 const SessionDescriptionInterface* remote_desc =
1973 session_->remote_description();
1974 ASSERT_TRUE(remote_desc != NULL);
1975 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1976 const IceCandidateCollection* candidates =
1977 remote_desc->candidates(kMediaContentIndex0);
1978 ASSERT_EQ(1u, candidates->count());
1979 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1980
1981 // Update the RemoteSessionDescription with a new session description and
1982 // a candidate and check that the new remote session description contains both
1983 // candidates.
1984 SessionDescriptionInterface* offer = CreateRemoteOffer();
1985 cricket::Candidate candidate2;
1986 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1987 candidate2);
1988 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1989 SetRemoteDescriptionWithoutError(offer);
1990
1991 remote_desc = session_->remote_description();
1992 ASSERT_TRUE(remote_desc != NULL);
1993 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1994 candidates = remote_desc->candidates(kMediaContentIndex0);
1995 ASSERT_EQ(2u, candidates->count());
1996 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1997 // Username and password have be updated with the TransportInfo of the
1998 // SessionDescription, won't be equal to the original one.
1999 candidate2.set_username(candidates->at(0)->candidate().username());
2000 candidate2.set_password(candidates->at(0)->candidate().password());
2001 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2002 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2003 // No need to verify the username and password.
2004 candidate1.set_username(candidates->at(1)->candidate().username());
2005 candidate1.set_password(candidates->at(1)->candidate().password());
2006 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2007
2008 // Test that the candidate is ignored if we can add the same candidate again.
2009 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2010}
2011
2012// Test that local candidates are added to the local session description and
2013// that they are retained if the local session description is changed.
2014TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002015 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002016 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 mediastream_signaling_.SendAudioVideoStream1();
2018 CreateAndSetRemoteOfferAndLocalAnswer();
2019
2020 const SessionDescriptionInterface* local_desc = session_->local_description();
2021 const IceCandidateCollection* candidates =
2022 local_desc->candidates(kMediaContentIndex0);
2023 ASSERT_TRUE(candidates != NULL);
2024 EXPECT_EQ(0u, candidates->count());
2025
2026 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2027
2028 local_desc = session_->local_description();
2029 candidates = local_desc->candidates(kMediaContentIndex0);
2030 ASSERT_TRUE(candidates != NULL);
2031 EXPECT_LT(0u, candidates->count());
2032 candidates = local_desc->candidates(1);
2033 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002034 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
2036 // Update the session descriptions.
2037 mediastream_signaling_.SendAudioVideoStream1();
2038 CreateAndSetRemoteOfferAndLocalAnswer();
2039
2040 local_desc = session_->local_description();
2041 candidates = local_desc->candidates(kMediaContentIndex0);
2042 ASSERT_TRUE(candidates != NULL);
2043 EXPECT_LT(0u, candidates->count());
2044 candidates = local_desc->candidates(1);
2045 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002046 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047}
2048
2049// Test that we can set a remote session description with remote candidates.
2050TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002051 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
2053 cricket::Candidate candidate1;
2054 candidate1.set_component(1);
2055 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2056 candidate1);
2057 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059
2060 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2061 SetRemoteDescriptionWithoutError(offer);
2062
2063 const SessionDescriptionInterface* remote_desc =
2064 session_->remote_description();
2065 ASSERT_TRUE(remote_desc != NULL);
2066 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2067 const IceCandidateCollection* candidates =
2068 remote_desc->candidates(kMediaContentIndex0);
2069 ASSERT_EQ(1u, candidates->count());
2070 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2071
wu@webrtc.org91053e72013-08-10 07:18:04 +00002072 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 SetLocalDescriptionWithoutError(answer);
2074}
2075
2076// Test that offers and answers contains ice candidates when Ice candidates have
2077// been gathered.
2078TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002079 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002080 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 mediastream_signaling_.SendAudioVideoStream1();
2082 // Ice is started but candidates are not provided until SetLocalDescription
2083 // is called.
2084 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2085 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2086 CreateAndSetRemoteOfferAndLocalAnswer();
2087 // Wait until at least one local candidate has been collected.
2088 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2089 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002091 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2094 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
2096 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2097 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002098 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2100 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 SetLocalDescriptionWithoutError(answer);
2102}
2103
2104// Verifies TransportProxy and media channels are created with content names
2105// present in the SessionDescription.
2106TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002107 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002109 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
2111 // CreateOffer creates session description with the content names "audio" and
2112 // "video". Goal is to modify these content names and verify transport channel
2113 // proxy in the BaseSession, as proxies are created with the content names
2114 // present in SDP.
2115 std::string sdp;
2116 EXPECT_TRUE(offer->ToString(&sdp));
2117 const std::string kAudioMid = "a=mid:audio";
2118 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2119 const std::string kVideoMid = "a=mid:video";
2120 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2121
2122 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002123 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 kAudioMidReplaceStr.c_str(),
2125 kAudioMidReplaceStr.length(),
2126 &sdp);
2127 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002128 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 kVideoMidReplaceStr.c_str(),
2130 kVideoMidReplaceStr.length(),
2131 &sdp);
2132
2133 SessionDescriptionInterface* modified_offer =
2134 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2135
2136 SetRemoteDescriptionWithoutError(modified_offer);
2137
2138 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002139 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 SetLocalDescriptionWithoutError(answer);
2141
deadbeefcbecd352015-09-23 11:50:27 -07002142 cricket::TransportChannel* voice_transport_channel =
2143 session_->voice_rtp_transport_channel();
2144 EXPECT_TRUE(voice_transport_channel != NULL);
2145 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2146 cricket::TransportChannel* video_transport_channel =
2147 session_->video_rtp_transport_channel();
2148 EXPECT_TRUE(video_transport_channel != NULL);
2149 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2151 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2152}
2153
2154// Test that an offer contains the correct media content descriptions based on
2155// the send streams when no constraints have been set.
2156TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002157 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002158 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2159
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 ASSERT_TRUE(offer != NULL);
2161 const cricket::ContentInfo* content =
2162 cricket::GetFirstAudioContent(offer->description());
2163 EXPECT_TRUE(content != NULL);
2164 content = cricket::GetFirstVideoContent(offer->description());
2165 EXPECT_TRUE(content == NULL);
2166}
2167
2168// Test that an offer contains the correct media content descriptions based on
2169// the send streams when no constraints have been set.
2170TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002171 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 // Test Audio only offer.
2173 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002174 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2175
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 const cricket::ContentInfo* content =
2177 cricket::GetFirstAudioContent(offer->description());
2178 EXPECT_TRUE(content != NULL);
2179 content = cricket::GetFirstVideoContent(offer->description());
2180 EXPECT_TRUE(content == NULL);
2181
2182 // Test Audio / Video offer.
2183 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002184 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 content = cricket::GetFirstAudioContent(offer->description());
2186 EXPECT_TRUE(content != NULL);
2187 content = cricket::GetFirstVideoContent(offer->description());
2188 EXPECT_TRUE(content != NULL);
2189}
2190
2191// Test that an offer contains no media content descriptions if
2192// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2193TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002194 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002195 PeerConnectionInterface::RTCOfferAnswerOptions options;
2196 options.offer_to_receive_audio = 0;
2197 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002199 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002200 CreateOffer(options));
2201
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202 ASSERT_TRUE(offer != NULL);
2203 const cricket::ContentInfo* content =
2204 cricket::GetFirstAudioContent(offer->description());
2205 EXPECT_TRUE(content == NULL);
2206 content = cricket::GetFirstVideoContent(offer->description());
2207 EXPECT_TRUE(content == NULL);
2208}
2209
2210// Test that an offer contains only audio media content descriptions if
2211// kOfferToReceiveAudio constraints are set to true.
2212TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002213 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002214 PeerConnectionInterface::RTCOfferAnswerOptions options;
2215 options.offer_to_receive_audio =
2216 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2217
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002218 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002219 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220
2221 const cricket::ContentInfo* content =
2222 cricket::GetFirstAudioContent(offer->description());
2223 EXPECT_TRUE(content != NULL);
2224 content = cricket::GetFirstVideoContent(offer->description());
2225 EXPECT_TRUE(content == NULL);
2226}
2227
2228// Test that an offer contains audio and video media content descriptions if
2229// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2230TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002231 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002233 PeerConnectionInterface::RTCOfferAnswerOptions options;
2234 options.offer_to_receive_audio =
2235 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2236 options.offer_to_receive_video =
2237 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2238
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002239 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002240 CreateOffer(options));
2241
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 const cricket::ContentInfo* content =
2243 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002244 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 content = cricket::GetFirstVideoContent(offer->description());
2247 EXPECT_TRUE(content != NULL);
2248
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002249 // Sets constraints to false and verifies that audio/video contents are
2250 // removed.
2251 options.offer_to_receive_audio = 0;
2252 options.offer_to_receive_video = 0;
2253 offer.reset(CreateOffer(options));
2254
2255 content = cricket::GetFirstAudioContent(offer->description());
2256 EXPECT_TRUE(content == NULL);
2257 content = cricket::GetFirstVideoContent(offer->description());
2258 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259}
2260
2261// Test that an answer can not be created if the last remote description is not
2262// an offer.
2263TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002264 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002265 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 SetLocalDescriptionWithoutError(offer);
2267 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2268 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002269 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270}
2271
2272// Test that an answer contains the correct media content descriptions when no
2273// constraints have been set.
2274TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002275 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002277 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002279 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002280 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 const cricket::ContentInfo* content =
2282 cricket::GetFirstAudioContent(answer->description());
2283 ASSERT_TRUE(content != NULL);
2284 EXPECT_FALSE(content->rejected);
2285
2286 content = cricket::GetFirstVideoContent(answer->description());
2287 ASSERT_TRUE(content != NULL);
2288 EXPECT_FALSE(content->rejected);
2289}
2290
2291// Test that an answer contains the correct media content descriptions when no
2292// constraints have been set and the offer only contain audio.
2293TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002294 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 // Create a remote offer with audio only.
2296 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002297
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002298 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 CreateRemoteOffer(options));
2300 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2301 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2302
2303 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002304 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002305 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 const cricket::ContentInfo* content =
2307 cricket::GetFirstAudioContent(answer->description());
2308 ASSERT_TRUE(content != NULL);
2309 EXPECT_FALSE(content->rejected);
2310
2311 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2312}
2313
2314// Test that an answer contains the correct media content descriptions when no
2315// constraints have been set.
2316TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002317 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002319 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 SetRemoteDescriptionWithoutError(offer.release());
2321 // Test with a stream with tracks.
2322 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002324 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 const cricket::ContentInfo* content =
2326 cricket::GetFirstAudioContent(answer->description());
2327 ASSERT_TRUE(content != NULL);
2328 EXPECT_FALSE(content->rejected);
2329
2330 content = cricket::GetFirstVideoContent(answer->description());
2331 ASSERT_TRUE(content != NULL);
2332 EXPECT_FALSE(content->rejected);
2333}
2334
2335// Test that an answer contains the correct media content descriptions when
2336// constraints have been set but no stream is sent.
2337TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002338 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002340 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 SetRemoteDescriptionWithoutError(offer.release());
2342
2343 webrtc::FakeConstraints constraints_no_receive;
2344 constraints_no_receive.SetMandatoryReceiveAudio(false);
2345 constraints_no_receive.SetMandatoryReceiveVideo(false);
2346
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002347 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002348 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 const cricket::ContentInfo* content =
2350 cricket::GetFirstAudioContent(answer->description());
2351 ASSERT_TRUE(content != NULL);
2352 EXPECT_TRUE(content->rejected);
2353
2354 content = cricket::GetFirstVideoContent(answer->description());
2355 ASSERT_TRUE(content != NULL);
2356 EXPECT_TRUE(content->rejected);
2357}
2358
2359// Test that an answer contains the correct media content descriptions when
2360// constraints have been set and streams are sent.
2361TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002362 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002364 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 SetRemoteDescriptionWithoutError(offer.release());
2366
2367 webrtc::FakeConstraints constraints_no_receive;
2368 constraints_no_receive.SetMandatoryReceiveAudio(false);
2369 constraints_no_receive.SetMandatoryReceiveVideo(false);
2370
2371 // Test with a stream with tracks.
2372 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002373 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002374 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375
2376 // TODO(perkj): Should the direction be set to SEND_ONLY?
2377 const cricket::ContentInfo* content =
2378 cricket::GetFirstAudioContent(answer->description());
2379 ASSERT_TRUE(content != NULL);
2380 EXPECT_FALSE(content->rejected);
2381
2382 // TODO(perkj): Should the direction be set to SEND_ONLY?
2383 content = cricket::GetFirstVideoContent(answer->description());
2384 ASSERT_TRUE(content != NULL);
2385 EXPECT_FALSE(content->rejected);
2386}
2387
2388TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2389 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002390 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391 PeerConnectionInterface::RTCOfferAnswerOptions options;
2392 options.offer_to_receive_audio =
2393 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2394 options.voice_activity_detection = false;
2395
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002396 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397 CreateOffer(options));
2398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 const cricket::ContentInfo* content =
2400 cricket::GetFirstAudioContent(offer->description());
2401 EXPECT_TRUE(content != NULL);
2402 EXPECT_TRUE(VerifyNoCNCodecs(content));
2403}
2404
2405TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2406 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002407 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002409 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 SetRemoteDescriptionWithoutError(offer.release());
2411
2412 webrtc::FakeConstraints constraints;
2413 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002414 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002415 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 const cricket::ContentInfo* content =
2417 cricket::GetFirstAudioContent(answer->description());
2418 ASSERT_TRUE(content != NULL);
2419 EXPECT_TRUE(VerifyNoCNCodecs(content));
2420}
2421
2422// This test verifies the call setup when remote answer with audio only and
2423// later updates with video.
2424TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002425 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2427 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2428
2429 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002430 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431
2432 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2434
2435 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2436 // and answer;
2437 SetLocalDescriptionWithoutError(offer);
2438 SetRemoteDescriptionWithoutError(answer);
2439
2440 video_channel_ = media_engine_->GetVideoChannel(0);
2441 voice_channel_ = media_engine_->GetVoiceChannel(0);
2442
2443 ASSERT_TRUE(video_channel_ == NULL);
2444
2445 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2446 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2447 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2448
2449 // Let the remote end update the session descriptions, with Audio and Video.
2450 mediastream_signaling_.SendAudioVideoStream2();
2451 CreateAndSetRemoteOfferAndLocalAnswer();
2452
2453 video_channel_ = media_engine_->GetVideoChannel(0);
2454 voice_channel_ = media_engine_->GetVoiceChannel(0);
2455
2456 ASSERT_TRUE(video_channel_ != NULL);
2457 ASSERT_TRUE(voice_channel_ != NULL);
2458
2459 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2460 ASSERT_EQ(1u, video_channel_->send_streams().size());
2461 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2462 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2463 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2464 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2465 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2466 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2467
2468 // Change session back to audio only.
2469 mediastream_signaling_.UseOptionsAudioOnly();
2470 CreateAndSetRemoteOfferAndLocalAnswer();
2471
2472 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2473 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2474 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2475 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2476 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2477}
2478
2479// This test verifies the call setup when remote answer with video only and
2480// later updates with audio.
2481TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002482 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2484 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2485 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002486 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487
2488 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002489 options.recv_audio = false;
2490 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2492 offer, options, cricket::SEC_ENABLED);
2493
2494 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2495 // and answer.
2496 SetLocalDescriptionWithoutError(offer);
2497 SetRemoteDescriptionWithoutError(answer);
2498
2499 video_channel_ = media_engine_->GetVideoChannel(0);
2500 voice_channel_ = media_engine_->GetVoiceChannel(0);
2501
2502 ASSERT_TRUE(voice_channel_ == NULL);
2503 ASSERT_TRUE(video_channel_ != NULL);
2504
2505 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2506 ASSERT_EQ(1u, video_channel_->send_streams().size());
2507 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2508
2509 // Update the session descriptions, with Audio and Video.
2510 mediastream_signaling_.SendAudioVideoStream2();
2511 CreateAndSetRemoteOfferAndLocalAnswer();
2512
2513 voice_channel_ = media_engine_->GetVoiceChannel(0);
2514 ASSERT_TRUE(voice_channel_ != NULL);
2515
2516 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2517 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2518 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2519 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2520
2521 // Change session back to video only.
2522 mediastream_signaling_.UseOptionsVideoOnly();
2523 CreateAndSetRemoteOfferAndLocalAnswer();
2524
2525 video_channel_ = media_engine_->GetVideoChannel(0);
2526 voice_channel_ = media_engine_->GetVoiceChannel(0);
2527
2528 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2529 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2530 ASSERT_EQ(1u, video_channel_->send_streams().size());
2531 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2532}
2533
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002535 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002537 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538 VerifyCryptoParams(offer->description());
2539 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002540 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 VerifyCryptoParams(answer->description());
2542}
2543
2544TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002545 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002546 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002548 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 VerifyNoCryptoParams(offer->description(), false);
2550}
2551
2552TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002553 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 VerifyAnswerFromNonCryptoOffer();
2555}
2556
2557TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002558 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 VerifyAnswerFromCryptoOffer();
2560}
2561
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002562// This test verifies that setLocalDescription fails if
2563// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2564TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002566 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002567 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2568
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002569 std::string sdp;
2570 RemoveIceUfragPwdLines(offer.get(), &sdp);
2571 SessionDescriptionInterface* modified_offer =
2572 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002573 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002574}
2575
2576// This test verifies that setRemoteDescription fails if
2577// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2578TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002579 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002581 std::string sdp;
2582 RemoveIceUfragPwdLines(offer.get(), &sdp);
2583 SessionDescriptionInterface* modified_offer =
2584 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002585 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002586}
2587
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002588// This test verifies that setLocalDescription fails if local offer has
2589// too short ice ufrag and pwd strings.
2590TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002591 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002592 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002593 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2594
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002595 std::string sdp;
2596 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2597 // recommended values of 4 and 22 bytes respectively.
2598 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2599 SessionDescriptionInterface* modified_offer =
2600 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2601 std::string error;
2602 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2603
2604 // Test with string greater than 256.
2605 sdp.clear();
2606 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2607 &sdp);
2608 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2609 NULL);
2610 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2611}
2612
2613// This test verifies that setRemoteDescription fails if remote offer has
2614// too short ice ufrag and pwd strings.
2615TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002616 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002617 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002618 std::string sdp;
2619 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2620 // recommended values of 4 and 22 bytes respectively.
2621 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2622 SessionDescriptionInterface* modified_offer =
2623 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2624 std::string error;
2625 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2626
2627 sdp.clear();
2628 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2629 &sdp);
2630 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2631 NULL);
2632 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2633}
2634
honghaiz503726c2015-07-31 12:37:38 -07002635// Test that if the remote description indicates the peer requested ICE restart
2636// (via a new ufrag or pwd), the old ICE candidates are not copied,
2637// and vice versa.
2638TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2639 Init();
2640 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2641
2642 // Create the first offer.
2643 std::string sdp;
2644 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2645 "abcdefghijklmnopqrstuvwx", &sdp);
2646 SessionDescriptionInterface* offer1 =
2647 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2648 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2649 0, "", "", "relay", 0, "");
2650 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2651 candidate1);
2652 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2653 SetRemoteDescriptionWithoutError(offer1);
2654 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2655
2656 // The second offer has the same ufrag and pwd but different address.
2657 sdp.clear();
2658 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2659 "abcdefghijklmnopqrstuvwx", &sdp);
2660 SessionDescriptionInterface* offer2 =
2661 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2662 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2663 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2664 candidate1);
2665 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2666 SetRemoteDescriptionWithoutError(offer2);
2667 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2668
2669 // The third offer has a different ufrag and different address.
2670 sdp.clear();
2671 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2672 "abcdefghijklmnopqrstuvwx", &sdp);
2673 SessionDescriptionInterface* offer3 =
2674 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2675 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2676 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2677 candidate1);
2678 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2679 SetRemoteDescriptionWithoutError(offer3);
2680 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2681
2682 // The fourth offer has no candidate but a different ufrag/pwd.
2683 sdp.clear();
2684 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2685 "abcdefghijklmnopqrstuvyz", &sdp);
2686 SessionDescriptionInterface* offer4 =
2687 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2688 SetRemoteDescriptionWithoutError(offer4);
2689 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2690}
2691
Donald Curtisd4f769d2015-05-28 09:48:21 -07002692// Test that candidates sent to the "video" transport do not get pushed down to
2693// the "audio" transport channel when bundling using TransportProxy.
2694TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2695 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2696
2697 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2698 mediastream_signaling_.SendAudioVideoStream1();
2699
2700 PeerConnectionInterface::RTCOfferAnswerOptions options;
2701 options.use_rtp_mux = true;
2702
2703 SessionDescriptionInterface* offer = CreateRemoteOffer();
2704 SetRemoteDescriptionWithoutError(offer);
2705
2706 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2707 SetLocalDescriptionWithoutError(answer);
2708
deadbeefcbecd352015-09-23 11:50:27 -07002709 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2710 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002711
deadbeefcbecd352015-09-23 11:50:27 -07002712 cricket::BaseChannel* voice_channel = session_->voice_channel();
2713 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002714
2715 // Checks if one of the transport channels contains a connection using a given
2716 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002717 auto connection_with_remote_port = [this, voice_channel](int port) {
2718 cricket::SessionStats stats;
2719 session_->GetChannelTransportStats(voice_channel, &stats);
2720 for (auto& kv : stats.transport_stats) {
2721 for (auto& chan_stat : kv.second.channel_stats) {
2722 for (auto& conn_info : chan_stat.connection_infos) {
2723 if (conn_info.remote_candidate.address().port() == port) {
2724 return true;
2725 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002726 }
2727 }
2728 }
2729 return false;
2730 };
2731
2732 EXPECT_FALSE(connection_with_remote_port(5000));
2733 EXPECT_FALSE(connection_with_remote_port(5001));
2734 EXPECT_FALSE(connection_with_remote_port(6000));
2735
2736 // The way the *_WAIT checks work is they only wait if the condition fails,
2737 // which does not help in the case where state is not changing. This is
2738 // problematic in this test since we want to verify that adding a video
2739 // candidate does _not_ change state. So we interleave candidates and assume
2740 // that messages are executed in the order they were posted.
2741
2742 // First audio candidate.
2743 cricket::Candidate candidate0;
2744 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2745 candidate0.set_component(1);
2746 candidate0.set_protocol("udp");
2747 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2748 candidate0);
2749 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2750
2751 // Video candidate.
2752 cricket::Candidate candidate1;
2753 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2754 candidate1.set_component(1);
2755 candidate1.set_protocol("udp");
2756 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2757 candidate1);
2758 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2759
2760 // Second audio candidate.
2761 cricket::Candidate candidate2;
2762 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2763 candidate2.set_component(1);
2764 candidate2.set_protocol("udp");
2765 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2766 candidate2);
2767 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2768
2769 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2770 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2771
2772 // No need here for a _WAIT check since we are checking that state hasn't
2773 // changed: if this is false we would be doing waits for nothing and if this
2774 // is true then there will be no messages processed anyways.
2775 EXPECT_FALSE(connection_with_remote_port(6000));
2776}
2777
deadbeefcbecd352015-09-23 11:50:27 -07002778// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002779TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2780 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002782
2783 PeerConnectionInterface::RTCOfferAnswerOptions options;
2784 options.use_rtp_mux = true;
2785
2786 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002788
deadbeefcbecd352015-09-23 11:50:27 -07002789 EXPECT_NE(session_->voice_rtp_transport_channel(),
2790 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002793 SessionDescriptionInterface* answer =
2794 CreateRemoteAnswer(session_->local_description());
2795 SetRemoteDescriptionWithoutError(answer);
2796
deadbeefcbecd352015-09-23 11:50:27 -07002797 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2798 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002799}
2800
deadbeefcbecd352015-09-23 11:50:27 -07002801// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002802TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2803 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2804 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002805
Donald Curtis0e209b02015-03-24 09:29:54 -07002806 PeerConnectionInterface::RTCOfferAnswerOptions options;
2807 options.use_rtp_mux = true;
2808
2809 SessionDescriptionInterface* offer = CreateOffer(options);
2810 SetLocalDescriptionWithoutError(offer);
2811
deadbeefcbecd352015-09-23 11:50:27 -07002812 EXPECT_NE(session_->voice_rtp_transport_channel(),
2813 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002814
2815 mediastream_signaling_.SendAudioVideoStream2();
2816
2817 // Remove BUNDLE from the answer.
2818 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2819 CreateRemoteAnswer(session_->local_description()));
2820 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2821 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2822 JsepSessionDescription* modified_answer =
2823 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2824 modified_answer->Initialize(answer_copy, "1", "1");
2825 SetRemoteDescriptionWithoutError(modified_answer); //
2826
deadbeefcbecd352015-09-23 11:50:27 -07002827 EXPECT_NE(session_->voice_rtp_transport_channel(),
2828 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002829}
2830
2831// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2832TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2833 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2834 mediastream_signaling_.SendAudioVideoStream1();
2835
2836 PeerConnectionInterface::RTCOfferAnswerOptions options;
2837 options.use_rtp_mux = true;
2838
2839 SessionDescriptionInterface* offer = CreateOffer(options);
2840 SetLocalDescriptionWithoutError(offer);
2841
deadbeefcbecd352015-09-23 11:50:27 -07002842 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2843 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002844
2845 mediastream_signaling_.SendAudioVideoStream2();
2846 SessionDescriptionInterface* answer =
2847 CreateRemoteAnswer(session_->local_description());
2848 SetRemoteDescriptionWithoutError(answer);
2849
deadbeefcbecd352015-09-23 11:50:27 -07002850 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2851 session_->video_rtp_transport_channel());
2852}
2853
2854// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
2855// audio content in the answer.
2856TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
2857 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2858 mediastream_signaling_.SendAudioVideoStream1();
2859
2860 PeerConnectionInterface::RTCOfferAnswerOptions options;
2861 options.use_rtp_mux = true;
2862
2863 SessionDescriptionInterface* offer = CreateOffer(options);
2864 SetLocalDescriptionWithoutError(offer);
2865
2866 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2867 session_->video_rtp_transport_channel());
2868
2869 mediastream_signaling_.SendAudioVideoStream2();
2870 cricket::MediaSessionOptions recv_options;
2871 recv_options.recv_audio = false;
2872 recv_options.recv_video = true;
2873 SessionDescriptionInterface* answer =
2874 CreateRemoteAnswer(session_->local_description(), recv_options);
2875 SetRemoteDescriptionWithoutError(answer);
2876
2877 EXPECT_TRUE(NULL == session_->voice_channel());
2878 EXPECT_TRUE(NULL != session_->video_rtp_transport_channel());
2879
2880 session_->Terminate();
2881 EXPECT_TRUE(NULL == session_->voice_rtp_transport_channel());
2882 EXPECT_TRUE(NULL == session_->voice_rtcp_transport_channel());
2883 EXPECT_TRUE(NULL == session_->video_rtp_transport_channel());
2884 EXPECT_TRUE(NULL == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002885}
2886
2887// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2888TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2889 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2890 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002891
Donald Curtis0e209b02015-03-24 09:29:54 -07002892 PeerConnectionInterface::RTCOfferAnswerOptions options;
2893 options.use_rtp_mux = true;
2894
2895 SessionDescriptionInterface* offer = CreateOffer(options);
2896 SetLocalDescriptionWithoutError(offer);
2897
deadbeefcbecd352015-09-23 11:50:27 -07002898 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2899 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002900
2901 mediastream_signaling_.SendAudioVideoStream2();
2902
2903 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002904 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 CreateRemoteAnswer(session_->local_description()));
2906 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2907 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2908 JsepSessionDescription* modified_answer =
2909 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2910 modified_answer->Initialize(answer_copy, "1", "1");
2911 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912
deadbeefcbecd352015-09-23 11:50:27 -07002913 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2914 session_->video_rtp_transport_channel());
2915}
2916
2917// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
2918TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
2919 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2920 mediastream_signaling_.SendAudioVideoStream1();
2921
2922 SessionDescriptionInterface* offer = CreateRemoteOffer();
2923 SetRemoteDescriptionWithoutError(offer);
2924
2925 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2926 session_->video_rtp_transport_channel());
2927
2928 mediastream_signaling_.SendAudioVideoStream2();
2929 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
2930 SetLocalDescriptionWithoutError(answer);
2931
2932 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2933 session_->video_rtp_transport_channel());
2934}
2935
2936// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
2937TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
2938 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2939 mediastream_signaling_.SendAudioVideoStream1();
2940
2941 // Remove BUNDLE from the offer.
2942 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2943 cricket::SessionDescription* offer_copy = offer->description()->Copy();
2944 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2945 JsepSessionDescription* modified_offer =
2946 new JsepSessionDescription(JsepSessionDescription::kOffer);
2947 modified_offer->Initialize(offer_copy, "1", "1");
2948
2949 // Expect an error when applying the remote description
2950 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
2951 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002952}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953
Peter Thatcher4eddf182015-04-30 10:55:59 -07002954// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002955TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2956 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2957 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958
Donald Curtis0e209b02015-03-24 09:29:54 -07002959 PeerConnectionInterface::RTCOfferAnswerOptions options;
2960 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961
Donald Curtis0e209b02015-03-24 09:29:54 -07002962 SessionDescriptionInterface* offer = CreateOffer(options);
2963 SetLocalDescriptionWithoutError(offer);
2964
deadbeefcbecd352015-09-23 11:50:27 -07002965 EXPECT_NE(session_->voice_rtp_transport_channel(),
2966 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002967
2968 mediastream_signaling_.SendAudioVideoStream2();
2969 SessionDescriptionInterface* answer =
2970 CreateRemoteAnswer(session_->local_description());
2971 SetRemoteDescriptionWithoutError(answer);
2972
2973 // This should lead to an audio-only call but isn't implemented
2974 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07002975 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2976 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002977}
2978
deadbeefcbecd352015-09-23 11:50:27 -07002979// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002980TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2981 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2982 mediastream_signaling_.SendAudioVideoStream1();
2983 PeerConnectionInterface::RTCOfferAnswerOptions options;
2984 options.use_rtp_mux = true;
2985
2986 SessionDescriptionInterface* offer = CreateOffer(options);
2987 SetLocalDescriptionWithoutError(offer);
2988
deadbeefcbecd352015-09-23 11:50:27 -07002989 EXPECT_NE(session_->voice_rtp_transport_channel(),
2990 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002991
2992 mediastream_signaling_.SendAudioVideoStream2();
2993
2994 // Remove BUNDLE from the answer.
2995 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2996 CreateRemoteAnswer(session_->local_description()));
2997 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2998 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2999 JsepSessionDescription* modified_answer =
3000 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3001 modified_answer->Initialize(answer_copy, "1", "1");
3002 SetRemoteDescriptionWithoutError(modified_answer); //
3003
deadbeefcbecd352015-09-23 11:50:27 -07003004 EXPECT_NE(session_->voice_rtp_transport_channel(),
3005 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006}
3007
Peter Thatcher4eddf182015-04-30 10:55:59 -07003008// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3009TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3010 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
3011 mediastream_signaling_.SendAudioVideoStream1();
3012
3013 PeerConnectionInterface::RTCOfferAnswerOptions options;
3014 options.use_rtp_mux = true;
3015
3016 SessionDescriptionInterface* offer = CreateOffer(options);
3017 SetRemoteDescriptionWithoutError(offer);
3018
deadbeefcbecd352015-09-23 11:50:27 -07003019 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3020 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003021}
3022
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003023TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3024 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
3025 mediastream_signaling_.SendAudioVideoStream1();
3026
3027 PeerConnectionInterface::RTCOfferAnswerOptions options;
3028 SessionDescriptionInterface* offer = CreateOffer(options);
3029 SetLocalDescriptionWithoutError(offer);
3030
deadbeefcbecd352015-09-23 11:50:27 -07003031 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3032 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003033
3034 mediastream_signaling_.SendAudioVideoStream2();
3035 SessionDescriptionInterface* answer =
3036 CreateRemoteAnswer(session_->local_description());
3037 SetRemoteDescriptionWithoutError(answer);
3038
deadbeefcbecd352015-09-23 11:50:27 -07003039 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3040 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003041}
3042
3043TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3044 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
3045 mediastream_signaling_.SendAudioVideoStream1();
3046
3047 PeerConnectionInterface::RTCOfferAnswerOptions options;
3048 SessionDescriptionInterface* offer = CreateOffer(options);
3049 SetLocalDescriptionWithoutError(offer);
3050
deadbeefcbecd352015-09-23 11:50:27 -07003051 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3052 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003053
3054 mediastream_signaling_.SendAudioVideoStream2();
3055 SessionDescriptionInterface* answer =
3056 CreateRemoteAnswer(session_->local_description());
3057 SetRemoteDescriptionWithoutError(answer);
3058
deadbeefcbecd352015-09-23 11:50:27 -07003059 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3060 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003061}
3062
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003063// This test verifies that SetLocalDescription and SetRemoteDescription fails
3064// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3065TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003066 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003067 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003068
3069 PeerConnectionInterface::RTCOfferAnswerOptions options;
3070 options.use_rtp_mux = true;
3071
3072 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003073 std::string offer_str;
3074 offer->ToString(&offer_str);
3075 // Disable rtcp-mux
3076 const std::string rtcp_mux = "rtcp-mux";
3077 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003078 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003079 xrtcp_mux.c_str(), xrtcp_mux.length(),
3080 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003081 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003082 new JsepSessionDescription(JsepSessionDescription::kOffer);
3083 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003084 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003085 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003086 new JsepSessionDescription(JsepSessionDescription::kOffer);
3087 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003088 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003089 // Trying unmodified SDP.
3090 SetLocalDescriptionWithoutError(offer);
3091}
3092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003094 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003095 mediastream_signaling_.SendAudioVideoStream1();
3096 CreateAndSetRemoteOfferAndLocalAnswer();
3097 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3098 ASSERT_TRUE(channel != NULL);
3099 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003100 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003101 double volume;
3102 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3103 EXPECT_EQ(1, volume);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003104 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003105 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
solenberg4bac9c52015-10-09 02:32:53 -07003106 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3107 EXPECT_EQ(0, volume);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003108 session_->SetAudioPlayout(receive_ssrc, true, NULL);
solenberg4bac9c52015-10-09 02:32:53 -07003109 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3110 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111}
3112
3113TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003114 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003115 mediastream_signaling_.SendAudioVideoStream1();
3116 CreateAndSetRemoteOfferAndLocalAnswer();
3117 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3118 ASSERT_TRUE(channel != NULL);
3119 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003120 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3122
3123 cricket::AudioOptions options;
3124 options.echo_cancellation.Set(true);
3125
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003126 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003127 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3129 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003130 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003132 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003133 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3135 bool value;
3136 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3137 EXPECT_TRUE(value);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003138 EXPECT_TRUE(renderer->sink() == NULL);
3139}
3140
3141TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003142 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003143 mediastream_signaling_.SendAudioVideoStream1();
3144 CreateAndSetRemoteOfferAndLocalAnswer();
3145 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3146 ASSERT_TRUE(channel != NULL);
3147 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003148 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003149
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003150 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003151 cricket::AudioOptions options;
3152 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3153 EXPECT_TRUE(renderer->sink() != NULL);
3154
3155 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3156 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3157 // SetSink(NULL) callback afterwards.
3158 renderer.reset();
3159
3160 // This will trigger SetSink(NULL) if no OnClose() callback.
3161 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162}
3163
3164TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003165 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166 mediastream_signaling_.SendAudioVideoStream1();
3167 CreateAndSetRemoteOfferAndLocalAnswer();
3168 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3169 ASSERT_TRUE(channel != NULL);
3170 ASSERT_LT(0u, channel->renderers().size());
3171 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3172 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003173 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174 cricket::FakeVideoRenderer renderer;
3175 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3176 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3177 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3178 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3179}
3180
3181TEST_F(WebRtcSessionTest, SetVideoSend) {
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_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003188 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3190 cricket::VideoOptions* options = NULL;
3191 session_->SetVideoSend(send_ssrc, false, options);
3192 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3193 session_->SetVideoSend(send_ssrc, true, options);
3194 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3195}
3196
3197TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3198 TestCanInsertDtmf(false);
3199}
3200
3201TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3202 TestCanInsertDtmf(true);
3203}
3204
3205TEST_F(WebRtcSessionTest, InsertDtmf) {
3206 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003207 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208 mediastream_signaling_.SendAudioVideoStream1();
3209 CreateAndSetRemoteOfferAndLocalAnswer();
3210 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3211 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3212
3213 // Insert DTMF
3214 const int expected_flags = DF_SEND;
3215 const int expected_duration = 90;
3216 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3217 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3218 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3219
3220 // Verify
3221 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003222 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003223 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3224 expected_duration, expected_flags));
3225 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3226 expected_duration, expected_flags));
3227 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3228 expected_duration, expected_flags));
3229}
3230
3231// This test verifies the |initiator| flag when session initiates the call.
3232TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003233 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003235 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3237 SetLocalDescriptionWithoutError(offer);
3238 EXPECT_TRUE(session_->initiator());
3239 SetRemoteDescriptionWithoutError(answer);
3240 EXPECT_TRUE(session_->initiator());
3241}
3242
3243// This test verifies the |initiator| flag when session receives the call.
3244TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003245 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003246 EXPECT_FALSE(session_->initiator());
3247 SessionDescriptionInterface* offer = CreateRemoteOffer();
3248 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003249 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250
3251 EXPECT_FALSE(session_->initiator());
3252 SetLocalDescriptionWithoutError(answer);
3253 EXPECT_FALSE(session_->initiator());
3254}
3255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3257TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003258 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003260 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003262 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 CreateRemoteAnswer(session_->local_description()));
3264
3265 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3266 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003267 JsepSessionDescription* modified_answer =
3268 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269
3270 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3271 answer->session_id(),
3272 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003273 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274
wu@webrtc.org4e393072014-04-07 17:04:35 +00003275 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 std::string sdp;
3277 EXPECT_TRUE(answer->ToString(&sdp));
3278 const std::string kAudioMid = "a=mid:audio";
3279 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003280 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281 kAudioMidReplaceStr.c_str(),
3282 kAudioMidReplaceStr.length(),
3283 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003284 SessionDescriptionInterface* modified_answer1 =
3285 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003286 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287
wu@webrtc.org4e393072014-04-07 17:04:35 +00003288 // Different media types.
3289 EXPECT_TRUE(answer->ToString(&sdp));
3290 const std::string kAudioMline = "m=audio";
3291 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003292 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003293 kAudioMlineReplaceStr.c_str(),
3294 kAudioMlineReplaceStr.length(),
3295 &sdp);
3296 SessionDescriptionInterface* modified_answer2 =
3297 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3298 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3299
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300 SetRemoteDescriptionWithoutError(answer.release());
3301}
3302
3303// Verifying remote offer and local answer have matching m-lines as per
3304// RFC 3264.
3305TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003306 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307 mediastream_signaling_.SendAudioVideoStream1();
3308 SessionDescriptionInterface* offer = CreateRemoteOffer();
3309 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003310 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311
3312 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3313 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003314 JsepSessionDescription* modified_answer =
3315 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003316
3317 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3318 answer->session_id(),
3319 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003320 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003321 SetLocalDescriptionWithoutError(answer);
3322}
3323
3324// This test verifies that WebRtcSession does not start candidate allocation
3325// before SetLocalDescription is called.
3326TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003327 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 mediastream_signaling_.SendAudioVideoStream1();
3329 SessionDescriptionInterface* offer = CreateRemoteOffer();
3330 cricket::Candidate candidate;
3331 candidate.set_component(1);
3332 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3333 candidate);
3334 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3335 cricket::Candidate candidate1;
3336 candidate1.set_component(1);
3337 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3338 candidate1);
3339 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3340 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003341 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3342 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343
3344 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003345 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3347 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3348
wu@webrtc.org91053e72013-08-10 07:18:04 +00003349 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3352}
3353
3354// This test verifies that crypto parameter is updated in local session
3355// description as per security policy set in MediaSessionDescriptionFactory.
3356TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003357 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003359 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360
3361 // Making sure SetLocalDescription correctly sets crypto value in
3362 // SessionDescription object after de-serialization of sdp string. The value
3363 // will be set as per MediaSessionDescriptionFactory.
3364 std::string offer_str;
3365 offer->ToString(&offer_str);
3366 SessionDescriptionInterface* jsep_offer_str =
3367 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3368 SetLocalDescriptionWithoutError(jsep_offer_str);
3369 EXPECT_TRUE(session_->voice_channel()->secure_required());
3370 EXPECT_TRUE(session_->video_channel()->secure_required());
3371}
3372
3373// This test verifies the crypto parameter when security is disabled.
3374TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003375 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003376 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003378 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379
3380 // Making sure SetLocalDescription correctly sets crypto value in
3381 // SessionDescription object after de-serialization of sdp string. The value
3382 // will be set as per MediaSessionDescriptionFactory.
3383 std::string offer_str;
3384 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003385 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3387 SetLocalDescriptionWithoutError(jsep_offer_str);
3388 EXPECT_FALSE(session_->voice_channel()->secure_required());
3389 EXPECT_FALSE(session_->video_channel()->secure_required());
3390}
3391
3392// This test verifies that an answer contains new ufrag and password if an offer
3393// with new ufrag and password is received.
3394TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003395 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003397 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003398 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 CreateRemoteOffer(options));
3400 SetRemoteDescriptionWithoutError(offer.release());
3401
3402 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003403 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003404 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405 SetLocalDescriptionWithoutError(answer.release());
3406
3407 // Receive an offer with new ufrag and password.
3408 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003409 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003410 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 SetRemoteDescriptionWithoutError(updated_offer1.release());
3412
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003413 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003414 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415
3416 CompareIceUfragAndPassword(updated_answer1->description(),
3417 session_->local_description()->description(),
3418 false);
3419
3420 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003421}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422
wu@webrtc.org91053e72013-08-10 07:18:04 +00003423// This test verifies that an answer contains old ufrag and password if an offer
3424// with old ufrag and password is received.
3425TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003426 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003427 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003428 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003429 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003430 CreateRemoteOffer(options));
3431 SetRemoteDescriptionWithoutError(offer.release());
3432
3433 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003434 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003435 CreateAnswer(NULL));
3436 SetLocalDescriptionWithoutError(answer.release());
3437
3438 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003440 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003441 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 SetRemoteDescriptionWithoutError(updated_offer2.release());
3443
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003444 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003445 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446
3447 CompareIceUfragAndPassword(updated_answer2->description(),
3448 session_->local_description()->description(),
3449 true);
3450
3451 SetLocalDescriptionWithoutError(updated_answer2.release());
3452}
3453
3454TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003455 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003457 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 const std::string session_id_orig = offer->session_id();
3459 const std::string session_version_orig = offer->session_version();
3460 SetLocalDescriptionWithoutError(offer);
3461
3462 video_channel_ = media_engine_->GetVideoChannel(0);
3463 video_channel_->set_fail_set_send_codecs(true);
3464
3465 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003466 SessionDescriptionInterface* answer =
3467 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003468 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469}
3470
3471// Runs the loopback call test with BUNDLE and STUN disabled.
3472TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3473 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003474 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003475 cricket::PORTALLOCATOR_DISABLE_STUN |
3476 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 TestLoopbackCall();
3478}
3479
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003480TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003481 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003482 cricket::PORTALLOCATOR_DISABLE_STUN |
3483 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3484 cricket::PORTALLOCATOR_DISABLE_RELAY);
3485
3486 // best connection is IPv6 since it has higher network preference.
3487 LoopbackNetworkConfiguration config;
3488 config.test_ipv6_network_ = true;
3489 config.best_connection_after_initial_ice_converged_ =
3490 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3491
3492 TestLoopbackCall(config);
3493}
3494
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003495// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003496TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003497 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3498 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003499 TestLoopbackCall();
3500}
3501
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003502TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003503 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003505 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003507 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3508 std::string error_code_str = "ERROR_CONTENT";
3509 std::string error_desc = "Fake session error description.";
3510 session_->SetError(error_code, error_desc);
3511
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3513 SessionDescriptionInterface* answer =
3514 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003515
3516 std::string action;
3517 std::ostringstream session_error_msg;
3518 session_error_msg << kSessionError << error_code_str << ". ";
3519 session_error_msg << kSessionErrorDesc << error_desc << ".";
3520 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3521 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522}
3523
3524TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3525 constraints_.reset(new FakeConstraints());
3526 constraints_->AddOptional(
3527 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003528 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529
3530 SetLocalDescriptionWithDataChannel();
3531 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3532}
3533
Henrik Boström87713d02015-08-25 09:53:21 +02003534TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003535 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536
3537 constraints_.reset(new FakeConstraints());
3538 constraints_->AddOptional(
3539 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003540 options_.disable_sctp_data_channels = false;
3541
Henrik Boström87713d02015-08-25 09:53:21 +02003542 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003543
3544 SetLocalDescriptionWithDataChannel();
3545 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3546}
3547
Henrik Boström87713d02015-08-25 09:53:21 +02003548TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003549 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003550
Henrik Boström87713d02015-08-25 09:53:21 +02003551 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003552
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003553 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003554 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003555 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3556}
3557
Henrik Boström87713d02015-08-25 09:53:21 +02003558TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003559 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003560 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003561 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003562
3563 // Create remote offer with SCTP.
3564 cricket::MediaSessionOptions options;
3565 options.data_channel_type = cricket::DCT_SCTP;
3566 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003567 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003568 SetRemoteDescriptionWithoutError(offer);
3569
3570 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003571 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003572 EXPECT_TRUE(answer != NULL);
3573 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3574 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003575}
3576
Henrik Boström87713d02015-08-25 09:53:21 +02003577TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 constraints_.reset(new FakeConstraints());
3579 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003580 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003581 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582
3583 SetLocalDescriptionWithDataChannel();
3584 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3585}
3586
Henrik Boström87713d02015-08-25 09:53:21 +02003587TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003588 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589
Henrik Boström87713d02015-08-25 09:53:21 +02003590 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591
3592 SetLocalDescriptionWithDataChannel();
3593 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3594}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003595
Henrik Boström87713d02015-08-25 09:53:21 +02003596TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003597 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003598 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003599 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003600
3601 SetLocalDescriptionWithDataChannel();
3602 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3603}
3604
Henrik Boström87713d02015-08-25 09:53:21 +02003605TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003606 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003607 const int new_send_port = 9998;
3608 const int new_recv_port = 7775;
3609
Henrik Boström87713d02015-08-25 09:53:21 +02003610 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003611 SetFactoryDtlsSrtp();
3612
3613 // By default, don't actually add the codecs to desc_factory_; they don't
3614 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3615 // let the session description get parsed. That'll get the proper codecs
3616 // into the stream.
3617 cricket::MediaSessionOptions options;
3618 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3619 "stream1", new_send_port, options);
3620
3621 // SetRemoteDescription will take the ownership of the offer.
3622 SetRemoteDescriptionWithoutError(offer);
3623
3624 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3625 new_recv_port, CreateAnswer(NULL));
3626 ASSERT_TRUE(answer != NULL);
3627
3628 // Now set the local description, which'll take ownership of the answer.
3629 SetLocalDescriptionWithoutError(answer);
3630
3631 // TEST PLAN: Set the port number to something new, set it in the SDP,
3632 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003633 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003634 dci.reliable = true;
3635 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003636 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003637 session_->CreateDataChannel("datachannel", &dci);
3638
3639 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3640 int portnum = -1;
3641 ASSERT_TRUE(ch != NULL);
3642 ASSERT_EQ(1UL, ch->send_codecs().size());
3643 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003644 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003645 ch->send_codecs()[0].name.c_str()));
3646 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3647 &portnum));
3648 EXPECT_EQ(new_send_port, portnum);
3649
3650 ASSERT_EQ(1UL, ch->recv_codecs().size());
3651 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003652 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003653 ch->recv_codecs()[0].name.c_str()));
3654 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3655 &portnum));
3656 EXPECT_EQ(new_recv_port, portnum);
3657}
3658
Henrik Boströmd8281982015-08-27 10:12:24 +02003659TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3660 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3661 FakeDtlsIdentityStore::GenerateCertificate();
3662
3663 PeerConnectionInterface::RTCConfiguration configuration;
3664 configuration.certificates.push_back(certificate);
3665 Init(nullptr, configuration);
3666 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3667
3668 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3669}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670
Henrik Boström87713d02015-08-25 09:53:21 +02003671// Verifies that CreateOffer succeeds when CreateOffer is called before async
3672// identity generation is finished (even if a certificate is provided this is
3673// an async op).
3674TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3675 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3676 InitWithDtls(GetParam());
3677
Henrik Boströmd8281982015-08-27 10:12:24 +02003678 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003679 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003680 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3681
wu@webrtc.org91053e72013-08-10 07:18:04 +00003682 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003683 VerifyNoCryptoParams(offer->description(), true);
3684 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003685}
3686
3687// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003688// identity generation is finished (even if a certificate is provided this is
3689// an async op).
3690TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003691 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003692 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003693 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003694
3695 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003696 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003697 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003698 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003699 ASSERT_TRUE(offer.get() != NULL);
3700 SetRemoteDescriptionWithoutError(offer.release());
3701
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003702 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003703 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003704 VerifyNoCryptoParams(answer->description(), true);
3705 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003706}
3707
3708// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003709// identity generation is finished (even if a certificate is provided this is
3710// an async op).
3711TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003712 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003713 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003714
Henrik Boströmd8281982015-08-27 10:12:24 +02003715 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003716
3717 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003718 EXPECT_TRUE(offer != NULL);
3719}
3720
3721// Verifies that CreateOffer fails when CreateOffer is called after async
3722// identity generation fails.
3723TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003724 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003725 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003726
Henrik Boströmd8281982015-08-27 10:12:24 +02003727 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003728
3729 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003730 EXPECT_TRUE(offer == NULL);
3731}
3732
3733// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3734// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003735TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003736 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003737 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003738 VerifyMultipleAsyncCreateDescription(GetParam(),
3739 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003740}
3741
3742// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3743// before async identity generation fails.
3744TEST_F(WebRtcSessionTest,
3745 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003746 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003747 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3748 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003749}
3750
3751// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3752// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003753TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003754 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003755 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003756 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003757 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003758}
3759
3760// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3761// before async identity generation fails.
3762TEST_F(WebRtcSessionTest,
3763 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003764 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003765 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3766 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003767}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003768
3769// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3770// offer has no SDES crypto but only DTLS fingerprint.
3771TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3772 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003773 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003774 // Create a remote offer with secured transport disabled.
3775 cricket::MediaSessionOptions options;
3776 JsepSessionDescription* offer(CreateRemoteOffer(
3777 options, cricket::SEC_DISABLED));
3778 // Adds a DTLS fingerprint to the remote offer.
3779 cricket::SessionDescription* sdp = offer->description();
3780 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3781 ASSERT_TRUE(audio != NULL);
3782 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3783 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003784 rtc::SSLFingerprint::CreateFromRfc4572(
3785 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003786 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003787 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003788}
3789
wu@webrtc.orgde305012013-10-31 15:40:38 +00003790// This test verifies DSCP is properly applied on the media channels.
3791TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3792 constraints_.reset(new FakeConstraints());
3793 constraints_->AddOptional(
3794 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003795 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003796 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003797 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003798
3799 SetLocalDescriptionWithoutError(offer);
3800
3801 video_channel_ = media_engine_->GetVideoChannel(0);
3802 voice_channel_ = media_engine_->GetVoiceChannel(0);
3803
3804 ASSERT_TRUE(video_channel_ != NULL);
3805 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003806 const cricket::AudioOptions& audio_options = voice_channel_->options();
3807 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003808 EXPECT_TRUE(audio_options.dscp.IsSet());
3809 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3810 EXPECT_TRUE(video_options.dscp.IsSet());
3811 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3812}
3813
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003814TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3815 constraints_.reset(new FakeConstraints());
3816 constraints_->AddOptional(
3817 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3818 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003819 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003820 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003821 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003822
3823 SetLocalDescriptionWithoutError(offer);
3824
3825 video_channel_ = media_engine_->GetVideoChannel(0);
3826
3827 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003828 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003829 EXPECT_TRUE(
3830 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3831}
3832
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003833TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3834 // Number of unsignalled receiving streams should be between 0 and
3835 // kMaxUnsignalledRecvStreams.
3836 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3837 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3838 kMaxUnsignalledRecvStreams);
3839 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3840}
3841
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003842TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3843 constraints_.reset(new FakeConstraints());
3844 constraints_->AddOptional(
3845 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3846 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003847 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003848 mediastream_signaling_.SendAudioVideoStream1();
3849 SessionDescriptionInterface* offer = CreateOffer();
3850
3851 SetLocalDescriptionWithoutError(offer);
3852
3853 voice_channel_ = media_engine_->GetVoiceChannel(0);
3854
3855 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003856 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003857 EXPECT_TRUE(
3858 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3859}
3860
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003861// Tests that we can renegotiate new media content with ICE candidates in the
3862// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003863TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003864 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003865 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003866 SetFactoryDtlsSrtp();
3867
3868 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003869 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003870 SetLocalDescriptionWithoutError(offer);
3871
3872 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3873 SetRemoteDescriptionWithoutError(answer);
3874
3875 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003876 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003877 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3878
3879 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003880 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003881 candidate1.set_component(1);
3882 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3883 candidate1);
3884 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3885 SetRemoteDescriptionWithoutError(offer);
3886
3887 answer = CreateAnswer(NULL);
3888 SetLocalDescriptionWithoutError(answer);
3889}
3890
3891// Tests that we can renegotiate new media content with ICE candidates separated
3892// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003893TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003894 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003895 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003896 SetFactoryDtlsSrtp();
3897
3898 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003899 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003900 SetLocalDescriptionWithoutError(offer);
3901
3902 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3903 SetRemoteDescriptionWithoutError(answer);
3904
3905 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003906 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003907 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3908 SetRemoteDescriptionWithoutError(offer);
3909
3910 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003911 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003912 candidate1.set_component(1);
3913 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3914 candidate1);
3915 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3916
3917 answer = CreateAnswer(NULL);
3918 SetLocalDescriptionWithoutError(answer);
3919}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003920// Tests that RTX codec is removed from the answer when it isn't supported
3921// by local side.
3922TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3923 Init();
3924 mediastream_signaling_.SendAudioVideoStream1();
3925 std::string offer_sdp(kSdpWithRtx);
3926
3927 SessionDescriptionInterface* offer =
3928 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3929 EXPECT_TRUE(offer->ToString(&offer_sdp));
3930
3931 // Offer SDP contains the RTX codec.
3932 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3933 SetRemoteDescriptionWithoutError(offer);
3934
3935 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3936 std::string answer_sdp;
3937 answer->ToString(&answer_sdp);
3938 // Answer SDP removes the unsupported RTX codec.
3939 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3940 SetLocalDescriptionWithoutError(answer);
3941}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003942
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003943// This verifies that the voice channel after bundle has both options from video
3944// and voice channels.
3945TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3946 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3947 mediastream_signaling_.SendAudioVideoStream1();
3948
3949 PeerConnectionInterface::RTCOfferAnswerOptions options;
3950 options.use_rtp_mux = true;
3951
3952 SessionDescriptionInterface* offer = CreateOffer(options);
3953 SetLocalDescriptionWithoutError(offer);
3954
3955 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3956 rtc::Socket::Option::OPT_SNDBUF, 4000);
3957
3958 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3959 rtc::Socket::Option::OPT_RCVBUF, 8000);
3960
3961 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07003962 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003963 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3964 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003965 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003966 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3967
deadbeefcbecd352015-09-23 11:50:27 -07003968 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003969 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3970 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003971 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003972 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3973
deadbeefcbecd352015-09-23 11:50:27 -07003974 EXPECT_NE(session_->voice_rtp_transport_channel(),
3975 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003976
3977 mediastream_signaling_.SendAudioVideoStream2();
3978 SessionDescriptionInterface* answer =
3979 CreateRemoteAnswer(session_->local_description());
3980 SetRemoteDescriptionWithoutError(answer);
3981
deadbeefcbecd352015-09-23 11:50:27 -07003982 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003983 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3984 EXPECT_EQ(4000, option_val);
3985
deadbeefcbecd352015-09-23 11:50:27 -07003986 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003987 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3988 EXPECT_EQ(8000, option_val);
3989}
3990
tommi0f620f42015-07-09 03:25:02 -07003991// Test creating a session, request multiple offers, destroy the session
3992// and make sure we got success/failure callbacks for all of the requests.
3993// Background: crbug.com/507307
3994TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3995 Init();
3996
3997 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3998 PeerConnectionInterface::RTCOfferAnswerOptions options;
3999 options.offer_to_receive_audio =
4000 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
4001
4002 for (auto& o : observers) {
4003 o = new WebRtcSessionCreateSDPObserverForTest();
4004 session_->CreateOffer(o, options);
4005 }
4006
4007 session_.reset();
4008
tommi0f620f42015-07-09 03:25:02 -07004009 for (auto& o : observers) {
4010 // We expect to have received a notification now even if the session was
4011 // terminated. The offer creation may or may not have succeeded, but we
4012 // must have received a notification which, so the only invalid state
4013 // is kInit.
4014 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4015 }
4016}
4017
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004018// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4019// currently fails because upon disconnection and reconnection OnIceComplete is
4020// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004021
deadbeefcbecd352015-09-23 11:50:27 -07004022INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4023 WebRtcSessionTest,
4024 testing::Values(ALREADY_GENERATED,
4025 DTLS_IDENTITY_STORE));