blob: 1e1785fe5752f7ba4886d71b75eaa0e99d83f55f [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
28#include "talk/app/webrtc/audiotrack.h"
jbauchac8869e2015-07-03 01:36:14 -070029#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/jsepicecandidate.h"
31#include "talk/app/webrtc/jsepsessiondescription.h"
32#include "talk/app/webrtc/mediastreamsignaling.h"
33#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020035#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000036#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000039#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "talk/media/base/fakemediaengine.h"
41#include "talk/media/base/fakevideorenderer.h"
42#include "talk/media/base/mediachannel.h"
43#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000047#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/channelmanager.h"
50#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051#include "webrtc/base/fakenetwork.h"
52#include "webrtc/base/firewallsocketserver.h"
53#include "webrtc/base/gunit.h"
54#include "webrtc/base/logging.h"
55#include "webrtc/base/network.h"
56#include "webrtc/base/physicalsocketserver.h"
57#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020058#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059#include "webrtc/base/sslstreamadapter.h"
60#include "webrtc/base/stringutils.h"
61#include "webrtc/base/thread.h"
62#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64#define MAYBE_SKIP_TEST(feature) \
65 if (!(feature())) { \
66 LOG(LS_INFO) << "Feature disabled... skipping"; \
67 return; \
68 }
69
70using cricket::BaseSession;
71using cricket::DF_PLAY;
72using cricket::DF_SEND;
73using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075using rtc::SocketAddress;
76using rtc::scoped_ptr;
77using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::CreateSessionDescriptionObserver;
80using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020081using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070083using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::IceCandidateCollection;
85using webrtc::JsepIceCandidate;
86using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000087using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::PeerConnectionInterface;
89using webrtc::SessionDescriptionInterface;
90using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000091using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kCreateChannelFailed;
94using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000096using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000098using webrtc::kSdpWithoutDtlsFingerprint;
99using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000102using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000104typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
105
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106static const int kClientAddrPort = 0;
107static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000108static const char kClientIPv6AddrHost1[] =
109 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const char kClientAddrHost2[] = "22.22.22.22";
111static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000112static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
113static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000114static const char kTurnUsername[] = "test";
115static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117static const char kSessionVersion[] = "1";
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119// Media index of candidates belonging to the first media content.
120static const int kMediaContentIndex0 = 0;
121static const char kMediaContentName0[] = "audio";
122
123// Media index of candidates belonging to the second media content.
124static const int kMediaContentIndex1 = 1;
125static const char kMediaContentName1[] = "video";
126
127static const int kIceCandidatesTimeout = 10000;
128
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000129static const char kFakeDtlsFingerprint[] =
130 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
131 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
132
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000133static const char kTooLongIceUfragPwd[] =
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
138
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000139static const char kSdpWithRtx[] =
140 "v=0\r\n"
141 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
142 "s=-\r\n"
143 "t=0 0\r\n"
144 "a=msid-semantic: WMS stream1\r\n"
145 "m=video 9 RTP/SAVPF 0 96\r\n"
146 "c=IN IP4 0.0.0.0\r\n"
147 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
148 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
149 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
150 "a=mid:video\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
153 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
154 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
155 "a=rtpmap:0 fake_video_codec/90000\r\n"
156 "a=rtpmap:96 rtx/90000\r\n"
157 "a=fmtp:96 apt=0\r\n";
158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159// Add some extra |newlines| to the |message| after |line|.
160static void InjectAfter(const std::string& line,
161 const std::string& newlines,
162 std::string* message) {
163 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 tmp.c_str(), tmp.length(), message);
166}
167
168class MockIceObserver : public webrtc::IceObserver {
169 public:
170 MockIceObserver()
171 : oncandidatesready_(false),
172 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
173 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
174 }
175
176 virtual void OnIceConnectionChange(
177 PeerConnectionInterface::IceConnectionState new_state) {
178 ice_connection_state_ = new_state;
179 }
180 virtual void OnIceGatheringChange(
181 PeerConnectionInterface::IceGatheringState new_state) {
182 // We can never transition back to "new".
183 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
184 ice_gathering_state_ = new_state;
185
186 // oncandidatesready_ really means "ICE gathering is complete".
187 // This if statement ensures that this value remains correct when we
188 // transition from kIceGatheringComplete to kIceGatheringGathering.
189 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
190 oncandidatesready_ = false;
191 }
192 }
193
194 // Found a new candidate.
195 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000196 switch (candidate->sdp_mline_index()) {
197 case kMediaContentIndex0:
198 mline_0_candidates_.push_back(candidate->candidate());
199 break;
200 case kMediaContentIndex1:
201 mline_1_candidates_.push_back(candidate->candidate());
202 break;
203 default:
204 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000206
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 // The ICE gathering state should always be Gathering when a candidate is
208 // received (or possibly Completed in the case of the final candidate).
209 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
210 }
211
212 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
213 virtual void OnIceComplete() {
214 EXPECT_FALSE(oncandidatesready_);
215 oncandidatesready_ = true;
216
217 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
218 // be called approximately simultaneously. For ease of testing, this
219 // check additionally requires that they be called in the above order.
220 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
221 ice_gathering_state_);
222 }
223
224 bool oncandidatesready_;
225 std::vector<cricket::Candidate> mline_0_candidates_;
226 std::vector<cricket::Candidate> mline_1_candidates_;
227 PeerConnectionInterface::IceConnectionState ice_connection_state_;
228 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
229};
230
231class WebRtcSessionForTest : public webrtc::WebRtcSession {
232 public:
233 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000234 rtc::Thread* signaling_thread,
235 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 cricket::PortAllocator* port_allocator,
237 webrtc::IceObserver* ice_observer,
238 webrtc::MediaStreamSignaling* mediastream_signaling)
239 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
240 mediastream_signaling) {
241 RegisterIceObserver(ice_observer);
242 }
243 virtual ~WebRtcSessionForTest() {}
244
245 using cricket::BaseSession::GetTransportProxy;
246 using webrtc::WebRtcSession::SetAudioPlayout;
247 using webrtc::WebRtcSession::SetAudioSend;
248 using webrtc::WebRtcSession::SetCaptureDevice;
249 using webrtc::WebRtcSession::SetVideoPlayout;
250 using webrtc::WebRtcSession::SetVideoSend;
251};
252
wu@webrtc.org91053e72013-08-10 07:18:04 +0000253class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000256 enum State {
257 kInit,
258 kFailed,
259 kSucceeded,
260 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000261 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262
263 // CreateSessionDescriptionObserver implementation.
264 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000265 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000266 state_ = kSucceeded;
267 }
268 virtual void OnFailure(const std::string& error) {
269 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 }
271
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000272 SessionDescriptionInterface* description() { return description_.get(); }
273
274 SessionDescriptionInterface* ReleaseDescription() {
275 return description_.release();
276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 protected:
281 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282
283 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000284 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286};
287
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000288class FakeAudioRenderer : public cricket::AudioRenderer {
289 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000290 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
291 virtual ~FakeAudioRenderer() {
292 if (sink_)
293 sink_->OnClose();
294 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000295
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000296 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297 ASSERT(channel_id_ == -1);
298 channel_id_ = channel_id;
299 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000300 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301 ASSERT(channel_id == channel_id_);
302 channel_id_ = -1;
303 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000304 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305
306 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000307 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308 private:
309 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000310 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311};
312
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313class WebRtcSessionTest : public testing::Test {
314 protected:
315 // TODO Investigate why ChannelManager crashes, if it's created
316 // after stun_server.
317 WebRtcSessionTest()
318 : media_engine_(new cricket::FakeMediaEngine()),
319 data_engine_(new cricket::FakeDataEngine()),
320 device_manager_(new cricket::FakeDeviceManager()),
321 channel_manager_(new cricket::ChannelManager(
322 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000323 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 tdesc_factory_(new cricket::TransportDescriptionFactory()),
325 desc_factory_(new cricket::MediaSessionDescriptionFactory(
326 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000327 pss_(new rtc::PhysicalSocketServer),
328 vss_(new rtc::VirtualSocketServer(pss_.get())),
329 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000332 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000333 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
334 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000335 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700336 mediastream_signaling_(channel_manager_.get()),
337 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000338 cricket::ServerAddresses stun_servers;
339 stun_servers.insert(stun_socket_addr_);
340 allocator_.reset(new cricket::BasicPortAllocator(
341 &network_manager_,
342 stun_servers,
343 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000344 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher2159b892015-08-21 20:46:05 -0700345 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 EXPECT_TRUE(channel_manager_->Init());
347 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000348 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350
351 void AddInterface(const SocketAddress& addr) {
352 network_manager_.AddInterface(addr);
353 }
354
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000355 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200356 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200357 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 ASSERT_TRUE(session_.get() == NULL);
359 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000360 channel_manager_.get(), rtc::Thread::Current(),
361 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 &observer_,
363 &mediastream_signaling_));
364
365 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
366 observer_.ice_connection_state_);
367 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
368 observer_.ice_gathering_state_);
369
Henrik Boström5e56c592015-08-11 10:33:13 +0200370 EXPECT_TRUE(session_->Initialize(
371 options_, constraints_.get(), dtls_identity_store.Pass(),
372 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700373 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 }
375
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000376 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200377 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200378 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000379 }
380
381 void InitWithIceTransport(
382 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200383 PeerConnectionInterface::RTCConfiguration configuration;
384 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200385 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000386 }
387
388 void InitWithBundlePolicy(
389 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200390 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200391 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200392 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700393 }
394
395 void InitWithRtcpMuxPolicy(
396 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
397 PeerConnectionInterface::RTCConfiguration configuration;
398 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200399 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000400 }
401
402 void InitWithDtls(bool identity_request_should_fail = false) {
Henrik Boström5e56c592015-08-11 10:33:13 +0200403 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
404 new FakeDtlsIdentityStore());
405 dtls_identity_store->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200406 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200407 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000408 }
409
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 void InitWithDtmfCodec() {
411 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000412 const cricket::AudioCodec kTelephoneEventCodec(
413 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 std::vector<cricket::AudioCodec> codecs;
415 codecs.push_back(kTelephoneEventCodec);
416 media_engine_->SetAudioCodecs(codecs);
417 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 }
420
421 // Creates a local offer and applies it. Starts ice.
422 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
423 // to decide which streams to create.
424 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000425 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 SetLocalDescriptionWithoutError(offer);
427 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
428 observer_.ice_gathering_state_,
429 kIceCandidatesTimeout);
430 }
431
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000432 SessionDescriptionInterface* CreateOffer() {
433 PeerConnectionInterface::RTCOfferAnswerOptions options;
434 options.offer_to_receive_audio =
435 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
436
437 return CreateOffer(options);
438 }
439
wu@webrtc.org91053e72013-08-10 07:18:04 +0000440 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000441 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000442 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000443 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000444 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000445 EXPECT_TRUE_WAIT(
446 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000447 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000448 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000449 }
450
451 SessionDescriptionInterface* CreateAnswer(
452 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000453 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000454 = new WebRtcSessionCreateSDPObserverForTest();
455 session_->CreateAnswer(observer, constraints);
456 EXPECT_TRUE_WAIT(
457 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000458 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000459 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000460 }
461
wu@webrtc.org364f2042013-11-20 21:49:41 +0000462 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 return (session_->voice_channel() != NULL &&
464 session_->video_channel() != NULL);
465 }
466
wu@webrtc.org364f2042013-11-20 21:49:41 +0000467 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
469 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
470 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
471 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
472 }
473
474 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
475 ASSERT_TRUE(session_.get() != NULL);
476 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
477 ASSERT_TRUE(content != NULL);
478 const cricket::AudioContentDescription* audio_content =
479 static_cast<const cricket::AudioContentDescription*>(
480 content->description);
481 ASSERT_TRUE(audio_content != NULL);
482 ASSERT_EQ(1U, audio_content->cryptos().size());
483 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
484 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
485 audio_content->cryptos()[0].cipher_suite);
486 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
487 audio_content->protocol());
488
489 content = cricket::GetFirstVideoContent(sdp);
490 ASSERT_TRUE(content != NULL);
491 const cricket::VideoContentDescription* video_content =
492 static_cast<const cricket::VideoContentDescription*>(
493 content->description);
494 ASSERT_TRUE(video_content != NULL);
495 ASSERT_EQ(1U, video_content->cryptos().size());
496 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
497 video_content->cryptos()[0].cipher_suite);
498 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
499 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
500 video_content->protocol());
501 }
502
503 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
504 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
505 ASSERT_TRUE(content != NULL);
506 const cricket::AudioContentDescription* audio_content =
507 static_cast<const cricket::AudioContentDescription*>(
508 content->description);
509 ASSERT_TRUE(audio_content != NULL);
510 ASSERT_EQ(0U, audio_content->cryptos().size());
511
512 content = cricket::GetFirstVideoContent(sdp);
513 ASSERT_TRUE(content != NULL);
514 const cricket::VideoContentDescription* video_content =
515 static_cast<const cricket::VideoContentDescription*>(
516 content->description);
517 ASSERT_TRUE(video_content != NULL);
518 ASSERT_EQ(0U, video_content->cryptos().size());
519
520 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700521 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700523 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 video_content->protocol());
525 } else {
526 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
527 audio_content->protocol());
528 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
529 video_content->protocol());
530 }
531 }
532
533 // Set the internal fake description factories to do DTLS-SRTP.
534 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000535 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000537 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200538 // Confirmed to work with KT_RSA and KT_ECDSA.
539 identity_.reset(rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000540 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
542 }
543
544 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
545 bool expected) {
546 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
547 ASSERT_TRUE(audio != NULL);
548 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 const TransportInfo* video = sdp->GetTransportInfoByName("video");
550 ASSERT_TRUE(video != NULL);
551 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 }
553
554 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000555 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000557 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000558 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000560 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000562 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
563 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000564 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 // Answer should be NULL as no crypto params in offer.
566 ASSERT_TRUE(answer == NULL);
567 }
568
569 void VerifyAnswerFromCryptoOffer() {
570 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000571 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 options.bundle_enabled = true;
573 scoped_ptr<JsepSessionDescription> offer(
574 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
575 ASSERT_TRUE(offer.get() != NULL);
576 VerifyCryptoParams(offer->description());
577 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000578 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 ASSERT_TRUE(answer.get() != NULL);
580 VerifyCryptoParams(answer->description());
581 }
582
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000583 void SetAndVerifyNumUnsignalledRecvStreams(
584 int value_set, int value_expected) {
585 constraints_.reset(new FakeConstraints());
586 constraints_->AddOptional(
587 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
588 value_set);
589 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000590 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000591 mediastream_signaling_.SendAudioVideoStream1();
592 SessionDescriptionInterface* offer = CreateOffer();
593
594 SetLocalDescriptionWithoutError(offer);
595
596 video_channel_ = media_engine_->GetVideoChannel(0);
597
598 ASSERT_TRUE(video_channel_ != NULL);
599 cricket::VideoOptions video_options;
600 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
601 EXPECT_EQ(value_expected,
602 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
603 }
604
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
606 const cricket::SessionDescription* desc2,
607 bool expect_equal) {
608 if (desc1->contents().size() != desc2->contents().size()) {
609 EXPECT_FALSE(expect_equal);
610 return;
611 }
612
613 const cricket::ContentInfos& contents = desc1->contents();
614 cricket::ContentInfos::const_iterator it = contents.begin();
615
616 for (; it != contents.end(); ++it) {
617 const cricket::TransportDescription* transport_desc1 =
618 desc1->GetTransportDescriptionByName(it->name);
619 const cricket::TransportDescription* transport_desc2 =
620 desc2->GetTransportDescriptionByName(it->name);
621 if (!transport_desc1 || !transport_desc2) {
622 EXPECT_FALSE(expect_equal);
623 return;
624 }
625 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
626 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
627 EXPECT_FALSE(expect_equal);
628 return;
629 }
630 }
631 EXPECT_TRUE(expect_equal);
632 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000633
634 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
635 std::string *sdp) {
636 const cricket::SessionDescription* desc = current_desc->description();
637 EXPECT_TRUE(current_desc->ToString(sdp));
638
639 const cricket::ContentInfos& contents = desc->contents();
640 cricket::ContentInfos::const_iterator it = contents.begin();
641 // Replace ufrag and pwd lines with empty strings.
642 for (; it != contents.end(); ++it) {
643 const cricket::TransportDescription* transport_desc =
644 desc->GetTransportDescriptionByName(it->name);
645 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
646 + "\r\n";
647 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
648 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000650 "", 0,
651 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000652 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000653 "", 0,
654 sdp);
655 }
656 }
657
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000658 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
659 const std::string& modified_ice_ufrag,
660 const std::string& modified_ice_pwd,
661 std::string* sdp) {
662 const cricket::SessionDescription* desc = current_desc->description();
663 EXPECT_TRUE(current_desc->ToString(sdp));
664
665 const cricket::ContentInfos& contents = desc->contents();
666 cricket::ContentInfos::const_iterator it = contents.begin();
667 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
668 // |modified_ice_pwd| strings.
669 for (; it != contents.end(); ++it) {
670 const cricket::TransportDescription* transport_desc =
671 desc->GetTransportDescriptionByName(it->name);
672 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
673 + "\r\n";
674 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
675 + "\r\n";
676 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
677 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000679 mod_ufrag.c_str(), mod_ufrag.length(),
680 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000681 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000682 mod_pwd.c_str(), mod_pwd.length(),
683 sdp);
684 }
685 }
686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 // Creates a remote offer and and applies it as a remote description,
688 // creates a local answer and applies is as a local description.
689 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
690 // to decide which local and remote streams to create.
691 void CreateAndSetRemoteOfferAndLocalAnswer() {
692 SessionDescriptionInterface* offer = CreateRemoteOffer();
693 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000694 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 SetLocalDescriptionWithoutError(answer);
696 }
697 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
698 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
699 }
700 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
701 BaseSession::State expected_state) {
702 SetLocalDescriptionWithoutError(desc);
703 EXPECT_EQ(expected_state, session_->state());
704 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000705 void SetLocalDescriptionExpectError(const std::string& action,
706 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 SessionDescriptionInterface* desc) {
708 std::string error;
709 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000710 std::string sdp_type = "local ";
711 sdp_type.append(action);
712 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 EXPECT_NE(std::string::npos, error.find(expected_error));
714 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000715 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
716 SessionDescriptionInterface* desc) {
717 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
718 expected_error, desc);
719 }
720 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
721 SessionDescriptionInterface* desc) {
722 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
723 expected_error, desc);
724 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
726 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
727 }
728 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
729 BaseSession::State expected_state) {
730 SetRemoteDescriptionWithoutError(desc);
731 EXPECT_EQ(expected_state, session_->state());
732 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000733 void SetRemoteDescriptionExpectError(const std::string& action,
734 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 SessionDescriptionInterface* desc) {
736 std::string error;
737 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000738 std::string sdp_type = "remote ";
739 sdp_type.append(action);
740 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 EXPECT_NE(std::string::npos, error.find(expected_error));
742 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 void SetRemoteDescriptionOfferExpectError(
744 const std::string& expected_error, SessionDescriptionInterface* desc) {
745 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
746 expected_error, desc);
747 }
748 void SetRemoteDescriptionPranswerExpectError(
749 const std::string& expected_error, SessionDescriptionInterface* desc) {
750 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
751 expected_error, desc);
752 }
753 void SetRemoteDescriptionAnswerExpectError(
754 const std::string& expected_error, SessionDescriptionInterface* desc) {
755 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
756 expected_error, desc);
757 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758
759 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
760 SessionDescriptionInterface** nocrypto_answer) {
761 // Create a SDP without Crypto.
762 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000763 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 options.bundle_enabled = true;
765 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
766 ASSERT_TRUE(*offer != NULL);
767 VerifyCryptoParams((*offer)->description());
768
769 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
770 cricket::SEC_DISABLED);
771 EXPECT_TRUE(*nocrypto_answer != NULL);
772 }
773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000774 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
775 SessionDescriptionInterface** nodtls_answer) {
776 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000777 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000778 options.bundle_enabled = true;
779
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000780 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000781 CreateRemoteOffer(options, cricket::SEC_ENABLED));
782
783 *nodtls_answer =
784 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
785 EXPECT_TRUE(*nodtls_answer != NULL);
786 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
787 VerifyCryptoParams((*nodtls_answer)->description());
788
789 SetFactoryDtlsSrtp();
790 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
791 ASSERT_TRUE(*offer != NULL);
792 VerifyFingerprintStatus((*offer)->description(), true);
793 VerifyCryptoParams((*offer)->description());
794 }
795
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 JsepSessionDescription* CreateRemoteOfferWithVersion(
797 cricket::MediaSessionOptions options,
798 cricket::SecurePolicy secure_policy,
799 const std::string& session_version,
800 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000801 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 const cricket::SessionDescription* cricket_desc = NULL;
803 if (current_desc) {
804 cricket_desc = current_desc->description();
805 session_id = current_desc->session_id();
806 }
807
808 desc_factory_->set_secure(secure_policy);
809 JsepSessionDescription* offer(
810 new JsepSessionDescription(JsepSessionDescription::kOffer));
811 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
812 session_id, session_version)) {
813 delete offer;
814 offer = NULL;
815 }
816 return offer;
817 }
818 JsepSessionDescription* CreateRemoteOffer(
819 cricket::MediaSessionOptions options) {
820 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
821 kSessionVersion, NULL);
822 }
823 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000824 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
825 return CreateRemoteOfferWithVersion(
826 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 }
828 JsepSessionDescription* CreateRemoteOffer(
829 cricket::MediaSessionOptions options,
830 const SessionDescriptionInterface* current_desc) {
831 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
832 kSessionVersion, current_desc);
833 }
834
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000835 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
836 const char* sctp_stream_name, int new_port,
837 cricket::MediaSessionOptions options) {
838 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000839 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
840 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000841 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
842 }
843
844 // Takes ownership of offer_basis (and deletes it).
845 JsepSessionDescription* ChangeSDPSctpPort(
846 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
847 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
848 // SessionDescription from the mutated string.
849 const char* default_port_str = "5000";
850 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000852 std::string offer_str;
853 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000854 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000855 new_port_str, strlen(new_port_str),
856 &offer_str);
857 JsepSessionDescription* offer = new JsepSessionDescription(
858 offer_basis->type());
859 delete offer_basis;
860 offer->Initialize(offer_str, NULL);
861 return offer;
862 }
863
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
865 // before this function to decide which streams to create.
866 JsepSessionDescription* CreateRemoteOffer() {
867 cricket::MediaSessionOptions options;
868 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
869 return CreateRemoteOffer(options, session_->remote_description());
870 }
871
872 JsepSessionDescription* CreateRemoteAnswer(
873 const SessionDescriptionInterface* offer,
874 cricket::MediaSessionOptions options,
875 cricket::SecurePolicy policy) {
876 desc_factory_->set_secure(policy);
877 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000878 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 JsepSessionDescription* answer(
880 new JsepSessionDescription(JsepSessionDescription::kAnswer));
881 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
882 options, NULL),
883 session_id, kSessionVersion)) {
884 delete answer;
885 answer = NULL;
886 }
887 return answer;
888 }
889
890 JsepSessionDescription* CreateRemoteAnswer(
891 const SessionDescriptionInterface* offer,
892 cricket::MediaSessionOptions options) {
893 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
894 }
895
896 // Creates an answer session description with streams based on
897 // |mediastream_signaling_|. Call
898 // mediastream_signaling_.UseOptionsWithStreamX() before this function
899 // to decide which streams to create.
900 JsepSessionDescription* CreateRemoteAnswer(
901 const SessionDescriptionInterface* offer) {
902 cricket::MediaSessionOptions options;
903 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
904 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
905 }
906
907 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000908 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000909 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000911
912 PeerConnectionInterface::RTCOfferAnswerOptions options;
913 options.use_rtp_mux = bundle;
914
915 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
917 // and answer.
918 SetLocalDescriptionWithoutError(offer);
919
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000920 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000921 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 std::string sdp;
923 EXPECT_TRUE(answer->ToString(&sdp));
924
925 size_t expected_candidate_num = 2;
926 if (!rtcp_mux) {
927 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
928 // for rtp and rtcp.
929 expected_candidate_num = 4;
930 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 const std::string kRtcpMux = "a=rtcp-mux";
932 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000933 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 kXRtcpMux.c_str(), kXRtcpMux.length(),
935 &sdp);
936 }
937
938 SessionDescriptionInterface* new_answer = CreateSessionDescription(
939 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940
941 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000942 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
944 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
945 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
946 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
947 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
948 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
949 if (bundle) {
950 EXPECT_TRUE(c0.IsEquivalent(c1));
951 } else {
952 EXPECT_FALSE(c0.IsEquivalent(c1));
953 }
954 }
955 }
956 // Tests that we can only send DTMF when the dtmf codec is supported.
957 void TestCanInsertDtmf(bool can) {
958 if (can) {
959 InitWithDtmfCodec();
960 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000961 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 }
963 mediastream_signaling_.SendAudioVideoStream1();
964 CreateAndSetRemoteOfferAndLocalAnswer();
965 EXPECT_FALSE(session_->CanInsertDtmf(""));
966 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
967 }
968
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000969 // Helper class to configure loopback network and verify Best
970 // Connection using right IP protocol for TestLoopbackCall
971 // method. LoopbackNetworkManager applies firewall rules to block
972 // all ping traffic once ICE completed, and remove them to observe
973 // ICE reconnected again. This LoopbackNetworkConfiguration struct
974 // verifies the best connection is using the right IP protocol after
975 // initial ICE convergences.
976
977 class LoopbackNetworkConfiguration {
978 public:
979 LoopbackNetworkConfiguration()
980 : test_ipv6_network_(false),
981 test_extra_ipv4_network_(false),
982 best_connection_after_initial_ice_converged_(1, 0) {}
983
984 // Used to track the expected best connection count in each IP protocol.
985 struct ExpectedBestConnection {
986 ExpectedBestConnection(int ipv4_count, int ipv6_count)
987 : ipv4_count_(ipv4_count),
988 ipv6_count_(ipv6_count) {}
989
990 int ipv4_count_;
991 int ipv6_count_;
992 };
993
994 bool test_ipv6_network_;
995 bool test_extra_ipv4_network_;
996 ExpectedBestConnection best_connection_after_initial_ice_converged_;
997
998 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -0700999 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001000 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1001 }
1002
1003 private:
jbauchac8869e2015-07-03 01:36:14 -07001004 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001005 const ExpectedBestConnection& expected) const {
1006 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001007 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1008 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001009 expected.ipv4_count_);
1010 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001011 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1012 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001013 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001014 // This is used in the loopback call so there is only single host to host
1015 // candidate pair.
1016 EXPECT_EQ(metrics_observer->GetEnumCounter(
1017 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1018 webrtc::kIceCandidatePairHostHost),
1019 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001020 }
1021 };
1022
1023 class LoopbackNetworkManager {
1024 public:
1025 LoopbackNetworkManager(WebRtcSessionTest* session,
1026 const LoopbackNetworkConfiguration& config)
1027 : config_(config) {
1028 session->AddInterface(
1029 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1030 if (config_.test_extra_ipv4_network_) {
1031 session->AddInterface(
1032 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1033 }
1034 if (config_.test_ipv6_network_) {
1035 session->AddInterface(
1036 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1037 }
1038 }
1039
1040 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1041 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1042 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1043 if (config_.test_extra_ipv4_network_) {
1044 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1045 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1046 }
1047 if (config_.test_ipv6_network_) {
1048 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1049 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1050 }
1051 }
1052
1053 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1054
1055 private:
1056 LoopbackNetworkConfiguration config_;
1057 };
1058
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // The method sets up a call from the session to itself, in a loopback
1060 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001061 // disconnection, and then a permanent disconnection.
1062 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1064 // While running the call, this method also checks if the session goes through
1065 // the correct sequence of ICE states when a connection is established,
1066 // broken, and re-established.
1067 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001068 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1069 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001071
1072 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1073 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001074 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001076 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077
1078 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1079 observer_.ice_gathering_state_);
1080 SetLocalDescriptionWithoutError(offer);
1081 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1082 observer_.ice_connection_state_);
1083 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1084 observer_.ice_gathering_state_,
1085 kIceCandidatesTimeout);
1086 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1087 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1088 observer_.ice_gathering_state_,
1089 kIceCandidatesTimeout);
1090
1091 std::string sdp;
1092 offer->ToString(&sdp);
1093 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001094 webrtc::CreateSessionDescription(
1095 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 ASSERT_TRUE(desc != NULL);
1097 SetRemoteDescriptionWithoutError(desc);
1098
1099 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1100 observer_.ice_connection_state_,
1101 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001102
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001103 // The ice connection state is "Connected" too briefly to catch in a test.
1104 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 observer_.ice_connection_state_,
1106 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001108 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 // Adding firewall rule to block ping requests, which should cause
1110 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001111
1112 loopback_network_manager.ApplyFirewallRules(fss_.get());
1113
1114 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1116 observer_.ice_connection_state_,
1117 kIceCandidatesTimeout);
1118
jbauchac8869e2015-07-03 01:36:14 -07001119 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001122 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 // Session is automatically calling OnSignalingReady after creation of
1124 // new portallocator session which will allocate new set of candidates.
1125
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001126 LOG(LS_INFO) << "Firewall Rules cleared";
1127
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001128 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 observer_.ice_connection_state_,
1130 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001131
1132 // Now we block ping requests and wait until the ICE connection transitions
1133 // to the Failed state. This will take at least 30 seconds because it must
1134 // wait for the Port to timeout.
1135 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136
1137 loopback_network_manager.ApplyFirewallRules(fss_.get());
1138 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001139 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001140 observer_.ice_connection_state_,
1141 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 }
1143
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001144 void TestLoopbackCall() {
1145 LoopbackNetworkConfiguration config;
1146 TestLoopbackCall(config);
1147 }
1148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1150 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001151 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1152 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1153
1154 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1156 codecs.push_back(kCNCodec1);
1157 codecs.push_back(kCNCodec2);
1158 media_engine_->SetAudioCodecs(codecs);
1159 desc_factory_->set_audio_codecs(codecs);
1160 }
1161
1162 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1163 const cricket::ContentDescription* description = content->description;
1164 ASSERT(description != NULL);
1165 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001166 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 ASSERT(audio_content_desc != NULL);
1168 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1169 if (audio_content_desc->codecs()[i].name == "CN")
1170 return false;
1171 }
1172 return true;
1173 }
1174
1175 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001176 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 dci.reliable = false;
1178 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001179 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 SetLocalDescriptionWithoutError(offer);
1181 }
1182
wu@webrtc.org91053e72013-08-10 07:18:04 +00001183 void VerifyMultipleAsyncCreateDescription(
1184 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001185 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001186 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 if (type == CreateSessionDescriptionRequest::kAnswer) {
1188 cricket::MediaSessionOptions options;
1189 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001190 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001191 ASSERT_TRUE(offer.get() != NULL);
1192 SetRemoteDescriptionWithoutError(offer.release());
1193 }
1194
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001195 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001196 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001197 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001198 observers[kNumber];
1199 for (int i = 0; i < kNumber; ++i) {
1200 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1201 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001202 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 } else {
1204 session_->CreateAnswer(observers[i], NULL);
1205 }
1206 }
1207
1208 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1209 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1210 WebRtcSessionCreateSDPObserverForTest::kFailed;
1211
1212 for (int i = 0; i < kNumber; ++i) {
1213 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1214 if (success) {
1215 EXPECT_TRUE(observers[i]->description() != NULL);
1216 } else {
1217 EXPECT_TRUE(observers[i]->description() == NULL);
1218 }
1219 }
1220 }
1221
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001222 void ConfigureAllocatorWithTurn() {
1223 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1224 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1225 relay_server.credentials = credentials;
1226 relay_server.ports.push_back(cricket::ProtocolAddress(
1227 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1228 allocator_->AddRelay(relay_server);
1229 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher2159b892015-08-21 20:46:05 -07001230 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001231 }
1232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 cricket::FakeMediaEngine* media_engine_;
1234 cricket::FakeDataEngine* data_engine_;
1235 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001236 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1237 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1238 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1239 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1240 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1241 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1242 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1243 rtc::SocketServerScope ss_scope_;
1244 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001245 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001246 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001247 rtc::FakeNetworkManager network_manager_;
1248 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001249 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001250 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 MockIceObserver observer_;
1254 cricket::FakeVideoMediaChannel* video_channel_;
1255 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001256 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257};
1258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1260 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001261 // SDES is disabled when DTLS is on.
1262 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263}
1264
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001265TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001266 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001267 // SDES is required if DTLS is off.
1268 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001269}
1270
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1272 TestSessionCandidatesWithBundleRtcpMux(false, false);
1273}
1274
1275// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1276// with rtcp-mux and/or bundle.
1277TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1278 TestSessionCandidatesWithBundleRtcpMux(false, true);
1279}
1280
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1282 TestSessionCandidatesWithBundleRtcpMux(true, true);
1283}
1284
1285TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001286 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1287 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001288 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 mediastream_signaling_.SendAudioVideoStream1();
1290 InitiateCall();
1291 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1292 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1293 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1294}
1295
1296TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001297 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1298 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001299 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001300 rtc::FP_UDP,
1301 rtc::FD_ANY,
1302 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001303 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 mediastream_signaling_.SendAudioVideoStream1();
1305 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001306 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1308 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1309 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1310}
1311
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001312// Test session delivers no candidates gathered when constraint set to "none".
1313TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1314 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001315 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001316 mediastream_signaling_.SendAudioVideoStream1();
1317 InitiateCall();
1318 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1319 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1320 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1321}
1322
1323// Test session delivers only relay candidates gathered when constaint set to
1324// "relay".
1325TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1326 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1327 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001328 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001329 mediastream_signaling_.SendAudioVideoStream1();
1330 InitiateCall();
1331 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1332 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1333 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1334 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1335 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1336 observer_.mline_0_candidates_[i].type());
1337 }
1338 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1339 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1340 observer_.mline_1_candidates_[i].type());
1341 }
1342}
1343
1344// Test session delivers all candidates gathered when constaint set to "all".
1345TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1346 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001347 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001348 mediastream_signaling_.SendAudioVideoStream1();
1349 InitiateCall();
1350 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1351 // Host + STUN. By default allocator is disabled to gather relay candidates.
1352 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1353 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1354}
1355
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001356TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001357 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001358 SessionDescriptionInterface* offer = NULL;
1359 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1360 std::string unknown_action;
1361 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1362 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1363}
1364
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365// Test creating offers and receive answers and make sure the
1366// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001367TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001368 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001370 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 const std::string session_id_orig = offer->session_id();
1372 const std::string session_version_orig = offer->session_version();
1373 SetLocalDescriptionWithoutError(offer);
1374
1375 mediastream_signaling_.SendAudioVideoStream2();
1376 SessionDescriptionInterface* answer =
1377 CreateRemoteAnswer(session_->local_description());
1378 SetRemoteDescriptionWithoutError(answer);
1379
1380 video_channel_ = media_engine_->GetVideoChannel(0);
1381 voice_channel_ = media_engine_->GetVoiceChannel(0);
1382
1383 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1384 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1385
1386 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1387 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1388
1389 ASSERT_EQ(1u, video_channel_->send_streams().size());
1390 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1391 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1392 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1393
1394 // Create new offer without send streams.
1395 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001396 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397
1398 // Verify the session id is the same and the session version is
1399 // increased.
1400 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001401 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1402 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403
1404 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001405 EXPECT_EQ(0u, video_channel_->send_streams().size());
1406 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407
1408 mediastream_signaling_.SendAudioVideoStream2();
1409 answer = CreateRemoteAnswer(session_->local_description());
1410 SetRemoteDescriptionWithoutError(answer);
1411
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 // Make sure the receive streams have not changed.
1413 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1414 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1415 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1416 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1417}
1418
1419// Test receiving offers and creating answers and make sure the
1420// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001421TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001422 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001424 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001425 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 SetRemoteDescriptionWithoutError(offer);
1427
1428 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001429 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001430 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 SetLocalDescriptionWithoutError(answer);
1432
1433 const std::string session_id_orig = answer->session_id();
1434 const std::string session_version_orig = answer->session_version();
1435
1436 video_channel_ = media_engine_->GetVideoChannel(0);
1437 voice_channel_ = media_engine_->GetVoiceChannel(0);
1438
1439 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1440 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1441
1442 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1443 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1444
1445 ASSERT_EQ(1u, video_channel_->send_streams().size());
1446 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1447 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1448 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1449
1450 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001451 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 SetRemoteDescriptionWithoutError(offer);
1453
1454 // Answer by turning off all send streams.
1455 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001456 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457
1458 // Verify the session id is the same and the session version is
1459 // increased.
1460 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001461 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1462 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 SetLocalDescriptionWithoutError(answer);
1464
1465 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1466 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1467 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1468 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1469 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1470 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1471
1472 // Make sure we have no send streams.
1473 EXPECT_EQ(0u, video_channel_->send_streams().size());
1474 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1475}
1476
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001477TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001478 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001479 media_engine_->set_fail_create_channel(true);
1480
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001481 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001482 ASSERT_TRUE(offer != NULL);
1483 // SetRemoteDescription and SetLocalDescription will take the ownership of
1484 // the offer.
1485 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001486 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001487 ASSERT_TRUE(offer != NULL);
1488 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1489}
1490
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001491//
1492// Tests for creating/setting SDP under different SDES/DTLS polices:
1493//
1494// --DTLS off and SDES on
1495// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1496// set local/remote offer/answer with crypto --> success
1497// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1498// failure
1499// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1500// failure
1501// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1502// failure
1503//
1504// --DTLS on and SDES off
1505// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1506// set local/remote offer/answer with DTLS fingerprint --> success
1507// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1508// fingerprint --> failure
1509// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1510// --> failure
1511// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1512// --> failure
1513//
1514// --Encryption disabled: DTLS off and SDES off
1515// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1516// answer without SDES or DTLS --> success
1517// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1518// answer without SDES or DTLS --> success
1519//
1520
1521// Test that we return a failure when applying a remote/local offer that doesn't
1522// have cryptos enabled when DTLS is off.
1523TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001524 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001526 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 JsepSessionDescription* offer = CreateRemoteOffer(
1528 options, cricket::SEC_DISABLED);
1529 ASSERT_TRUE(offer != NULL);
1530 VerifyNoCryptoParams(offer->description(), false);
1531 // SetRemoteDescription and SetLocalDescription will take the ownership of
1532 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001533 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1535 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001536 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537}
1538
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001539// Test that we return a failure when applying a local answer that doesn't have
1540// cryptos enabled when DTLS is off.
1541TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001542 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 SessionDescriptionInterface* offer = NULL;
1544 SessionDescriptionInterface* answer = NULL;
1545 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1546 // SetRemoteDescription and SetLocalDescription will take the ownership of
1547 // the offer.
1548 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001549 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550}
1551
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001552// Test we will return fail when apply an remote answer that doesn't have
1553// crypto enabled when DTLS is off.
1554TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001555 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 SessionDescriptionInterface* offer = NULL;
1557 SessionDescriptionInterface* answer = NULL;
1558 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1559 // SetRemoteDescription and SetLocalDescription will take the ownership of
1560 // the offer.
1561 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001562 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563}
1564
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001565// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1566// and that we return an answer with a DTLS fingerprint.
1567TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001568 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 InitWithDtls();
1571 SetFactoryDtlsSrtp();
1572 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001573 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001574 JsepSessionDescription* offer =
1575 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 ASSERT_TRUE(offer != NULL);
1577 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001578 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579
1580 // SetRemoteDescription will take the ownership of the offer.
1581 SetRemoteDescriptionWithoutError(offer);
1582
1583 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001584 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 ASSERT_TRUE(answer != NULL);
1586 VerifyFingerprintStatus(answer->description(), true);
1587 // Check that we don't have an a=crypto line in the answer.
1588 VerifyNoCryptoParams(answer->description(), true);
1589
1590 // Now set the local description, which should work, even without a=crypto.
1591 SetLocalDescriptionWithoutError(answer);
1592}
1593
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1595// and then we accept a remote answer with a DTLS fingerprint successfully.
1596TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001597 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598 mediastream_signaling_.SendAudioVideoStream1();
1599 InitWithDtls();
1600 SetFactoryDtlsSrtp();
1601
1602 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001603 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001604 ASSERT_TRUE(offer != NULL);
1605 VerifyFingerprintStatus(offer->description(), true);
1606 // Check that we don't have an a=crypto line in the offer.
1607 VerifyNoCryptoParams(offer->description(), true);
1608
1609 // Now set the local description, which should work, even without a=crypto.
1610 SetLocalDescriptionWithoutError(offer);
1611
1612 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001613 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001614 JsepSessionDescription* answer =
1615 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1616 ASSERT_TRUE(answer != NULL);
1617 VerifyFingerprintStatus(answer->description(), true);
1618 VerifyNoCryptoParams(answer->description(), true);
1619
1620 // SetRemoteDescription will take the ownership of the answer.
1621 SetRemoteDescriptionWithoutError(answer);
1622}
1623
1624// Test that if we support DTLS and the other side didn't offer a fingerprint,
1625// we will fail to set the remote description.
1626TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001627 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 InitWithDtls();
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 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 JsepSessionDescription* offer = CreateRemoteOffer(
1633 options, cricket::SEC_REQUIRED);
1634 ASSERT_TRUE(offer != NULL);
1635 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001636 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001638 // SetRemoteDescription will take the ownership of the offer.
1639 SetRemoteDescriptionOfferExpectError(
1640 kSdpWithoutDtlsFingerprint, offer);
1641
1642 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1643 // SetLocalDescription will take the ownership of the offer.
1644 SetLocalDescriptionOfferExpectError(
1645 kSdpWithoutDtlsFingerprint, offer);
1646}
1647
1648// Test that we return a failure when applying a local answer that doesn't have
1649// a DTLS fingerprint when DTLS is required.
1650TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001651 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001652 InitWithDtls();
1653 SessionDescriptionInterface* offer = NULL;
1654 SessionDescriptionInterface* answer = NULL;
1655 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1656
1657 // SetRemoteDescription and SetLocalDescription will take the ownership of
1658 // the offer and answer.
1659 SetRemoteDescriptionWithoutError(offer);
1660 SetLocalDescriptionAnswerExpectError(
1661 kSdpWithoutDtlsFingerprint, answer);
1662}
1663
1664// Test that we return a failure when applying a remote answer that doesn't have
1665// a DTLS fingerprint when DTLS is required.
1666TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001667 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001668 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1669 // result of using the "UDP/TLS/RTP/SAVPF" profile.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 InitWithDtls();
deadbeeff3938292015-07-15 12:20:53 -07001671 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001672 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001673 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001674 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001675 JsepSessionDescription* answer =
1676 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1677
1678 // SetRemoteDescription and SetLocalDescription will take the ownership of
1679 // the offer and answer.
1680 SetLocalDescriptionWithoutError(offer);
1681 SetRemoteDescriptionAnswerExpectError(
1682 kSdpWithoutDtlsFingerprint, answer);
1683}
1684
1685// Test that we create a local offer without SDES or DTLS and accept a remote
1686// answer without SDES or DTLS when encryption is disabled.
1687TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1688 mediastream_signaling_.SendAudioVideoStream1();
1689 options_.disable_encryption = true;
1690 InitWithDtls();
1691
1692 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001693 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001694 ASSERT_TRUE(offer != NULL);
1695 VerifyFingerprintStatus(offer->description(), false);
1696 // Check that we don't have an a=crypto line in the offer.
1697 VerifyNoCryptoParams(offer->description(), false);
1698
1699 // Now set the local description, which should work, even without a=crypto.
1700 SetLocalDescriptionWithoutError(offer);
1701
1702 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001703 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001704 JsepSessionDescription* answer =
1705 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1706 ASSERT_TRUE(answer != NULL);
1707 VerifyFingerprintStatus(answer->description(), false);
1708 VerifyNoCryptoParams(answer->description(), false);
1709
1710 // SetRemoteDescription will take the ownership of the answer.
1711 SetRemoteDescriptionWithoutError(answer);
1712}
1713
1714// Test that we create a local answer without SDES or DTLS and accept a remote
1715// offer without SDES or DTLS when encryption is disabled.
1716TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1717 options_.disable_encryption = true;
1718 InitWithDtls();
1719
1720 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001721 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001722 JsepSessionDescription* offer =
1723 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1724 ASSERT_TRUE(offer != NULL);
1725 VerifyFingerprintStatus(offer->description(), false);
1726 VerifyNoCryptoParams(offer->description(), false);
1727
1728 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 SetRemoteDescriptionWithoutError(offer);
1730
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001732 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 ASSERT_TRUE(answer != NULL);
1734 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 // Check that we don't have an a=crypto line in the answer.
1736 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 SetLocalDescriptionWithoutError(answer);
1740}
1741
1742TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001743 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 mediastream_signaling_.SendNothing();
1745 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001746 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 SetLocalDescriptionWithoutError(offer);
1748
1749 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001750 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 SetLocalDescriptionWithoutError(offer2);
1752}
1753
1754TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001755 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 mediastream_signaling_.SendNothing();
1757 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001758 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 SetRemoteDescriptionWithoutError(offer);
1760
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001761 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 SetRemoteDescriptionWithoutError(offer2);
1763}
1764
1765TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001766 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001768 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001770 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001771 SetRemoteDescriptionOfferExpectError(
1772 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773}
1774
1775TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001776 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001780 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001781 SetLocalDescriptionOfferExpectError(
1782 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783}
1784
1785TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001786 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 mediastream_signaling_.SendNothing();
1788 SessionDescriptionInterface* offer = CreateRemoteOffer();
1789 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1790
1791 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001792 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1794 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1795
1796 mediastream_signaling_.SendAudioVideoStream1();
1797 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001798 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1800
1801 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1802
1803 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001804 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1806}
1807
1808TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001809 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001811 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1813
1814 JsepSessionDescription* pranswer =
1815 CreateRemoteAnswer(session_->local_description());
1816 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1817
1818 SetRemoteDescriptionExpectState(pranswer,
1819 BaseSession::STATE_RECEIVEDPRACCEPT);
1820
1821 mediastream_signaling_.SendAudioVideoStream1();
1822 JsepSessionDescription* pranswer2 =
1823 CreateRemoteAnswer(session_->local_description());
1824 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1825
1826 SetRemoteDescriptionExpectState(pranswer2,
1827 BaseSession::STATE_RECEIVEDPRACCEPT);
1828
1829 mediastream_signaling_.SendAudioVideoStream2();
1830 SessionDescriptionInterface* answer =
1831 CreateRemoteAnswer(session_->local_description());
1832 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1833}
1834
1835TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001836 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001838 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1839
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 SessionDescriptionInterface* answer =
1841 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001842 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1843 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844}
1845
1846TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001847 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001849 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1850
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 SessionDescriptionInterface* answer =
1852 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001853 SetRemoteDescriptionAnswerExpectError(
1854 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855}
1856
1857TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001858 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 mediastream_signaling_.SendAudioVideoStream1();
1860
1861 cricket::Candidate candidate;
1862 candidate.set_component(1);
1863 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1864
1865 // Fail since we have not set a offer description.
1866 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1867
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001868 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 SetLocalDescriptionWithoutError(offer);
1870 // Candidate should be allowed to add before remote description.
1871 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1872 candidate.set_component(2);
1873 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1874 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1875
1876 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1877 session_->local_description());
1878 SetRemoteDescriptionWithoutError(answer);
1879
1880 // Verifying the candidates are copied properly from internal vector.
1881 const SessionDescriptionInterface* remote_desc =
1882 session_->remote_description();
1883 ASSERT_TRUE(remote_desc != NULL);
1884 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1885 const IceCandidateCollection* candidates =
1886 remote_desc->candidates(kMediaContentIndex0);
1887 ASSERT_EQ(2u, candidates->count());
1888 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1889 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1890 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1891 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1892
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001893 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1894 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 candidate.set_component(2);
1896 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1897 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001898 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899
1900 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1901 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1902}
1903
1904// Test that a remote candidate is added to the remote session description and
1905// that it is retained if the remote session description is changed.
1906TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001907 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 cricket::Candidate candidate1;
1909 candidate1.set_component(1);
1910 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1911 candidate1);
1912 mediastream_signaling_.SendAudioVideoStream1();
1913 CreateAndSetRemoteOfferAndLocalAnswer();
1914
1915 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1916 const SessionDescriptionInterface* remote_desc =
1917 session_->remote_description();
1918 ASSERT_TRUE(remote_desc != NULL);
1919 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1920 const IceCandidateCollection* candidates =
1921 remote_desc->candidates(kMediaContentIndex0);
1922 ASSERT_EQ(1u, candidates->count());
1923 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1924
1925 // Update the RemoteSessionDescription with a new session description and
1926 // a candidate and check that the new remote session description contains both
1927 // candidates.
1928 SessionDescriptionInterface* offer = CreateRemoteOffer();
1929 cricket::Candidate candidate2;
1930 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1931 candidate2);
1932 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1933 SetRemoteDescriptionWithoutError(offer);
1934
1935 remote_desc = session_->remote_description();
1936 ASSERT_TRUE(remote_desc != NULL);
1937 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1938 candidates = remote_desc->candidates(kMediaContentIndex0);
1939 ASSERT_EQ(2u, candidates->count());
1940 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1941 // Username and password have be updated with the TransportInfo of the
1942 // SessionDescription, won't be equal to the original one.
1943 candidate2.set_username(candidates->at(0)->candidate().username());
1944 candidate2.set_password(candidates->at(0)->candidate().password());
1945 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1946 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1947 // No need to verify the username and password.
1948 candidate1.set_username(candidates->at(1)->candidate().username());
1949 candidate1.set_password(candidates->at(1)->candidate().password());
1950 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1951
1952 // Test that the candidate is ignored if we can add the same candidate again.
1953 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1954}
1955
1956// Test that local candidates are added to the local session description and
1957// that they are retained if the local session description is changed.
1958TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001959 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001960 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 mediastream_signaling_.SendAudioVideoStream1();
1962 CreateAndSetRemoteOfferAndLocalAnswer();
1963
1964 const SessionDescriptionInterface* local_desc = session_->local_description();
1965 const IceCandidateCollection* candidates =
1966 local_desc->candidates(kMediaContentIndex0);
1967 ASSERT_TRUE(candidates != NULL);
1968 EXPECT_EQ(0u, candidates->count());
1969
1970 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1971
1972 local_desc = session_->local_description();
1973 candidates = local_desc->candidates(kMediaContentIndex0);
1974 ASSERT_TRUE(candidates != NULL);
1975 EXPECT_LT(0u, candidates->count());
1976 candidates = local_desc->candidates(1);
1977 ASSERT_TRUE(candidates != NULL);
1978 EXPECT_LT(0u, candidates->count());
1979
1980 // Update the session descriptions.
1981 mediastream_signaling_.SendAudioVideoStream1();
1982 CreateAndSetRemoteOfferAndLocalAnswer();
1983
1984 local_desc = session_->local_description();
1985 candidates = local_desc->candidates(kMediaContentIndex0);
1986 ASSERT_TRUE(candidates != NULL);
1987 EXPECT_LT(0u, candidates->count());
1988 candidates = local_desc->candidates(1);
1989 ASSERT_TRUE(candidates != NULL);
1990 EXPECT_LT(0u, candidates->count());
1991}
1992
1993// Test that we can set a remote session description with remote candidates.
1994TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996
1997 cricket::Candidate candidate1;
1998 candidate1.set_component(1);
1999 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2000 candidate1);
2001 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002002 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003
2004 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2005 SetRemoteDescriptionWithoutError(offer);
2006
2007 const SessionDescriptionInterface* remote_desc =
2008 session_->remote_description();
2009 ASSERT_TRUE(remote_desc != NULL);
2010 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2011 const IceCandidateCollection* candidates =
2012 remote_desc->candidates(kMediaContentIndex0);
2013 ASSERT_EQ(1u, candidates->count());
2014 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2015
wu@webrtc.org91053e72013-08-10 07:18:04 +00002016 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 SetLocalDescriptionWithoutError(answer);
2018}
2019
2020// Test that offers and answers contains ice candidates when Ice candidates have
2021// been gathered.
2022TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002023 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002024 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 mediastream_signaling_.SendAudioVideoStream1();
2026 // Ice is started but candidates are not provided until SetLocalDescription
2027 // is called.
2028 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2029 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2030 CreateAndSetRemoteOfferAndLocalAnswer();
2031 // Wait until at least one local candidate has been collected.
2032 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2033 kIceCandidatesTimeout);
2034 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2035 kIceCandidatesTimeout);
2036
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002037 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2038
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2040 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2041 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2042 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2043
2044 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2045 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002046 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2048 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2049 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2050 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2051 SetLocalDescriptionWithoutError(answer);
2052}
2053
2054// Verifies TransportProxy and media channels are created with content names
2055// present in the SessionDescription.
2056TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002057 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002059 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060
2061 // CreateOffer creates session description with the content names "audio" and
2062 // "video". Goal is to modify these content names and verify transport channel
2063 // proxy in the BaseSession, as proxies are created with the content names
2064 // present in SDP.
2065 std::string sdp;
2066 EXPECT_TRUE(offer->ToString(&sdp));
2067 const std::string kAudioMid = "a=mid:audio";
2068 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2069 const std::string kVideoMid = "a=mid:video";
2070 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2071
2072 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002073 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 kAudioMidReplaceStr.c_str(),
2075 kAudioMidReplaceStr.length(),
2076 &sdp);
2077 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002078 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 kVideoMidReplaceStr.c_str(),
2080 kVideoMidReplaceStr.length(),
2081 &sdp);
2082
2083 SessionDescriptionInterface* modified_offer =
2084 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2085
2086 SetRemoteDescriptionWithoutError(modified_offer);
2087
2088 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002089 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 SetLocalDescriptionWithoutError(answer);
2091
2092 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2093 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2094 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2095 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2096}
2097
2098// Test that an offer contains the correct media content descriptions based on
2099// the send streams when no constraints have been set.
2100TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002101 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002102 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2103
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 ASSERT_TRUE(offer != NULL);
2105 const cricket::ContentInfo* content =
2106 cricket::GetFirstAudioContent(offer->description());
2107 EXPECT_TRUE(content != NULL);
2108 content = cricket::GetFirstVideoContent(offer->description());
2109 EXPECT_TRUE(content == NULL);
2110}
2111
2112// Test that an offer contains the correct media content descriptions based on
2113// the send streams when no constraints have been set.
2114TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002115 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 // Test Audio only offer.
2117 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002118 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 const cricket::ContentInfo* content =
2121 cricket::GetFirstAudioContent(offer->description());
2122 EXPECT_TRUE(content != NULL);
2123 content = cricket::GetFirstVideoContent(offer->description());
2124 EXPECT_TRUE(content == NULL);
2125
2126 // Test Audio / Video offer.
2127 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 content = cricket::GetFirstAudioContent(offer->description());
2130 EXPECT_TRUE(content != NULL);
2131 content = cricket::GetFirstVideoContent(offer->description());
2132 EXPECT_TRUE(content != NULL);
2133}
2134
2135// Test that an offer contains no media content descriptions if
2136// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2137TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002138 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002139 PeerConnectionInterface::RTCOfferAnswerOptions options;
2140 options.offer_to_receive_audio = 0;
2141 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002143 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002144 CreateOffer(options));
2145
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 ASSERT_TRUE(offer != NULL);
2147 const cricket::ContentInfo* content =
2148 cricket::GetFirstAudioContent(offer->description());
2149 EXPECT_TRUE(content == NULL);
2150 content = cricket::GetFirstVideoContent(offer->description());
2151 EXPECT_TRUE(content == NULL);
2152}
2153
2154// Test that an offer contains only audio media content descriptions if
2155// kOfferToReceiveAudio constraints are set to true.
2156TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002157 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002158 PeerConnectionInterface::RTCOfferAnswerOptions options;
2159 options.offer_to_receive_audio =
2160 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2161
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002162 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002163 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164
2165 const cricket::ContentInfo* content =
2166 cricket::GetFirstAudioContent(offer->description());
2167 EXPECT_TRUE(content != NULL);
2168 content = cricket::GetFirstVideoContent(offer->description());
2169 EXPECT_TRUE(content == NULL);
2170}
2171
2172// Test that an offer contains audio and video media content descriptions if
2173// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2174TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002175 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002177 PeerConnectionInterface::RTCOfferAnswerOptions options;
2178 options.offer_to_receive_audio =
2179 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2180 options.offer_to_receive_video =
2181 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2182
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002183 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002184 CreateOffer(options));
2185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 const cricket::ContentInfo* content =
2187 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002188 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002189
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 content = cricket::GetFirstVideoContent(offer->description());
2191 EXPECT_TRUE(content != NULL);
2192
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002193 // Sets constraints to false and verifies that audio/video contents are
2194 // removed.
2195 options.offer_to_receive_audio = 0;
2196 options.offer_to_receive_video = 0;
2197 offer.reset(CreateOffer(options));
2198
2199 content = cricket::GetFirstAudioContent(offer->description());
2200 EXPECT_TRUE(content == NULL);
2201 content = cricket::GetFirstVideoContent(offer->description());
2202 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203}
2204
2205// Test that an answer can not be created if the last remote description is not
2206// an offer.
2207TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002208 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002209 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 SetLocalDescriptionWithoutError(offer);
2211 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2212 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002213 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214}
2215
2216// Test that an answer contains the correct media content descriptions when no
2217// constraints have been set.
2218TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002219 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002221 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002223 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002224 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 const cricket::ContentInfo* content =
2226 cricket::GetFirstAudioContent(answer->description());
2227 ASSERT_TRUE(content != NULL);
2228 EXPECT_FALSE(content->rejected);
2229
2230 content = cricket::GetFirstVideoContent(answer->description());
2231 ASSERT_TRUE(content != NULL);
2232 EXPECT_FALSE(content->rejected);
2233}
2234
2235// Test that an answer contains the correct media content descriptions when no
2236// constraints have been set and the offer only contain audio.
2237TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002238 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 // Create a remote offer with audio only.
2240 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002241
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002242 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 CreateRemoteOffer(options));
2244 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2245 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2246
2247 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002248 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002249 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 const cricket::ContentInfo* content =
2251 cricket::GetFirstAudioContent(answer->description());
2252 ASSERT_TRUE(content != NULL);
2253 EXPECT_FALSE(content->rejected);
2254
2255 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2256}
2257
2258// Test that an answer contains the correct media content descriptions when no
2259// constraints have been set.
2260TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002261 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002263 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 SetRemoteDescriptionWithoutError(offer.release());
2265 // Test with a stream with tracks.
2266 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002267 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002268 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 const cricket::ContentInfo* content =
2270 cricket::GetFirstAudioContent(answer->description());
2271 ASSERT_TRUE(content != NULL);
2272 EXPECT_FALSE(content->rejected);
2273
2274 content = cricket::GetFirstVideoContent(answer->description());
2275 ASSERT_TRUE(content != NULL);
2276 EXPECT_FALSE(content->rejected);
2277}
2278
2279// Test that an answer contains the correct media content descriptions when
2280// constraints have been set but no stream is sent.
2281TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002282 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002284 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 SetRemoteDescriptionWithoutError(offer.release());
2286
2287 webrtc::FakeConstraints constraints_no_receive;
2288 constraints_no_receive.SetMandatoryReceiveAudio(false);
2289 constraints_no_receive.SetMandatoryReceiveVideo(false);
2290
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002291 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002292 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 const cricket::ContentInfo* content =
2294 cricket::GetFirstAudioContent(answer->description());
2295 ASSERT_TRUE(content != NULL);
2296 EXPECT_TRUE(content->rejected);
2297
2298 content = cricket::GetFirstVideoContent(answer->description());
2299 ASSERT_TRUE(content != NULL);
2300 EXPECT_TRUE(content->rejected);
2301}
2302
2303// Test that an answer contains the correct media content descriptions when
2304// constraints have been set and streams are sent.
2305TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002306 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002308 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 SetRemoteDescriptionWithoutError(offer.release());
2310
2311 webrtc::FakeConstraints constraints_no_receive;
2312 constraints_no_receive.SetMandatoryReceiveAudio(false);
2313 constraints_no_receive.SetMandatoryReceiveVideo(false);
2314
2315 // Test with a stream with tracks.
2316 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002317 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002318 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319
2320 // TODO(perkj): Should the direction be set to SEND_ONLY?
2321 const cricket::ContentInfo* content =
2322 cricket::GetFirstAudioContent(answer->description());
2323 ASSERT_TRUE(content != NULL);
2324 EXPECT_FALSE(content->rejected);
2325
2326 // TODO(perkj): Should the direction be set to SEND_ONLY?
2327 content = cricket::GetFirstVideoContent(answer->description());
2328 ASSERT_TRUE(content != NULL);
2329 EXPECT_FALSE(content->rejected);
2330}
2331
2332TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2333 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002334 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002335 PeerConnectionInterface::RTCOfferAnswerOptions options;
2336 options.offer_to_receive_audio =
2337 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2338 options.voice_activity_detection = false;
2339
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002340 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002341 CreateOffer(options));
2342
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 const cricket::ContentInfo* content =
2344 cricket::GetFirstAudioContent(offer->description());
2345 EXPECT_TRUE(content != NULL);
2346 EXPECT_TRUE(VerifyNoCNCodecs(content));
2347}
2348
2349TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2350 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002351 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002353 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 SetRemoteDescriptionWithoutError(offer.release());
2355
2356 webrtc::FakeConstraints constraints;
2357 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002358 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002359 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 const cricket::ContentInfo* content =
2361 cricket::GetFirstAudioContent(answer->description());
2362 ASSERT_TRUE(content != NULL);
2363 EXPECT_TRUE(VerifyNoCNCodecs(content));
2364}
2365
2366// This test verifies the call setup when remote answer with audio only and
2367// later updates with video.
2368TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002369 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2371 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2372
2373 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002374 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375
2376 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2378
2379 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2380 // and answer;
2381 SetLocalDescriptionWithoutError(offer);
2382 SetRemoteDescriptionWithoutError(answer);
2383
2384 video_channel_ = media_engine_->GetVideoChannel(0);
2385 voice_channel_ = media_engine_->GetVoiceChannel(0);
2386
2387 ASSERT_TRUE(video_channel_ == NULL);
2388
2389 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2390 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2391 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2392
2393 // Let the remote end update the session descriptions, with Audio and Video.
2394 mediastream_signaling_.SendAudioVideoStream2();
2395 CreateAndSetRemoteOfferAndLocalAnswer();
2396
2397 video_channel_ = media_engine_->GetVideoChannel(0);
2398 voice_channel_ = media_engine_->GetVoiceChannel(0);
2399
2400 ASSERT_TRUE(video_channel_ != NULL);
2401 ASSERT_TRUE(voice_channel_ != NULL);
2402
2403 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2404 ASSERT_EQ(1u, video_channel_->send_streams().size());
2405 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2406 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2407 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2408 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2409 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2410 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2411
2412 // Change session back to audio only.
2413 mediastream_signaling_.UseOptionsAudioOnly();
2414 CreateAndSetRemoteOfferAndLocalAnswer();
2415
2416 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2417 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2418 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2419 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2420 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2421}
2422
2423// This test verifies the call setup when remote answer with video only and
2424// later updates with audio.
2425TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002426 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2428 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
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;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002433 options.recv_audio = false;
2434 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2436 offer, options, cricket::SEC_ENABLED);
2437
2438 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2439 // and answer.
2440 SetLocalDescriptionWithoutError(offer);
2441 SetRemoteDescriptionWithoutError(answer);
2442
2443 video_channel_ = media_engine_->GetVideoChannel(0);
2444 voice_channel_ = media_engine_->GetVoiceChannel(0);
2445
2446 ASSERT_TRUE(voice_channel_ == NULL);
2447 ASSERT_TRUE(video_channel_ != NULL);
2448
2449 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2450 ASSERT_EQ(1u, video_channel_->send_streams().size());
2451 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2452
2453 // Update the session descriptions, with Audio and Video.
2454 mediastream_signaling_.SendAudioVideoStream2();
2455 CreateAndSetRemoteOfferAndLocalAnswer();
2456
2457 voice_channel_ = media_engine_->GetVoiceChannel(0);
2458 ASSERT_TRUE(voice_channel_ != NULL);
2459
2460 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2461 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2462 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2463 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2464
2465 // Change session back to video only.
2466 mediastream_signaling_.UseOptionsVideoOnly();
2467 CreateAndSetRemoteOfferAndLocalAnswer();
2468
2469 video_channel_ = media_engine_->GetVideoChannel(0);
2470 voice_channel_ = media_engine_->GetVoiceChannel(0);
2471
2472 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2473 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2474 ASSERT_EQ(1u, video_channel_->send_streams().size());
2475 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2476}
2477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002479 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002481 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 VerifyCryptoParams(offer->description());
2483 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002484 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 VerifyCryptoParams(answer->description());
2486}
2487
2488TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002489 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002490 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002492 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 VerifyNoCryptoParams(offer->description(), false);
2494}
2495
2496TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002497 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 VerifyAnswerFromNonCryptoOffer();
2499}
2500
2501TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002502 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 VerifyAnswerFromCryptoOffer();
2504}
2505
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002506// This test verifies that setLocalDescription fails if
2507// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2508TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002509 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002510 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002511 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2512
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002513 std::string sdp;
2514 RemoveIceUfragPwdLines(offer.get(), &sdp);
2515 SessionDescriptionInterface* modified_offer =
2516 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002517 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002518}
2519
2520// This test verifies that setRemoteDescription fails if
2521// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2522TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002523 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002524 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002525 std::string sdp;
2526 RemoveIceUfragPwdLines(offer.get(), &sdp);
2527 SessionDescriptionInterface* modified_offer =
2528 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002529 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002530}
2531
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002532// This test verifies that setLocalDescription fails if local offer has
2533// too short ice ufrag and pwd strings.
2534TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002535 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002536 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002537 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2538
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002539 std::string sdp;
2540 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2541 // recommended values of 4 and 22 bytes respectively.
2542 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2543 SessionDescriptionInterface* modified_offer =
2544 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2545 std::string error;
2546 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2547
2548 // Test with string greater than 256.
2549 sdp.clear();
2550 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2551 &sdp);
2552 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2553 NULL);
2554 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2555}
2556
2557// This test verifies that setRemoteDescription fails if remote offer has
2558// too short ice ufrag and pwd strings.
2559TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002560 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002561 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002562 std::string sdp;
2563 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2564 // recommended values of 4 and 22 bytes respectively.
2565 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2566 SessionDescriptionInterface* modified_offer =
2567 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2568 std::string error;
2569 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2570
2571 sdp.clear();
2572 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2573 &sdp);
2574 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2575 NULL);
2576 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2577}
2578
honghaiz503726c2015-07-31 12:37:38 -07002579// Test that if the remote description indicates the peer requested ICE restart
2580// (via a new ufrag or pwd), the old ICE candidates are not copied,
2581// and vice versa.
2582TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2583 Init();
2584 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2585
2586 // Create the first offer.
2587 std::string sdp;
2588 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2589 "abcdefghijklmnopqrstuvwx", &sdp);
2590 SessionDescriptionInterface* offer1 =
2591 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2592 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2593 0, "", "", "relay", 0, "");
2594 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2595 candidate1);
2596 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2597 SetRemoteDescriptionWithoutError(offer1);
2598 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2599
2600 // The second offer has the same ufrag and pwd but different address.
2601 sdp.clear();
2602 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2603 "abcdefghijklmnopqrstuvwx", &sdp);
2604 SessionDescriptionInterface* offer2 =
2605 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2606 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2607 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2608 candidate1);
2609 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2610 SetRemoteDescriptionWithoutError(offer2);
2611 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2612
2613 // The third offer has a different ufrag and different address.
2614 sdp.clear();
2615 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2616 "abcdefghijklmnopqrstuvwx", &sdp);
2617 SessionDescriptionInterface* offer3 =
2618 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2619 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2620 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2621 candidate1);
2622 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2623 SetRemoteDescriptionWithoutError(offer3);
2624 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2625
2626 // The fourth offer has no candidate but a different ufrag/pwd.
2627 sdp.clear();
2628 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2629 "abcdefghijklmnopqrstuvyz", &sdp);
2630 SessionDescriptionInterface* offer4 =
2631 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2632 SetRemoteDescriptionWithoutError(offer4);
2633 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2634}
2635
Donald Curtisd4f769d2015-05-28 09:48:21 -07002636// Test that candidates sent to the "video" transport do not get pushed down to
2637// the "audio" transport channel when bundling using TransportProxy.
2638TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2639 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2640
2641 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2642 mediastream_signaling_.SendAudioVideoStream1();
2643
2644 PeerConnectionInterface::RTCOfferAnswerOptions options;
2645 options.use_rtp_mux = true;
2646
2647 SessionDescriptionInterface* offer = CreateRemoteOffer();
2648 SetRemoteDescriptionWithoutError(offer);
2649
2650 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2651 SetLocalDescriptionWithoutError(answer);
2652
2653 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2654 session_->GetTransportProxy("video")->impl());
2655
2656 cricket::Transport* t = session_->GetTransport("audio");
2657
2658 // Checks if one of the transport channels contains a connection using a given
2659 // port.
2660 auto connection_with_remote_port = [t](int port) {
2661 cricket::TransportStats stats;
2662 t->GetStats(&stats);
2663 for (auto& chan_stat : stats.channel_stats) {
2664 for (auto& conn_info : chan_stat.connection_infos) {
2665 if (conn_info.remote_candidate.address().port() == port) {
2666 return true;
2667 }
2668 }
2669 }
2670 return false;
2671 };
2672
2673 EXPECT_FALSE(connection_with_remote_port(5000));
2674 EXPECT_FALSE(connection_with_remote_port(5001));
2675 EXPECT_FALSE(connection_with_remote_port(6000));
2676
2677 // The way the *_WAIT checks work is they only wait if the condition fails,
2678 // which does not help in the case where state is not changing. This is
2679 // problematic in this test since we want to verify that adding a video
2680 // candidate does _not_ change state. So we interleave candidates and assume
2681 // that messages are executed in the order they were posted.
2682
2683 // First audio candidate.
2684 cricket::Candidate candidate0;
2685 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2686 candidate0.set_component(1);
2687 candidate0.set_protocol("udp");
2688 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2689 candidate0);
2690 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2691
2692 // Video candidate.
2693 cricket::Candidate candidate1;
2694 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2695 candidate1.set_component(1);
2696 candidate1.set_protocol("udp");
2697 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2698 candidate1);
2699 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2700
2701 // Second audio candidate.
2702 cricket::Candidate candidate2;
2703 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2704 candidate2.set_component(1);
2705 candidate2.set_protocol("udp");
2706 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2707 candidate2);
2708 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2709
2710 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2711 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2712
2713 // No need here for a _WAIT check since we are checking that state hasn't
2714 // changed: if this is false we would be doing waits for nothing and if this
2715 // is true then there will be no messages processed anyways.
2716 EXPECT_FALSE(connection_with_remote_port(6000));
2717}
2718
Peter Thatcher4eddf182015-04-30 10:55:59 -07002719// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002720TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2721 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002723
2724 PeerConnectionInterface::RTCOfferAnswerOptions options;
2725 options.use_rtp_mux = true;
2726
2727 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002729
2730 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2731 session_->GetTransportProxy("video")->impl());
2732
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002734 SessionDescriptionInterface* answer =
2735 CreateRemoteAnswer(session_->local_description());
2736 SetRemoteDescriptionWithoutError(answer);
2737
2738 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2739 session_->GetTransportProxy("video")->impl());
2740}
2741
2742// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2743TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2744 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2745 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002746
Donald Curtis0e209b02015-03-24 09:29:54 -07002747 PeerConnectionInterface::RTCOfferAnswerOptions options;
2748 options.use_rtp_mux = true;
2749
2750 SessionDescriptionInterface* offer = CreateOffer(options);
2751 SetLocalDescriptionWithoutError(offer);
2752
2753 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2754 session_->GetTransportProxy("video")->impl());
2755
2756 mediastream_signaling_.SendAudioVideoStream2();
2757
2758 // Remove BUNDLE from the answer.
2759 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2760 CreateRemoteAnswer(session_->local_description()));
2761 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2762 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2763 JsepSessionDescription* modified_answer =
2764 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2765 modified_answer->Initialize(answer_copy, "1", "1");
2766 SetRemoteDescriptionWithoutError(modified_answer); //
2767
2768 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2769 session_->GetTransportProxy("video")->impl());
2770}
2771
2772// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2773TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2774 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2775 mediastream_signaling_.SendAudioVideoStream1();
2776
2777 PeerConnectionInterface::RTCOfferAnswerOptions options;
2778 options.use_rtp_mux = true;
2779
2780 SessionDescriptionInterface* offer = CreateOffer(options);
2781 SetLocalDescriptionWithoutError(offer);
2782
2783 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2784 session_->GetTransportProxy("video")->impl());
2785
2786 mediastream_signaling_.SendAudioVideoStream2();
2787 SessionDescriptionInterface* answer =
2788 CreateRemoteAnswer(session_->local_description());
2789 SetRemoteDescriptionWithoutError(answer);
2790
2791 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2792 session_->GetTransportProxy("video")->impl());
2793}
2794
2795// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2796TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2797 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2798 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002799
Donald Curtis0e209b02015-03-24 09:29:54 -07002800 PeerConnectionInterface::RTCOfferAnswerOptions options;
2801 options.use_rtp_mux = true;
2802
2803 SessionDescriptionInterface* offer = CreateOffer(options);
2804 SetLocalDescriptionWithoutError(offer);
2805
2806 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2807 session_->GetTransportProxy("video")->impl());
2808
2809 mediastream_signaling_.SendAudioVideoStream2();
2810
2811 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002812 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 CreateRemoteAnswer(session_->local_description()));
2814 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2815 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2816 JsepSessionDescription* modified_answer =
2817 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2818 modified_answer->Initialize(answer_copy, "1", "1");
2819 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820
Donald Curtis0e209b02015-03-24 09:29:54 -07002821 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2822 session_->GetTransportProxy("video")->impl());
2823}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824
Peter Thatcher4eddf182015-04-30 10:55:59 -07002825// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002826TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2827 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2828 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002829
Donald Curtis0e209b02015-03-24 09:29:54 -07002830 PeerConnectionInterface::RTCOfferAnswerOptions options;
2831 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002832
Donald Curtis0e209b02015-03-24 09:29:54 -07002833 SessionDescriptionInterface* offer = CreateOffer(options);
2834 SetLocalDescriptionWithoutError(offer);
2835
2836 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2837 session_->GetTransportProxy("video")->impl());
2838
2839 mediastream_signaling_.SendAudioVideoStream2();
2840 SessionDescriptionInterface* answer =
2841 CreateRemoteAnswer(session_->local_description());
2842 SetRemoteDescriptionWithoutError(answer);
2843
2844 // This should lead to an audio-only call but isn't implemented
2845 // correctly yet.
2846 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2847 session_->GetTransportProxy("video")->impl());
2848}
2849
2850// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2851TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2852 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2853 mediastream_signaling_.SendAudioVideoStream1();
2854 PeerConnectionInterface::RTCOfferAnswerOptions options;
2855 options.use_rtp_mux = true;
2856
2857 SessionDescriptionInterface* offer = CreateOffer(options);
2858 SetLocalDescriptionWithoutError(offer);
2859
2860 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2861 session_->GetTransportProxy("video")->impl());
2862
2863 mediastream_signaling_.SendAudioVideoStream2();
2864
2865 // Remove BUNDLE from the answer.
2866 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2867 CreateRemoteAnswer(session_->local_description()));
2868 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2869 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2870 JsepSessionDescription* modified_answer =
2871 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2872 modified_answer->Initialize(answer_copy, "1", "1");
2873 SetRemoteDescriptionWithoutError(modified_answer); //
2874
2875 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2876 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877}
2878
Peter Thatcher4eddf182015-04-30 10:55:59 -07002879// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2880TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2881 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2882 mediastream_signaling_.SendAudioVideoStream1();
2883
2884 PeerConnectionInterface::RTCOfferAnswerOptions options;
2885 options.use_rtp_mux = true;
2886
2887 SessionDescriptionInterface* offer = CreateOffer(options);
2888 SetRemoteDescriptionWithoutError(offer);
2889
2890 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2891 session_->GetTransportProxy("video")->impl());
2892}
2893
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002894TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2895 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2896 mediastream_signaling_.SendAudioVideoStream1();
2897
2898 PeerConnectionInterface::RTCOfferAnswerOptions options;
2899 SessionDescriptionInterface* offer = CreateOffer(options);
2900 SetLocalDescriptionWithoutError(offer);
2901
2902 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2903 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2904
2905 mediastream_signaling_.SendAudioVideoStream2();
2906 SessionDescriptionInterface* answer =
2907 CreateRemoteAnswer(session_->local_description());
2908 SetRemoteDescriptionWithoutError(answer);
2909
2910 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2911 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2912}
2913
2914TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2915 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2916 mediastream_signaling_.SendAudioVideoStream1();
2917
2918 PeerConnectionInterface::RTCOfferAnswerOptions options;
2919 SessionDescriptionInterface* offer = CreateOffer(options);
2920 SetLocalDescriptionWithoutError(offer);
2921
2922 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2923 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2924
2925 mediastream_signaling_.SendAudioVideoStream2();
2926 SessionDescriptionInterface* answer =
2927 CreateRemoteAnswer(session_->local_description());
2928 SetRemoteDescriptionWithoutError(answer);
2929
2930 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2931 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2932}
2933
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002934// This test verifies that SetLocalDescription and SetRemoteDescription fails
2935// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2936TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002937 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002938 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002939
2940 PeerConnectionInterface::RTCOfferAnswerOptions options;
2941 options.use_rtp_mux = true;
2942
2943 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002944 std::string offer_str;
2945 offer->ToString(&offer_str);
2946 // Disable rtcp-mux
2947 const std::string rtcp_mux = "rtcp-mux";
2948 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002949 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002950 xrtcp_mux.c_str(), xrtcp_mux.length(),
2951 &offer_str);
2952 JsepSessionDescription *local_offer =
2953 new JsepSessionDescription(JsepSessionDescription::kOffer);
2954 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002955 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002956 JsepSessionDescription *remote_offer =
2957 new JsepSessionDescription(JsepSessionDescription::kOffer);
2958 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002959 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002960 // Trying unmodified SDP.
2961 SetLocalDescriptionWithoutError(offer);
2962}
2963
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002965 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 mediastream_signaling_.SendAudioVideoStream1();
2967 CreateAndSetRemoteOfferAndLocalAnswer();
2968 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2969 ASSERT_TRUE(channel != NULL);
2970 ASSERT_EQ(1u, channel->recv_streams().size());
2971 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2972 double left_vol, right_vol;
2973 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2974 EXPECT_EQ(1, left_vol);
2975 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002976 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002977 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2979 EXPECT_EQ(0, left_vol);
2980 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002981 EXPECT_EQ(0, renderer->channel_id());
2982 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2984 EXPECT_EQ(1, left_vol);
2985 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002986 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987}
2988
2989TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002990 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 mediastream_signaling_.SendAudioVideoStream1();
2992 CreateAndSetRemoteOfferAndLocalAnswer();
2993 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2994 ASSERT_TRUE(channel != NULL);
2995 ASSERT_EQ(1u, channel->send_streams().size());
2996 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2997 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2998
2999 cricket::AudioOptions options;
3000 options.echo_cancellation.Set(true);
3001
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003002 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003003 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3005 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003006 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003007 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003009 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003010 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3012 bool value;
3013 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3014 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003015 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003016 EXPECT_TRUE(renderer->sink() == NULL);
3017}
3018
3019TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003020 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003021 mediastream_signaling_.SendAudioVideoStream1();
3022 CreateAndSetRemoteOfferAndLocalAnswer();
3023 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3024 ASSERT_TRUE(channel != NULL);
3025 ASSERT_EQ(1u, channel->send_streams().size());
3026 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3027
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003028 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003029 cricket::AudioOptions options;
3030 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3031 EXPECT_TRUE(renderer->sink() != NULL);
3032
3033 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3034 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3035 // SetSink(NULL) callback afterwards.
3036 renderer.reset();
3037
3038 // This will trigger SetSink(NULL) if no OnClose() callback.
3039 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040}
3041
3042TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003043 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 mediastream_signaling_.SendAudioVideoStream1();
3045 CreateAndSetRemoteOfferAndLocalAnswer();
3046 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3047 ASSERT_TRUE(channel != NULL);
3048 ASSERT_LT(0u, channel->renderers().size());
3049 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3050 ASSERT_EQ(1u, channel->recv_streams().size());
3051 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3052 cricket::FakeVideoRenderer renderer;
3053 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3054 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3055 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3056 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3057}
3058
3059TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003060 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 mediastream_signaling_.SendAudioVideoStream1();
3062 CreateAndSetRemoteOfferAndLocalAnswer();
3063 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3064 ASSERT_TRUE(channel != NULL);
3065 ASSERT_EQ(1u, channel->send_streams().size());
3066 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3067 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3068 cricket::VideoOptions* options = NULL;
3069 session_->SetVideoSend(send_ssrc, false, options);
3070 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3071 session_->SetVideoSend(send_ssrc, true, options);
3072 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3073}
3074
3075TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3076 TestCanInsertDtmf(false);
3077}
3078
3079TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3080 TestCanInsertDtmf(true);
3081}
3082
3083TEST_F(WebRtcSessionTest, InsertDtmf) {
3084 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003085 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003086 mediastream_signaling_.SendAudioVideoStream1();
3087 CreateAndSetRemoteOfferAndLocalAnswer();
3088 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3089 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3090
3091 // Insert DTMF
3092 const int expected_flags = DF_SEND;
3093 const int expected_duration = 90;
3094 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3095 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3096 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3097
3098 // Verify
3099 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3100 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3101 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3102 expected_duration, expected_flags));
3103 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3104 expected_duration, expected_flags));
3105 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3106 expected_duration, expected_flags));
3107}
3108
3109// This test verifies the |initiator| flag when session initiates the call.
3110TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003111 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003112 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003113 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3115 SetLocalDescriptionWithoutError(offer);
3116 EXPECT_TRUE(session_->initiator());
3117 SetRemoteDescriptionWithoutError(answer);
3118 EXPECT_TRUE(session_->initiator());
3119}
3120
3121// This test verifies the |initiator| flag when session receives the call.
3122TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003123 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003124 EXPECT_FALSE(session_->initiator());
3125 SessionDescriptionInterface* offer = CreateRemoteOffer();
3126 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003127 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128
3129 EXPECT_FALSE(session_->initiator());
3130 SetLocalDescriptionWithoutError(answer);
3131 EXPECT_FALSE(session_->initiator());
3132}
3133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3135TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003136 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003137 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003138 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003140 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003141 CreateRemoteAnswer(session_->local_description()));
3142
3143 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3144 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003145 JsepSessionDescription* modified_answer =
3146 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147
3148 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3149 answer->session_id(),
3150 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003151 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152
wu@webrtc.org4e393072014-04-07 17:04:35 +00003153 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003154 std::string sdp;
3155 EXPECT_TRUE(answer->ToString(&sdp));
3156 const std::string kAudioMid = "a=mid:audio";
3157 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003158 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003159 kAudioMidReplaceStr.c_str(),
3160 kAudioMidReplaceStr.length(),
3161 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003162 SessionDescriptionInterface* modified_answer1 =
3163 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003164 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003165
wu@webrtc.org4e393072014-04-07 17:04:35 +00003166 // Different media types.
3167 EXPECT_TRUE(answer->ToString(&sdp));
3168 const std::string kAudioMline = "m=audio";
3169 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003170 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003171 kAudioMlineReplaceStr.c_str(),
3172 kAudioMlineReplaceStr.length(),
3173 &sdp);
3174 SessionDescriptionInterface* modified_answer2 =
3175 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3176 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3177
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003178 SetRemoteDescriptionWithoutError(answer.release());
3179}
3180
3181// Verifying remote offer and local answer have matching m-lines as per
3182// RFC 3264.
3183TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003184 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185 mediastream_signaling_.SendAudioVideoStream1();
3186 SessionDescriptionInterface* offer = CreateRemoteOffer();
3187 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003188 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189
3190 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3191 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003192 JsepSessionDescription* modified_answer =
3193 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194
3195 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3196 answer->session_id(),
3197 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003198 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199 SetLocalDescriptionWithoutError(answer);
3200}
3201
3202// This test verifies that WebRtcSession does not start candidate allocation
3203// before SetLocalDescription is called.
3204TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003205 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206 mediastream_signaling_.SendAudioVideoStream1();
3207 SessionDescriptionInterface* offer = CreateRemoteOffer();
3208 cricket::Candidate candidate;
3209 candidate.set_component(1);
3210 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3211 candidate);
3212 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3213 cricket::Candidate candidate1;
3214 candidate1.set_component(1);
3215 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3216 candidate1);
3217 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3218 SetRemoteDescriptionWithoutError(offer);
3219 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3220 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3221
3222 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003223 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3225 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3226
wu@webrtc.org91053e72013-08-10 07:18:04 +00003227 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228 SetLocalDescriptionWithoutError(answer);
3229 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3230 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3231 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3232}
3233
3234// This test verifies that crypto parameter is updated in local session
3235// description as per security policy set in MediaSessionDescriptionFactory.
3236TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003237 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003239 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240
3241 // Making sure SetLocalDescription correctly sets crypto value in
3242 // SessionDescription object after de-serialization of sdp string. The value
3243 // will be set as per MediaSessionDescriptionFactory.
3244 std::string offer_str;
3245 offer->ToString(&offer_str);
3246 SessionDescriptionInterface* jsep_offer_str =
3247 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3248 SetLocalDescriptionWithoutError(jsep_offer_str);
3249 EXPECT_TRUE(session_->voice_channel()->secure_required());
3250 EXPECT_TRUE(session_->video_channel()->secure_required());
3251}
3252
3253// This test verifies the crypto parameter when security is disabled.
3254TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003255 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003256 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003258 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259
3260 // Making sure SetLocalDescription correctly sets crypto value in
3261 // SessionDescription object after de-serialization of sdp string. The value
3262 // will be set as per MediaSessionDescriptionFactory.
3263 std::string offer_str;
3264 offer->ToString(&offer_str);
3265 SessionDescriptionInterface *jsep_offer_str =
3266 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3267 SetLocalDescriptionWithoutError(jsep_offer_str);
3268 EXPECT_FALSE(session_->voice_channel()->secure_required());
3269 EXPECT_FALSE(session_->video_channel()->secure_required());
3270}
3271
3272// This test verifies that an answer contains new ufrag and password if an offer
3273// with new ufrag and password is received.
3274TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003275 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003277 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003278 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279 CreateRemoteOffer(options));
3280 SetRemoteDescriptionWithoutError(offer.release());
3281
3282 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003283 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003284 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285 SetLocalDescriptionWithoutError(answer.release());
3286
3287 // Receive an offer with new ufrag and password.
3288 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003289 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003290 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 SetRemoteDescriptionWithoutError(updated_offer1.release());
3292
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003293 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003294 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295
3296 CompareIceUfragAndPassword(updated_answer1->description(),
3297 session_->local_description()->description(),
3298 false);
3299
3300 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003301}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302
wu@webrtc.org91053e72013-08-10 07:18:04 +00003303// This test verifies that an answer contains old ufrag and password if an offer
3304// with old ufrag and password is received.
3305TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003306 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003307 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003308 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003310 CreateRemoteOffer(options));
3311 SetRemoteDescriptionWithoutError(offer.release());
3312
3313 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003314 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003315 CreateAnswer(NULL));
3316 SetLocalDescriptionWithoutError(answer.release());
3317
3318 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003320 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003321 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 SetRemoteDescriptionWithoutError(updated_offer2.release());
3323
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003324 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003325 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326
3327 CompareIceUfragAndPassword(updated_answer2->description(),
3328 session_->local_description()->description(),
3329 true);
3330
3331 SetLocalDescriptionWithoutError(updated_answer2.release());
3332}
3333
3334TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003335 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003337 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 const std::string session_id_orig = offer->session_id();
3339 const std::string session_version_orig = offer->session_version();
3340 SetLocalDescriptionWithoutError(offer);
3341
3342 video_channel_ = media_engine_->GetVideoChannel(0);
3343 video_channel_->set_fail_set_send_codecs(true);
3344
3345 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003346 SessionDescriptionInterface* answer =
3347 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003348 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003349}
3350
3351// Runs the loopback call test with BUNDLE and STUN disabled.
3352TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3353 // Lets try with only UDP ports.
Peter Thatcher2159b892015-08-21 20:46:05 -07003354 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003355 cricket::PORTALLOCATOR_DISABLE_STUN |
3356 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357 TestLoopbackCall();
3358}
3359
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003360TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003361 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003362 cricket::PORTALLOCATOR_DISABLE_STUN |
3363 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3364 cricket::PORTALLOCATOR_DISABLE_RELAY);
3365
3366 // best connection is IPv6 since it has higher network preference.
3367 LoopbackNetworkConfiguration config;
3368 config.test_ipv6_network_ = true;
3369 config.best_connection_after_initial_ice_converged_ =
3370 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3371
3372 TestLoopbackCall(config);
3373}
3374
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003375// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003376TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003377 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3378 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003379 TestLoopbackCall();
3380}
3381
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003382TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003383 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003385 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003387 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3388 std::string error_code_str = "ERROR_CONTENT";
3389 std::string error_desc = "Fake session error description.";
3390 session_->SetError(error_code, error_desc);
3391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3393 SessionDescriptionInterface* answer =
3394 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003395
3396 std::string action;
3397 std::ostringstream session_error_msg;
3398 session_error_msg << kSessionError << error_code_str << ". ";
3399 session_error_msg << kSessionErrorDesc << error_desc << ".";
3400 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3401 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402}
3403
3404TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3405 constraints_.reset(new FakeConstraints());
3406 constraints_->AddOptional(
3407 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003408 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409
3410 SetLocalDescriptionWithDataChannel();
3411 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3412}
3413
3414TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003415 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416
3417 constraints_.reset(new FakeConstraints());
3418 constraints_->AddOptional(
3419 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003420 options_.disable_sctp_data_channels = false;
3421
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003422 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423
3424 SetLocalDescriptionWithDataChannel();
3425 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3426}
3427
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003428TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003429 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003430
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003431 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003432
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003433 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003434 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003435 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3436}
3437
3438TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003439 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003440 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003441 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003442
3443 // Create remote offer with SCTP.
3444 cricket::MediaSessionOptions options;
3445 options.data_channel_type = cricket::DCT_SCTP;
3446 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003447 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003448 SetRemoteDescriptionWithoutError(offer);
3449
3450 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003451 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003452 EXPECT_TRUE(answer != NULL);
3453 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3454 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003455}
3456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3458 constraints_.reset(new FakeConstraints());
3459 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003460 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003461 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462
3463 SetLocalDescriptionWithDataChannel();
3464 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3465}
3466
3467TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003468 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003470 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471
3472 SetLocalDescriptionWithDataChannel();
3473 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3474}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003475
wu@webrtc.org97077a32013-10-25 21:18:33 +00003476TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003477 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003478 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003479 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003480
3481 SetLocalDescriptionWithDataChannel();
3482 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3483}
3484
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003485TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003486 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003487 const int new_send_port = 9998;
3488 const int new_recv_port = 7775;
3489
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003490 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003491 SetFactoryDtlsSrtp();
3492
3493 // By default, don't actually add the codecs to desc_factory_; they don't
3494 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3495 // let the session description get parsed. That'll get the proper codecs
3496 // into the stream.
3497 cricket::MediaSessionOptions options;
3498 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3499 "stream1", new_send_port, options);
3500
3501 // SetRemoteDescription will take the ownership of the offer.
3502 SetRemoteDescriptionWithoutError(offer);
3503
3504 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3505 new_recv_port, CreateAnswer(NULL));
3506 ASSERT_TRUE(answer != NULL);
3507
3508 // Now set the local description, which'll take ownership of the answer.
3509 SetLocalDescriptionWithoutError(answer);
3510
3511 // TEST PLAN: Set the port number to something new, set it in the SDP,
3512 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003513 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003514 dci.reliable = true;
3515 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003516 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003517 session_->CreateDataChannel("datachannel", &dci);
3518
3519 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3520 int portnum = -1;
3521 ASSERT_TRUE(ch != NULL);
3522 ASSERT_EQ(1UL, ch->send_codecs().size());
3523 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003524 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003525 ch->send_codecs()[0].name.c_str()));
3526 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3527 &portnum));
3528 EXPECT_EQ(new_send_port, portnum);
3529
3530 ASSERT_EQ(1UL, ch->recv_codecs().size());
3531 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003532 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003533 ch->recv_codecs()[0].name.c_str()));
3534 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3535 &portnum));
3536 EXPECT_EQ(new_recv_port, portnum);
3537}
3538
wu@webrtc.org91053e72013-08-10 07:18:04 +00003539// Verifies that CreateOffer succeeds when CreateOffer is called before async
3540// identity generation is finished.
3541TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003542 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003543 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003544
3545 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003546 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003547 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3548
wu@webrtc.org91053e72013-08-10 07:18:04 +00003549 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003550 VerifyNoCryptoParams(offer->description(), true);
3551 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003552}
3553
3554// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3555// identity generation is finished.
3556TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003557 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003558 InitWithDtls();
3559 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003560
3561 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003562 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003563 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003564 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003565 ASSERT_TRUE(offer.get() != NULL);
3566 SetRemoteDescriptionWithoutError(offer.release());
3567
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003568 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003569 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003570 VerifyNoCryptoParams(answer->description(), true);
3571 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003572}
3573
3574// Verifies that CreateOffer succeeds when CreateOffer is called after async
3575// identity generation is finished.
3576TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003577 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003578 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003579
3580 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003581
3582 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003583 EXPECT_TRUE(offer != NULL);
3584}
3585
3586// Verifies that CreateOffer fails when CreateOffer is called after async
3587// identity generation fails.
3588TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003589 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003590 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003591
3592 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003593
3594 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003595 EXPECT_TRUE(offer == NULL);
3596}
3597
3598// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3599// before async identity generation is finished.
3600TEST_F(WebRtcSessionTest,
3601 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003602 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003603 VerifyMultipleAsyncCreateDescription(
3604 true, CreateSessionDescriptionRequest::kOffer);
3605}
3606
3607// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3608// before async identity generation fails.
3609TEST_F(WebRtcSessionTest,
3610 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003611 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003612 VerifyMultipleAsyncCreateDescription(
3613 false, CreateSessionDescriptionRequest::kOffer);
3614}
3615
3616// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3617// before async identity generation is finished.
3618TEST_F(WebRtcSessionTest,
3619 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003620 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003621 VerifyMultipleAsyncCreateDescription(
3622 true, CreateSessionDescriptionRequest::kAnswer);
3623}
3624
3625// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3626// before async identity generation fails.
3627TEST_F(WebRtcSessionTest,
3628 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003629 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003630 VerifyMultipleAsyncCreateDescription(
3631 false, CreateSessionDescriptionRequest::kAnswer);
3632}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003633
3634// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3635// offer has no SDES crypto but only DTLS fingerprint.
3636TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3637 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003638 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003639 // Create a remote offer with secured transport disabled.
3640 cricket::MediaSessionOptions options;
3641 JsepSessionDescription* offer(CreateRemoteOffer(
3642 options, cricket::SEC_DISABLED));
3643 // Adds a DTLS fingerprint to the remote offer.
3644 cricket::SessionDescription* sdp = offer->description();
3645 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3646 ASSERT_TRUE(audio != NULL);
3647 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3648 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003649 rtc::SSLFingerprint::CreateFromRfc4572(
3650 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003651 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003652 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003653}
3654
wu@webrtc.orgde305012013-10-31 15:40:38 +00003655// This test verifies DSCP is properly applied on the media channels.
3656TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3657 constraints_.reset(new FakeConstraints());
3658 constraints_->AddOptional(
3659 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003660 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003661 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003662 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003663
3664 SetLocalDescriptionWithoutError(offer);
3665
3666 video_channel_ = media_engine_->GetVideoChannel(0);
3667 voice_channel_ = media_engine_->GetVoiceChannel(0);
3668
3669 ASSERT_TRUE(video_channel_ != NULL);
3670 ASSERT_TRUE(voice_channel_ != NULL);
3671 cricket::AudioOptions audio_options;
3672 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3673 cricket::VideoOptions video_options;
3674 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3675 EXPECT_TRUE(audio_options.dscp.IsSet());
3676 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3677 EXPECT_TRUE(video_options.dscp.IsSet());
3678 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3679}
3680
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003681TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3682 constraints_.reset(new FakeConstraints());
3683 constraints_->AddOptional(
3684 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3685 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003686 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003687 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003688 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003689
3690 SetLocalDescriptionWithoutError(offer);
3691
3692 video_channel_ = media_engine_->GetVideoChannel(0);
3693
3694 ASSERT_TRUE(video_channel_ != NULL);
3695 cricket::VideoOptions video_options;
3696 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3697 EXPECT_TRUE(
3698 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3699}
3700
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003701TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3702 // Number of unsignalled receiving streams should be between 0 and
3703 // kMaxUnsignalledRecvStreams.
3704 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3705 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3706 kMaxUnsignalledRecvStreams);
3707 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3708}
3709
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003710TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3711 constraints_.reset(new FakeConstraints());
3712 constraints_->AddOptional(
3713 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3714 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003715 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003716 mediastream_signaling_.SendAudioVideoStream1();
3717 SessionDescriptionInterface* offer = CreateOffer();
3718
3719 SetLocalDescriptionWithoutError(offer);
3720
3721 voice_channel_ = media_engine_->GetVoiceChannel(0);
3722
3723 ASSERT_TRUE(voice_channel_ != NULL);
3724 cricket::AudioOptions audio_options;
3725 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3726 EXPECT_TRUE(
3727 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3728}
3729
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003730// Tests that we can renegotiate new media content with ICE candidates in the
3731// new remote SDP.
3732TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003733 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003734 InitWithDtls();
3735 SetFactoryDtlsSrtp();
3736
3737 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003738 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003739 SetLocalDescriptionWithoutError(offer);
3740
3741 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3742 SetRemoteDescriptionWithoutError(answer);
3743
3744 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003745 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003746 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3747
3748 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003749 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003750 candidate1.set_component(1);
3751 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3752 candidate1);
3753 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3754 SetRemoteDescriptionWithoutError(offer);
3755
3756 answer = CreateAnswer(NULL);
3757 SetLocalDescriptionWithoutError(answer);
3758}
3759
3760// Tests that we can renegotiate new media content with ICE candidates separated
3761// from the remote SDP.
3762TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003763 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003764 InitWithDtls();
3765 SetFactoryDtlsSrtp();
3766
3767 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003768 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003769 SetLocalDescriptionWithoutError(offer);
3770
3771 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3772 SetRemoteDescriptionWithoutError(answer);
3773
3774 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003775 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003776 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3777 SetRemoteDescriptionWithoutError(offer);
3778
3779 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003780 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003781 candidate1.set_component(1);
3782 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3783 candidate1);
3784 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3785
3786 answer = CreateAnswer(NULL);
3787 SetLocalDescriptionWithoutError(answer);
3788}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003789// Tests that RTX codec is removed from the answer when it isn't supported
3790// by local side.
3791TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3792 Init();
3793 mediastream_signaling_.SendAudioVideoStream1();
3794 std::string offer_sdp(kSdpWithRtx);
3795
3796 SessionDescriptionInterface* offer =
3797 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3798 EXPECT_TRUE(offer->ToString(&offer_sdp));
3799
3800 // Offer SDP contains the RTX codec.
3801 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3802 SetRemoteDescriptionWithoutError(offer);
3803
3804 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3805 std::string answer_sdp;
3806 answer->ToString(&answer_sdp);
3807 // Answer SDP removes the unsupported RTX codec.
3808 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3809 SetLocalDescriptionWithoutError(answer);
3810}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003811
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003812// This verifies that the voice channel after bundle has both options from video
3813// and voice channels.
3814TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3815 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3816 mediastream_signaling_.SendAudioVideoStream1();
3817
3818 PeerConnectionInterface::RTCOfferAnswerOptions options;
3819 options.use_rtp_mux = true;
3820
3821 SessionDescriptionInterface* offer = CreateOffer(options);
3822 SetLocalDescriptionWithoutError(offer);
3823
3824 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3825 rtc::Socket::Option::OPT_SNDBUF, 4000);
3826
3827 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3828 rtc::Socket::Option::OPT_RCVBUF, 8000);
3829
3830 int option_val;
3831 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3832 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3833 EXPECT_EQ(4000, option_val);
3834 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3835 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3836
3837 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3838 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3839 EXPECT_EQ(8000, option_val);
3840 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3841 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3842
3843 EXPECT_NE(session_->voice_channel()->transport_channel(),
3844 session_->video_channel()->transport_channel());
3845
3846 mediastream_signaling_.SendAudioVideoStream2();
3847 SessionDescriptionInterface* answer =
3848 CreateRemoteAnswer(session_->local_description());
3849 SetRemoteDescriptionWithoutError(answer);
3850
3851 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3852 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3853 EXPECT_EQ(4000, option_val);
3854
3855 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3856 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3857 EXPECT_EQ(8000, option_val);
3858}
3859
tommi0f620f42015-07-09 03:25:02 -07003860// Test creating a session, request multiple offers, destroy the session
3861// and make sure we got success/failure callbacks for all of the requests.
3862// Background: crbug.com/507307
3863TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3864 Init();
3865
3866 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3867 PeerConnectionInterface::RTCOfferAnswerOptions options;
3868 options.offer_to_receive_audio =
3869 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3870
3871 for (auto& o : observers) {
3872 o = new WebRtcSessionCreateSDPObserverForTest();
3873 session_->CreateOffer(o, options);
3874 }
3875
3876 session_.reset();
3877
3878 // Make sure we process pending messages on the current (signaling) thread
3879 // before checking we we got our callbacks. Quit() will do this and then
3880 // immediately exit. We won't need the queue after this point anyway.
3881 rtc::Thread::Current()->Quit();
3882
3883 for (auto& o : observers) {
3884 // We expect to have received a notification now even if the session was
3885 // terminated. The offer creation may or may not have succeeded, but we
3886 // must have received a notification which, so the only invalid state
3887 // is kInit.
3888 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3889 }
3890}
3891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003892// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3893// currently fails because upon disconnection and reconnection OnIceComplete is
3894// called more than once without returning to IceGatheringGathering.