blob: ecbd5074cd328941cc9333dddec9ac767c197e4b [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;
pthatcherfa301802015-08-11 04:12:56 -070074using cricket::NS_GINGLE_P2P;
75using cricket::NS_JINGLE_ICE_UDP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020083using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070085using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::IceCandidateCollection;
87using webrtc::JsepIceCandidate;
88using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000089using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::PeerConnectionInterface;
91using webrtc::SessionDescriptionInterface;
92using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000093using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000094using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kCreateChannelFailed;
96using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000099using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000100using webrtc::kSdpWithoutDtlsFingerprint;
101using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000103using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000104using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000106typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
107
wu@webrtc.org364f2042013-11-20 21:49:41 +0000108static const int kClientAddrPort = 0;
109static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000110static const char kClientIPv6AddrHost1[] =
111 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000112static const char kClientAddrHost2[] = "22.22.22.22";
113static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000114static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
115static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000116static const char kTurnUsername[] = "test";
117static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
119static const char kSessionVersion[] = "1";
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121// Media index of candidates belonging to the first media content.
122static const int kMediaContentIndex0 = 0;
123static const char kMediaContentName0[] = "audio";
124
125// Media index of candidates belonging to the second media content.
126static const int kMediaContentIndex1 = 1;
127static const char kMediaContentName1[] = "video";
128
129static const int kIceCandidatesTimeout = 10000;
130
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000131static const char kFakeDtlsFingerprint[] =
132 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
133 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
134
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000135static const char kTooLongIceUfragPwd[] =
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
140
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000141static const char kSdpWithRtx[] =
142 "v=0\r\n"
143 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
144 "s=-\r\n"
145 "t=0 0\r\n"
146 "a=msid-semantic: WMS stream1\r\n"
147 "m=video 9 RTP/SAVPF 0 96\r\n"
148 "c=IN IP4 0.0.0.0\r\n"
149 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
150 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
151 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
152 "a=mid:video\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
156 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
157 "a=rtpmap:0 fake_video_codec/90000\r\n"
158 "a=rtpmap:96 rtx/90000\r\n"
159 "a=fmtp:96 apt=0\r\n";
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161// Add some extra |newlines| to the |message| after |line|.
162static void InjectAfter(const std::string& line,
163 const std::string& newlines,
164 std::string* message) {
165 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 tmp.c_str(), tmp.length(), message);
168}
169
170class MockIceObserver : public webrtc::IceObserver {
171 public:
172 MockIceObserver()
173 : oncandidatesready_(false),
174 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
175 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
176 }
177
178 virtual void OnIceConnectionChange(
179 PeerConnectionInterface::IceConnectionState new_state) {
180 ice_connection_state_ = new_state;
181 }
182 virtual void OnIceGatheringChange(
183 PeerConnectionInterface::IceGatheringState new_state) {
184 // We can never transition back to "new".
185 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
186 ice_gathering_state_ = new_state;
187
188 // oncandidatesready_ really means "ICE gathering is complete".
189 // This if statement ensures that this value remains correct when we
190 // transition from kIceGatheringComplete to kIceGatheringGathering.
191 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
192 oncandidatesready_ = false;
193 }
194 }
195
196 // Found a new candidate.
197 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000198 switch (candidate->sdp_mline_index()) {
199 case kMediaContentIndex0:
200 mline_0_candidates_.push_back(candidate->candidate());
201 break;
202 case kMediaContentIndex1:
203 mline_1_candidates_.push_back(candidate->candidate());
204 break;
205 default:
206 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000208
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // The ICE gathering state should always be Gathering when a candidate is
210 // received (or possibly Completed in the case of the final candidate).
211 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
212 }
213
214 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
215 virtual void OnIceComplete() {
216 EXPECT_FALSE(oncandidatesready_);
217 oncandidatesready_ = true;
218
219 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
220 // be called approximately simultaneously. For ease of testing, this
221 // check additionally requires that they be called in the above order.
222 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
223 ice_gathering_state_);
224 }
225
226 bool oncandidatesready_;
227 std::vector<cricket::Candidate> mline_0_candidates_;
228 std::vector<cricket::Candidate> mline_1_candidates_;
229 PeerConnectionInterface::IceConnectionState ice_connection_state_;
230 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
231};
232
233class WebRtcSessionForTest : public webrtc::WebRtcSession {
234 public:
235 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::Thread* signaling_thread,
237 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 cricket::PortAllocator* port_allocator,
239 webrtc::IceObserver* ice_observer,
240 webrtc::MediaStreamSignaling* mediastream_signaling)
241 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
242 mediastream_signaling) {
243 RegisterIceObserver(ice_observer);
244 }
245 virtual ~WebRtcSessionForTest() {}
246
247 using cricket::BaseSession::GetTransportProxy;
248 using webrtc::WebRtcSession::SetAudioPlayout;
249 using webrtc::WebRtcSession::SetAudioSend;
250 using webrtc::WebRtcSession::SetCaptureDevice;
251 using webrtc::WebRtcSession::SetVideoPlayout;
252 using webrtc::WebRtcSession::SetVideoSend;
253};
254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000258 enum State {
259 kInit,
260 kFailed,
261 kSucceeded,
262 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000263 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264
265 // CreateSessionDescriptionObserver implementation.
266 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000267 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000268 state_ = kSucceeded;
269 }
270 virtual void OnFailure(const std::string& error) {
271 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 SessionDescriptionInterface* description() { return description_.get(); }
275
276 SessionDescriptionInterface* ReleaseDescription() {
277 return description_.release();
278 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 protected:
283 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
285 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288};
289
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290class FakeAudioRenderer : public cricket::AudioRenderer {
291 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000292 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
293 virtual ~FakeAudioRenderer() {
294 if (sink_)
295 sink_->OnClose();
296 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000298 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299 ASSERT(channel_id_ == -1);
300 channel_id_ = channel_id;
301 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000302 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 ASSERT(channel_id == channel_id_);
304 channel_id_ = -1;
305 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307
308 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 private:
311 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000312 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313};
314
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315class WebRtcSessionTest : public testing::Test {
316 protected:
317 // TODO Investigate why ChannelManager crashes, if it's created
318 // after stun_server.
319 WebRtcSessionTest()
320 : media_engine_(new cricket::FakeMediaEngine()),
321 data_engine_(new cricket::FakeDataEngine()),
322 device_manager_(new cricket::FakeDeviceManager()),
323 channel_manager_(new cricket::ChannelManager(
324 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000325 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 tdesc_factory_(new cricket::TransportDescriptionFactory()),
327 desc_factory_(new cricket::MediaSessionDescriptionFactory(
328 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000329 pss_(new rtc::PhysicalSocketServer),
330 vss_(new rtc::VirtualSocketServer(pss_.get())),
331 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000334 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000335 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
336 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000337 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700338 mediastream_signaling_(channel_manager_.get()),
339 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
pthatcherfa301802015-08-11 04:12:56 -0700340 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
341
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000342 cricket::ServerAddresses stun_servers;
343 stun_servers.insert(stun_socket_addr_);
344 allocator_.reset(new cricket::BasicPortAllocator(
345 &network_manager_,
346 stun_servers,
347 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000348 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
pthatcherfa301802015-08-11 04:12:56 -0700349 cricket::PORTALLOCATOR_DISABLE_RELAY |
350 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 EXPECT_TRUE(channel_manager_->Init());
352 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000353 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
355
356 void AddInterface(const SocketAddress& addr) {
357 network_manager_.AddInterface(addr);
358 }
359
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000360 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200361 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200362 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 ASSERT_TRUE(session_.get() == NULL);
364 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 channel_manager_.get(), rtc::Thread::Current(),
366 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 &observer_,
368 &mediastream_signaling_));
369
370 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
371 observer_.ice_connection_state_);
372 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
373 observer_.ice_gathering_state_);
374
Henrik Boström5e56c592015-08-11 10:33:13 +0200375 EXPECT_TRUE(session_->Initialize(
376 options_, constraints_.get(), dtls_identity_store.Pass(),
377 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700378 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 }
380
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000381 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200382 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200383 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 }
385
386 void InitWithIceTransport(
387 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200388 PeerConnectionInterface::RTCConfiguration configuration;
389 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200390 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000391 }
392
393 void InitWithBundlePolicy(
394 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200395 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200396 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200397 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700398 }
399
400 void InitWithRtcpMuxPolicy(
401 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
402 PeerConnectionInterface::RTCConfiguration configuration;
403 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200404 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000405 }
406
407 void InitWithDtls(bool identity_request_should_fail = false) {
Henrik Boström5e56c592015-08-11 10:33:13 +0200408 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
409 new FakeDtlsIdentityStore());
410 dtls_identity_store->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200411 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200412 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 }
414
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 void InitWithDtmfCodec() {
416 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000417 const cricket::AudioCodec kTelephoneEventCodec(
418 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 std::vector<cricket::AudioCodec> codecs;
420 codecs.push_back(kTelephoneEventCodec);
421 media_engine_->SetAudioCodecs(codecs);
422 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000423 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 }
425
426 // Creates a local offer and applies it. Starts ice.
427 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
428 // to decide which streams to create.
429 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000430 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 SetLocalDescriptionWithoutError(offer);
432 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
433 observer_.ice_gathering_state_,
434 kIceCandidatesTimeout);
435 }
436
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000437 SessionDescriptionInterface* CreateOffer() {
438 PeerConnectionInterface::RTCOfferAnswerOptions options;
439 options.offer_to_receive_audio =
440 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
441
442 return CreateOffer(options);
443 }
444
wu@webrtc.org91053e72013-08-10 07:18:04 +0000445 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000446 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000447 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000448 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000449 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000450 EXPECT_TRUE_WAIT(
451 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000452 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000453 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000454 }
455
456 SessionDescriptionInterface* CreateAnswer(
457 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000458 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000459 = new WebRtcSessionCreateSDPObserverForTest();
460 session_->CreateAnswer(observer, constraints);
461 EXPECT_TRUE_WAIT(
462 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000463 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000464 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000465 }
466
wu@webrtc.org364f2042013-11-20 21:49:41 +0000467 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 return (session_->voice_channel() != NULL &&
469 session_->video_channel() != NULL);
470 }
471
wu@webrtc.org364f2042013-11-20 21:49:41 +0000472 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
474 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
475 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
476 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
477 }
478
479 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
480 ASSERT_TRUE(session_.get() != NULL);
481 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
482 ASSERT_TRUE(content != NULL);
483 const cricket::AudioContentDescription* audio_content =
484 static_cast<const cricket::AudioContentDescription*>(
485 content->description);
486 ASSERT_TRUE(audio_content != NULL);
487 ASSERT_EQ(1U, audio_content->cryptos().size());
488 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
489 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
490 audio_content->cryptos()[0].cipher_suite);
491 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
492 audio_content->protocol());
493
494 content = cricket::GetFirstVideoContent(sdp);
495 ASSERT_TRUE(content != NULL);
496 const cricket::VideoContentDescription* video_content =
497 static_cast<const cricket::VideoContentDescription*>(
498 content->description);
499 ASSERT_TRUE(video_content != NULL);
500 ASSERT_EQ(1U, video_content->cryptos().size());
501 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
502 video_content->cryptos()[0].cipher_suite);
503 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
504 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
505 video_content->protocol());
506 }
507
508 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
509 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
510 ASSERT_TRUE(content != NULL);
511 const cricket::AudioContentDescription* audio_content =
512 static_cast<const cricket::AudioContentDescription*>(
513 content->description);
514 ASSERT_TRUE(audio_content != NULL);
515 ASSERT_EQ(0U, audio_content->cryptos().size());
516
517 content = cricket::GetFirstVideoContent(sdp);
518 ASSERT_TRUE(content != NULL);
519 const cricket::VideoContentDescription* video_content =
520 static_cast<const cricket::VideoContentDescription*>(
521 content->description);
522 ASSERT_TRUE(video_content != NULL);
523 ASSERT_EQ(0U, video_content->cryptos().size());
524
525 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700526 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700528 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 video_content->protocol());
530 } else {
531 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
532 audio_content->protocol());
533 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
534 video_content->protocol());
535 }
536 }
537
538 // Set the internal fake description factories to do DTLS-SRTP.
539 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000540 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200543 // Confirmed to work with KT_RSA and KT_ECDSA.
544 identity_.reset(rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000545 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
547 }
548
549 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
550 bool expected) {
551 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
552 ASSERT_TRUE(audio != NULL);
553 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 const TransportInfo* video = sdp->GetTransportInfoByName("video");
555 ASSERT_TRUE(video != NULL);
556 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 }
558
559 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000560 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000562 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000563 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000565 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000567 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
568 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000569 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // Answer should be NULL as no crypto params in offer.
571 ASSERT_TRUE(answer == NULL);
572 }
573
574 void VerifyAnswerFromCryptoOffer() {
575 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000576 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 options.bundle_enabled = true;
578 scoped_ptr<JsepSessionDescription> offer(
579 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
580 ASSERT_TRUE(offer.get() != NULL);
581 VerifyCryptoParams(offer->description());
582 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000583 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 ASSERT_TRUE(answer.get() != NULL);
585 VerifyCryptoParams(answer->description());
586 }
587
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000588 void SetAndVerifyNumUnsignalledRecvStreams(
589 int value_set, int value_expected) {
590 constraints_.reset(new FakeConstraints());
591 constraints_->AddOptional(
592 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
593 value_set);
594 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000595 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000596 mediastream_signaling_.SendAudioVideoStream1();
597 SessionDescriptionInterface* offer = CreateOffer();
598
599 SetLocalDescriptionWithoutError(offer);
600
601 video_channel_ = media_engine_->GetVideoChannel(0);
602
603 ASSERT_TRUE(video_channel_ != NULL);
604 cricket::VideoOptions video_options;
605 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
606 EXPECT_EQ(value_expected,
607 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
608 }
609
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
611 const cricket::SessionDescription* desc2,
612 bool expect_equal) {
613 if (desc1->contents().size() != desc2->contents().size()) {
614 EXPECT_FALSE(expect_equal);
615 return;
616 }
617
618 const cricket::ContentInfos& contents = desc1->contents();
619 cricket::ContentInfos::const_iterator it = contents.begin();
620
621 for (; it != contents.end(); ++it) {
622 const cricket::TransportDescription* transport_desc1 =
623 desc1->GetTransportDescriptionByName(it->name);
624 const cricket::TransportDescription* transport_desc2 =
625 desc2->GetTransportDescriptionByName(it->name);
626 if (!transport_desc1 || !transport_desc2) {
627 EXPECT_FALSE(expect_equal);
628 return;
629 }
630 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
631 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
632 EXPECT_FALSE(expect_equal);
633 return;
634 }
635 }
636 EXPECT_TRUE(expect_equal);
637 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000638
639 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
640 std::string *sdp) {
641 const cricket::SessionDescription* desc = current_desc->description();
642 EXPECT_TRUE(current_desc->ToString(sdp));
643
644 const cricket::ContentInfos& contents = desc->contents();
645 cricket::ContentInfos::const_iterator it = contents.begin();
646 // Replace ufrag and pwd lines with empty strings.
647 for (; it != contents.end(); ++it) {
648 const cricket::TransportDescription* transport_desc =
649 desc->GetTransportDescriptionByName(it->name);
650 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
651 + "\r\n";
652 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
653 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000654 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000655 "", 0,
656 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000657 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000658 "", 0,
659 sdp);
660 }
661 }
662
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000663 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
664 const std::string& modified_ice_ufrag,
665 const std::string& modified_ice_pwd,
666 std::string* sdp) {
667 const cricket::SessionDescription* desc = current_desc->description();
668 EXPECT_TRUE(current_desc->ToString(sdp));
669
670 const cricket::ContentInfos& contents = desc->contents();
671 cricket::ContentInfos::const_iterator it = contents.begin();
672 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
673 // |modified_ice_pwd| strings.
674 for (; it != contents.end(); ++it) {
675 const cricket::TransportDescription* transport_desc =
676 desc->GetTransportDescriptionByName(it->name);
677 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
678 + "\r\n";
679 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
680 + "\r\n";
681 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
682 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000683 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000684 mod_ufrag.c_str(), mod_ufrag.length(),
685 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000686 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000687 mod_pwd.c_str(), mod_pwd.length(),
688 sdp);
689 }
690 }
691
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 // Creates a remote offer and and applies it as a remote description,
693 // creates a local answer and applies is as a local description.
694 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
695 // to decide which local and remote streams to create.
696 void CreateAndSetRemoteOfferAndLocalAnswer() {
697 SessionDescriptionInterface* offer = CreateRemoteOffer();
698 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000699 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 SetLocalDescriptionWithoutError(answer);
701 }
702 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
703 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
704 }
705 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
706 BaseSession::State expected_state) {
707 SetLocalDescriptionWithoutError(desc);
708 EXPECT_EQ(expected_state, session_->state());
709 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000710 void SetLocalDescriptionExpectError(const std::string& action,
711 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 SessionDescriptionInterface* desc) {
713 std::string error;
714 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000715 std::string sdp_type = "local ";
716 sdp_type.append(action);
717 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 EXPECT_NE(std::string::npos, error.find(expected_error));
719 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
721 SessionDescriptionInterface* desc) {
722 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
723 expected_error, desc);
724 }
725 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
726 SessionDescriptionInterface* desc) {
727 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
728 expected_error, desc);
729 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
731 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
732 }
733 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
734 BaseSession::State expected_state) {
735 SetRemoteDescriptionWithoutError(desc);
736 EXPECT_EQ(expected_state, session_->state());
737 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000738 void SetRemoteDescriptionExpectError(const std::string& action,
739 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 SessionDescriptionInterface* desc) {
741 std::string error;
742 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 std::string sdp_type = "remote ";
744 sdp_type.append(action);
745 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 EXPECT_NE(std::string::npos, error.find(expected_error));
747 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 void SetRemoteDescriptionOfferExpectError(
749 const std::string& expected_error, SessionDescriptionInterface* desc) {
750 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
751 expected_error, desc);
752 }
753 void SetRemoteDescriptionPranswerExpectError(
754 const std::string& expected_error, SessionDescriptionInterface* desc) {
755 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
756 expected_error, desc);
757 }
758 void SetRemoteDescriptionAnswerExpectError(
759 const std::string& expected_error, SessionDescriptionInterface* desc) {
760 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
761 expected_error, desc);
762 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
765 SessionDescriptionInterface** nocrypto_answer) {
766 // Create a SDP without Crypto.
767 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000768 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 options.bundle_enabled = true;
770 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
771 ASSERT_TRUE(*offer != NULL);
772 VerifyCryptoParams((*offer)->description());
773
774 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
775 cricket::SEC_DISABLED);
776 EXPECT_TRUE(*nocrypto_answer != NULL);
777 }
778
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000779 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
780 SessionDescriptionInterface** nodtls_answer) {
781 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000782 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000783 options.bundle_enabled = true;
784
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000785 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000786 CreateRemoteOffer(options, cricket::SEC_ENABLED));
787
788 *nodtls_answer =
789 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
790 EXPECT_TRUE(*nodtls_answer != NULL);
791 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
792 VerifyCryptoParams((*nodtls_answer)->description());
793
794 SetFactoryDtlsSrtp();
795 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
796 ASSERT_TRUE(*offer != NULL);
797 VerifyFingerprintStatus((*offer)->description(), true);
798 VerifyCryptoParams((*offer)->description());
799 }
800
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 JsepSessionDescription* CreateRemoteOfferWithVersion(
802 cricket::MediaSessionOptions options,
803 cricket::SecurePolicy secure_policy,
804 const std::string& session_version,
805 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 const cricket::SessionDescription* cricket_desc = NULL;
808 if (current_desc) {
809 cricket_desc = current_desc->description();
810 session_id = current_desc->session_id();
811 }
812
813 desc_factory_->set_secure(secure_policy);
814 JsepSessionDescription* offer(
815 new JsepSessionDescription(JsepSessionDescription::kOffer));
816 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
817 session_id, session_version)) {
818 delete offer;
819 offer = NULL;
820 }
821 return offer;
822 }
823 JsepSessionDescription* CreateRemoteOffer(
824 cricket::MediaSessionOptions options) {
825 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
826 kSessionVersion, NULL);
827 }
828 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000829 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
830 return CreateRemoteOfferWithVersion(
831 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 }
833 JsepSessionDescription* CreateRemoteOffer(
834 cricket::MediaSessionOptions options,
835 const SessionDescriptionInterface* current_desc) {
836 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
837 kSessionVersion, current_desc);
838 }
839
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
841 const char* sctp_stream_name, int new_port,
842 cricket::MediaSessionOptions options) {
843 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000844 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
845 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000846 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
847 }
848
849 // Takes ownership of offer_basis (and deletes it).
850 JsepSessionDescription* ChangeSDPSctpPort(
851 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
852 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
853 // SessionDescription from the mutated string.
854 const char* default_port_str = "5000";
855 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000856 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000857 std::string offer_str;
858 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000859 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000860 new_port_str, strlen(new_port_str),
861 &offer_str);
862 JsepSessionDescription* offer = new JsepSessionDescription(
863 offer_basis->type());
864 delete offer_basis;
865 offer->Initialize(offer_str, NULL);
866 return offer;
867 }
868
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
870 // before this function to decide which streams to create.
871 JsepSessionDescription* CreateRemoteOffer() {
872 cricket::MediaSessionOptions options;
873 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
874 return CreateRemoteOffer(options, session_->remote_description());
875 }
876
877 JsepSessionDescription* CreateRemoteAnswer(
878 const SessionDescriptionInterface* offer,
879 cricket::MediaSessionOptions options,
880 cricket::SecurePolicy policy) {
881 desc_factory_->set_secure(policy);
882 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000883 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 JsepSessionDescription* answer(
885 new JsepSessionDescription(JsepSessionDescription::kAnswer));
886 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
887 options, NULL),
888 session_id, kSessionVersion)) {
889 delete answer;
890 answer = NULL;
891 }
892 return answer;
893 }
894
895 JsepSessionDescription* CreateRemoteAnswer(
896 const SessionDescriptionInterface* offer,
897 cricket::MediaSessionOptions options) {
898 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
899 }
900
901 // Creates an answer session description with streams based on
902 // |mediastream_signaling_|. Call
903 // mediastream_signaling_.UseOptionsWithStreamX() before this function
904 // to decide which streams to create.
905 JsepSessionDescription* CreateRemoteAnswer(
906 const SessionDescriptionInterface* offer) {
907 cricket::MediaSessionOptions options;
908 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
909 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
910 }
911
912 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000913 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000914 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000916
917 PeerConnectionInterface::RTCOfferAnswerOptions options;
918 options.use_rtp_mux = bundle;
919
920 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
922 // and answer.
923 SetLocalDescriptionWithoutError(offer);
924
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000926 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 std::string sdp;
928 EXPECT_TRUE(answer->ToString(&sdp));
929
930 size_t expected_candidate_num = 2;
931 if (!rtcp_mux) {
932 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
933 // for rtp and rtcp.
934 expected_candidate_num = 4;
935 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 const std::string kRtcpMux = "a=rtcp-mux";
937 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000938 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 kXRtcpMux.c_str(), kXRtcpMux.length(),
940 &sdp);
941 }
942
943 SessionDescriptionInterface* new_answer = CreateSessionDescription(
944 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945
946 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000947 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
949 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
950 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
951 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
952 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
953 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
954 if (bundle) {
955 EXPECT_TRUE(c0.IsEquivalent(c1));
956 } else {
957 EXPECT_FALSE(c0.IsEquivalent(c1));
958 }
959 }
960 }
961 // Tests that we can only send DTMF when the dtmf codec is supported.
962 void TestCanInsertDtmf(bool can) {
963 if (can) {
964 InitWithDtmfCodec();
965 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000966 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 }
968 mediastream_signaling_.SendAudioVideoStream1();
969 CreateAndSetRemoteOfferAndLocalAnswer();
970 EXPECT_FALSE(session_->CanInsertDtmf(""));
971 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
972 }
973
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000974 // Helper class to configure loopback network and verify Best
975 // Connection using right IP protocol for TestLoopbackCall
976 // method. LoopbackNetworkManager applies firewall rules to block
977 // all ping traffic once ICE completed, and remove them to observe
978 // ICE reconnected again. This LoopbackNetworkConfiguration struct
979 // verifies the best connection is using the right IP protocol after
980 // initial ICE convergences.
981
982 class LoopbackNetworkConfiguration {
983 public:
984 LoopbackNetworkConfiguration()
985 : test_ipv6_network_(false),
986 test_extra_ipv4_network_(false),
987 best_connection_after_initial_ice_converged_(1, 0) {}
988
989 // Used to track the expected best connection count in each IP protocol.
990 struct ExpectedBestConnection {
991 ExpectedBestConnection(int ipv4_count, int ipv6_count)
992 : ipv4_count_(ipv4_count),
993 ipv6_count_(ipv6_count) {}
994
995 int ipv4_count_;
996 int ipv6_count_;
997 };
998
999 bool test_ipv6_network_;
1000 bool test_extra_ipv4_network_;
1001 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1002
1003 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001004 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001005 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1006 }
1007
1008 private:
jbauchac8869e2015-07-03 01:36:14 -07001009 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001010 const ExpectedBestConnection& expected) const {
1011 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001012 metrics_observer->GetCounter(webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001013 expected.ipv4_count_);
1014 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001015 metrics_observer->GetCounter(webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001016 expected.ipv6_count_);
1017 }
1018 };
1019
1020 class LoopbackNetworkManager {
1021 public:
1022 LoopbackNetworkManager(WebRtcSessionTest* session,
1023 const LoopbackNetworkConfiguration& config)
1024 : config_(config) {
1025 session->AddInterface(
1026 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1027 if (config_.test_extra_ipv4_network_) {
1028 session->AddInterface(
1029 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1030 }
1031 if (config_.test_ipv6_network_) {
1032 session->AddInterface(
1033 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1034 }
1035 }
1036
1037 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1038 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1039 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1040 if (config_.test_extra_ipv4_network_) {
1041 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1042 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1043 }
1044 if (config_.test_ipv6_network_) {
1045 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1046 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1047 }
1048 }
1049
1050 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1051
1052 private:
1053 LoopbackNetworkConfiguration config_;
1054 };
1055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 // The method sets up a call from the session to itself, in a loopback
1057 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001058 // disconnection, and then a permanent disconnection.
1059 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1061 // While running the call, this method also checks if the session goes through
1062 // the correct sequence of ICE states when a connection is established,
1063 // broken, and re-established.
1064 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001065 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1066 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001068
1069 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1070 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001071 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001073 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074
1075 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1076 observer_.ice_gathering_state_);
1077 SetLocalDescriptionWithoutError(offer);
1078 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1079 observer_.ice_connection_state_);
1080 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1081 observer_.ice_gathering_state_,
1082 kIceCandidatesTimeout);
1083 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1084 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1085 observer_.ice_gathering_state_,
1086 kIceCandidatesTimeout);
1087
1088 std::string sdp;
1089 offer->ToString(&sdp);
1090 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001091 webrtc::CreateSessionDescription(
1092 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 ASSERT_TRUE(desc != NULL);
1094 SetRemoteDescriptionWithoutError(desc);
1095
1096 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1097 observer_.ice_connection_state_,
1098 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001099
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001100 // The ice connection state is "Connected" too briefly to catch in a test.
1101 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 observer_.ice_connection_state_,
1103 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001105 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 // Adding firewall rule to block ping requests, which should cause
1107 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001108
1109 loopback_network_manager.ApplyFirewallRules(fss_.get());
1110
1111 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1113 observer_.ice_connection_state_,
1114 kIceCandidatesTimeout);
1115
jbauchac8869e2015-07-03 01:36:14 -07001116 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001119 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 // Session is automatically calling OnSignalingReady after creation of
1121 // new portallocator session which will allocate new set of candidates.
1122
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001123 LOG(LS_INFO) << "Firewall Rules cleared";
1124
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001125 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 observer_.ice_connection_state_,
1127 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001128
1129 // Now we block ping requests and wait until the ICE connection transitions
1130 // to the Failed state. This will take at least 30 seconds because it must
1131 // wait for the Port to timeout.
1132 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001133
1134 loopback_network_manager.ApplyFirewallRules(fss_.get());
1135 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001136 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001137 observer_.ice_connection_state_,
1138 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 }
1140
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001141 void TestLoopbackCall() {
1142 LoopbackNetworkConfiguration config;
1143 TestLoopbackCall(config);
1144 }
1145
pthatcherfa301802015-08-11 04:12:56 -07001146 void VerifyTransportType(const std::string& content_name,
1147 cricket::TransportProtocol protocol) {
1148 const cricket::Transport* transport = session_->GetTransport(content_name);
1149 ASSERT_TRUE(transport != NULL);
1150 EXPECT_EQ(protocol, transport->protocol());
1151 }
1152
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1154 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001155 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1156 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1157
1158 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1160 codecs.push_back(kCNCodec1);
1161 codecs.push_back(kCNCodec2);
1162 media_engine_->SetAudioCodecs(codecs);
1163 desc_factory_->set_audio_codecs(codecs);
1164 }
1165
1166 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1167 const cricket::ContentDescription* description = content->description;
1168 ASSERT(description != NULL);
1169 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001170 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171 ASSERT(audio_content_desc != NULL);
1172 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1173 if (audio_content_desc->codecs()[i].name == "CN")
1174 return false;
1175 }
1176 return true;
1177 }
1178
1179 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001180 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 dci.reliable = false;
1182 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001183 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184 SetLocalDescriptionWithoutError(offer);
1185 }
1186
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 void VerifyMultipleAsyncCreateDescription(
1188 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001189 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001190 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001191 if (type == CreateSessionDescriptionRequest::kAnswer) {
1192 cricket::MediaSessionOptions options;
1193 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001194 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001195 ASSERT_TRUE(offer.get() != NULL);
1196 SetRemoteDescriptionWithoutError(offer.release());
1197 }
1198
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001199 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001200 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001201 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001202 observers[kNumber];
1203 for (int i = 0; i < kNumber; ++i) {
1204 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1205 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001206 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001207 } else {
1208 session_->CreateAnswer(observers[i], NULL);
1209 }
1210 }
1211
1212 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1213 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1214 WebRtcSessionCreateSDPObserverForTest::kFailed;
1215
1216 for (int i = 0; i < kNumber; ++i) {
1217 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1218 if (success) {
1219 EXPECT_TRUE(observers[i]->description() != NULL);
1220 } else {
1221 EXPECT_TRUE(observers[i]->description() == NULL);
1222 }
1223 }
1224 }
1225
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001226 void ConfigureAllocatorWithTurn() {
1227 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1228 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1229 relay_server.credentials = credentials;
1230 relay_server.ports.push_back(cricket::ProtocolAddress(
1231 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1232 allocator_->AddRelay(relay_server);
1233 allocator_->set_step_delay(cricket::kMinimumStepDelay);
pthatcherfa301802015-08-11 04:12:56 -07001234 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1235 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001236 }
1237
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 cricket::FakeMediaEngine* media_engine_;
1239 cricket::FakeDataEngine* data_engine_;
1240 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001241 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1242 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1243 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1244 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1245 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1246 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1247 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1248 rtc::SocketServerScope ss_scope_;
1249 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001250 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001251 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::FakeNetworkManager network_manager_;
1253 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001254 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001255 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001257 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 MockIceObserver observer_;
1259 cricket::FakeVideoMediaChannel* video_channel_;
1260 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001261 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262};
1263
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1265 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001266 // SDES is disabled when DTLS is on.
1267 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268}
1269
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001270TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001271 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001272 // SDES is required if DTLS is off.
1273 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001274}
1275
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1277 TestSessionCandidatesWithBundleRtcpMux(false, false);
1278}
1279
1280// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1281// with rtcp-mux and/or bundle.
1282TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1283 TestSessionCandidatesWithBundleRtcpMux(false, true);
1284}
1285
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1287 TestSessionCandidatesWithBundleRtcpMux(true, true);
1288}
1289
1290TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001291 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1292 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001293 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 mediastream_signaling_.SendAudioVideoStream1();
1295 InitiateCall();
1296 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1297 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1298 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1299}
1300
1301TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001302 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1303 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001304 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001305 rtc::FP_UDP,
1306 rtc::FD_ANY,
1307 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001308 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 mediastream_signaling_.SendAudioVideoStream1();
1310 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001311 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1313 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1314 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1315}
1316
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001317// Test session delivers no candidates gathered when constraint set to "none".
1318TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1319 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001320 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001321 mediastream_signaling_.SendAudioVideoStream1();
1322 InitiateCall();
1323 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1324 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1325 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1326}
1327
1328// Test session delivers only relay candidates gathered when constaint set to
1329// "relay".
1330TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1331 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1332 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001333 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001334 mediastream_signaling_.SendAudioVideoStream1();
1335 InitiateCall();
1336 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1337 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1338 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1339 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1340 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1341 observer_.mline_0_candidates_[i].type());
1342 }
1343 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1344 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1345 observer_.mline_1_candidates_[i].type());
1346 }
1347}
1348
1349// Test session delivers all candidates gathered when constaint set to "all".
1350TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1351 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001352 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001353 mediastream_signaling_.SendAudioVideoStream1();
1354 InitiateCall();
1355 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1356 // Host + STUN. By default allocator is disabled to gather relay candidates.
1357 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1358 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1359}
1360
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001361TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001362 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001363 SessionDescriptionInterface* offer = NULL;
1364 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1365 std::string unknown_action;
1366 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1367 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1368}
1369
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001370// Test creating offers and receive answers and make sure the
1371// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001372TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001373 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001375 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 const std::string session_id_orig = offer->session_id();
1377 const std::string session_version_orig = offer->session_version();
1378 SetLocalDescriptionWithoutError(offer);
1379
1380 mediastream_signaling_.SendAudioVideoStream2();
1381 SessionDescriptionInterface* answer =
1382 CreateRemoteAnswer(session_->local_description());
1383 SetRemoteDescriptionWithoutError(answer);
1384
1385 video_channel_ = media_engine_->GetVideoChannel(0);
1386 voice_channel_ = media_engine_->GetVoiceChannel(0);
1387
1388 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1389 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1390
1391 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1392 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1393
1394 ASSERT_EQ(1u, video_channel_->send_streams().size());
1395 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1396 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1397 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1398
1399 // Create new offer without send streams.
1400 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001401 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402
1403 // Verify the session id is the same and the session version is
1404 // increased.
1405 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001406 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1407 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408
1409 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001410 EXPECT_EQ(0u, video_channel_->send_streams().size());
1411 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412
1413 mediastream_signaling_.SendAudioVideoStream2();
1414 answer = CreateRemoteAnswer(session_->local_description());
1415 SetRemoteDescriptionWithoutError(answer);
1416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 // Make sure the receive streams have not changed.
1418 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1419 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1420 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1421 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1422}
1423
1424// Test receiving offers and creating answers and make sure the
1425// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001426TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001427 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001429 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001430 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 SetRemoteDescriptionWithoutError(offer);
1432
1433 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001434 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001435 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 SetLocalDescriptionWithoutError(answer);
1437
1438 const std::string session_id_orig = answer->session_id();
1439 const std::string session_version_orig = answer->session_version();
1440
1441 video_channel_ = media_engine_->GetVideoChannel(0);
1442 voice_channel_ = media_engine_->GetVoiceChannel(0);
1443
1444 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1445 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1446
1447 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1448 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1449
1450 ASSERT_EQ(1u, video_channel_->send_streams().size());
1451 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1452 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1453 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1454
1455 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001456 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 SetRemoteDescriptionWithoutError(offer);
1458
1459 // Answer by turning off all send streams.
1460 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001461 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462
1463 // Verify the session id is the same and the session version is
1464 // increased.
1465 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001466 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1467 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 SetLocalDescriptionWithoutError(answer);
1469
1470 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1471 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1472 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1473 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1474 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1475 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1476
1477 // Make sure we have no send streams.
1478 EXPECT_EQ(0u, video_channel_->send_streams().size());
1479 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1480}
1481
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001482TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001483 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001484 media_engine_->set_fail_create_channel(true);
1485
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001486 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001487 ASSERT_TRUE(offer != NULL);
1488 // SetRemoteDescription and SetLocalDescription will take the ownership of
1489 // the offer.
1490 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001491 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001492 ASSERT_TRUE(offer != NULL);
1493 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1494}
1495
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001496//
1497// Tests for creating/setting SDP under different SDES/DTLS polices:
1498//
1499// --DTLS off and SDES on
1500// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1501// set local/remote offer/answer with crypto --> success
1502// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1503// failure
1504// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1505// failure
1506// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1507// failure
1508//
1509// --DTLS on and SDES off
1510// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1511// set local/remote offer/answer with DTLS fingerprint --> success
1512// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1513// fingerprint --> failure
1514// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1515// --> failure
1516// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1517// --> failure
1518//
1519// --Encryption disabled: DTLS off and SDES off
1520// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1521// answer without SDES or DTLS --> success
1522// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1523// answer without SDES or DTLS --> success
1524//
1525
1526// Test that we return a failure when applying a remote/local offer that doesn't
1527// have cryptos enabled when DTLS is off.
1528TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001529 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001531 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 JsepSessionDescription* offer = CreateRemoteOffer(
1533 options, cricket::SEC_DISABLED);
1534 ASSERT_TRUE(offer != NULL);
1535 VerifyNoCryptoParams(offer->description(), false);
1536 // SetRemoteDescription and SetLocalDescription will take the ownership of
1537 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001538 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1540 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542}
1543
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001544// Test that we return a failure when applying a local answer that doesn't have
1545// cryptos enabled when DTLS is off.
1546TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001547 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 SessionDescriptionInterface* offer = NULL;
1549 SessionDescriptionInterface* answer = NULL;
1550 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1551 // SetRemoteDescription and SetLocalDescription will take the ownership of
1552 // the offer.
1553 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001554 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555}
1556
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001557// Test we will return fail when apply an remote answer that doesn't have
1558// crypto enabled when DTLS is off.
1559TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001560 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 SessionDescriptionInterface* offer = NULL;
1562 SessionDescriptionInterface* answer = NULL;
1563 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1564 // SetRemoteDescription and SetLocalDescription will take the ownership of
1565 // the offer.
1566 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001567 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568}
1569
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001570// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1571// and that we return an answer with a DTLS fingerprint.
1572TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001573 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 InitWithDtls();
1576 SetFactoryDtlsSrtp();
1577 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001578 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001579 JsepSessionDescription* offer =
1580 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 ASSERT_TRUE(offer != NULL);
1582 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001583 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584
1585 // SetRemoteDescription will take the ownership of the offer.
1586 SetRemoteDescriptionWithoutError(offer);
1587
1588 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001589 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 ASSERT_TRUE(answer != NULL);
1591 VerifyFingerprintStatus(answer->description(), true);
1592 // Check that we don't have an a=crypto line in the answer.
1593 VerifyNoCryptoParams(answer->description(), true);
1594
1595 // Now set the local description, which should work, even without a=crypto.
1596 SetLocalDescriptionWithoutError(answer);
1597}
1598
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1600// and then we accept a remote answer with a DTLS fingerprint successfully.
1601TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001602 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 mediastream_signaling_.SendAudioVideoStream1();
1604 InitWithDtls();
1605 SetFactoryDtlsSrtp();
1606
1607 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001608 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001609 ASSERT_TRUE(offer != NULL);
1610 VerifyFingerprintStatus(offer->description(), true);
1611 // Check that we don't have an a=crypto line in the offer.
1612 VerifyNoCryptoParams(offer->description(), true);
1613
1614 // Now set the local description, which should work, even without a=crypto.
1615 SetLocalDescriptionWithoutError(offer);
1616
1617 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001618 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619 JsepSessionDescription* answer =
1620 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1621 ASSERT_TRUE(answer != NULL);
1622 VerifyFingerprintStatus(answer->description(), true);
1623 VerifyNoCryptoParams(answer->description(), true);
1624
1625 // SetRemoteDescription will take the ownership of the answer.
1626 SetRemoteDescriptionWithoutError(answer);
1627}
1628
1629// Test that if we support DTLS and the other side didn't offer a fingerprint,
1630// we will fail to set the remote description.
1631TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001632 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 InitWithDtls();
1634 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001635 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001636 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 JsepSessionDescription* offer = CreateRemoteOffer(
1638 options, cricket::SEC_REQUIRED);
1639 ASSERT_TRUE(offer != NULL);
1640 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 // SetRemoteDescription will take the ownership of the offer.
1644 SetRemoteDescriptionOfferExpectError(
1645 kSdpWithoutDtlsFingerprint, offer);
1646
1647 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1648 // SetLocalDescription will take the ownership of the offer.
1649 SetLocalDescriptionOfferExpectError(
1650 kSdpWithoutDtlsFingerprint, offer);
1651}
1652
1653// Test that we return a failure when applying a local answer that doesn't have
1654// a DTLS fingerprint when DTLS is required.
1655TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001656 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657 InitWithDtls();
1658 SessionDescriptionInterface* offer = NULL;
1659 SessionDescriptionInterface* answer = NULL;
1660 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1661
1662 // SetRemoteDescription and SetLocalDescription will take the ownership of
1663 // the offer and answer.
1664 SetRemoteDescriptionWithoutError(offer);
1665 SetLocalDescriptionAnswerExpectError(
1666 kSdpWithoutDtlsFingerprint, answer);
1667}
1668
1669// Test that we return a failure when applying a remote answer that doesn't have
1670// a DTLS fingerprint when DTLS is required.
1671TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001672 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001673 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1674 // result of using the "UDP/TLS/RTP/SAVPF" profile.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001675 InitWithDtls();
deadbeeff3938292015-07-15 12:20:53 -07001676 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001677 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001678 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001679 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001680 JsepSessionDescription* answer =
1681 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1682
1683 // SetRemoteDescription and SetLocalDescription will take the ownership of
1684 // the offer and answer.
1685 SetLocalDescriptionWithoutError(offer);
1686 SetRemoteDescriptionAnswerExpectError(
1687 kSdpWithoutDtlsFingerprint, answer);
1688}
1689
1690// Test that we create a local offer without SDES or DTLS and accept a remote
1691// answer without SDES or DTLS when encryption is disabled.
1692TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1693 mediastream_signaling_.SendAudioVideoStream1();
1694 options_.disable_encryption = true;
1695 InitWithDtls();
1696
1697 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001698 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001699 ASSERT_TRUE(offer != NULL);
1700 VerifyFingerprintStatus(offer->description(), false);
1701 // Check that we don't have an a=crypto line in the offer.
1702 VerifyNoCryptoParams(offer->description(), false);
1703
1704 // Now set the local description, which should work, even without a=crypto.
1705 SetLocalDescriptionWithoutError(offer);
1706
1707 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001708 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 JsepSessionDescription* answer =
1710 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1711 ASSERT_TRUE(answer != NULL);
1712 VerifyFingerprintStatus(answer->description(), false);
1713 VerifyNoCryptoParams(answer->description(), false);
1714
1715 // SetRemoteDescription will take the ownership of the answer.
1716 SetRemoteDescriptionWithoutError(answer);
1717}
1718
1719// Test that we create a local answer without SDES or DTLS and accept a remote
1720// offer without SDES or DTLS when encryption is disabled.
1721TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1722 options_.disable_encryption = true;
1723 InitWithDtls();
1724
1725 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001726 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 JsepSessionDescription* offer =
1728 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1729 ASSERT_TRUE(offer != NULL);
1730 VerifyFingerprintStatus(offer->description(), false);
1731 VerifyNoCryptoParams(offer->description(), false);
1732
1733 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 SetRemoteDescriptionWithoutError(offer);
1735
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001736 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001737 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 ASSERT_TRUE(answer != NULL);
1739 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740 // Check that we don't have an a=crypto line in the answer.
1741 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 SetLocalDescriptionWithoutError(answer);
1745}
1746
1747TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001748 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 mediastream_signaling_.SendNothing();
1750 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001751 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 SetLocalDescriptionWithoutError(offer);
1753
1754 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001755 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 SetLocalDescriptionWithoutError(offer2);
1757}
1758
1759TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001760 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 mediastream_signaling_.SendNothing();
1762 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001763 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 SetRemoteDescriptionWithoutError(offer);
1765
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001766 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 SetRemoteDescriptionWithoutError(offer2);
1768}
1769
1770TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001771 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001773 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001775 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001776 SetRemoteDescriptionOfferExpectError(
1777 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778}
1779
1780TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001783 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001785 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001786 SetLocalDescriptionOfferExpectError(
1787 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788}
1789
1790TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001791 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 mediastream_signaling_.SendNothing();
1793 SessionDescriptionInterface* offer = CreateRemoteOffer();
1794 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1795
1796 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001797 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1799 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1800
1801 mediastream_signaling_.SendAudioVideoStream1();
1802 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001803 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1805
1806 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1807
1808 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001809 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1811}
1812
1813TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001814 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001816 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1818
1819 JsepSessionDescription* pranswer =
1820 CreateRemoteAnswer(session_->local_description());
1821 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1822
1823 SetRemoteDescriptionExpectState(pranswer,
1824 BaseSession::STATE_RECEIVEDPRACCEPT);
1825
1826 mediastream_signaling_.SendAudioVideoStream1();
1827 JsepSessionDescription* pranswer2 =
1828 CreateRemoteAnswer(session_->local_description());
1829 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1830
1831 SetRemoteDescriptionExpectState(pranswer2,
1832 BaseSession::STATE_RECEIVEDPRACCEPT);
1833
1834 mediastream_signaling_.SendAudioVideoStream2();
1835 SessionDescriptionInterface* answer =
1836 CreateRemoteAnswer(session_->local_description());
1837 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1838}
1839
1840TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001841 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001843 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1844
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 SessionDescriptionInterface* answer =
1846 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001847 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1848 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849}
1850
1851TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001852 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001854 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1855
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 SessionDescriptionInterface* answer =
1857 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001858 SetRemoteDescriptionAnswerExpectError(
1859 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860}
1861
1862TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001863 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 mediastream_signaling_.SendAudioVideoStream1();
1865
1866 cricket::Candidate candidate;
1867 candidate.set_component(1);
1868 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1869
1870 // Fail since we have not set a offer description.
1871 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1872
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001873 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 SetLocalDescriptionWithoutError(offer);
1875 // Candidate should be allowed to add before remote description.
1876 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1877 candidate.set_component(2);
1878 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1879 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1880
1881 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1882 session_->local_description());
1883 SetRemoteDescriptionWithoutError(answer);
1884
1885 // Verifying the candidates are copied properly from internal vector.
1886 const SessionDescriptionInterface* remote_desc =
1887 session_->remote_description();
1888 ASSERT_TRUE(remote_desc != NULL);
1889 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1890 const IceCandidateCollection* candidates =
1891 remote_desc->candidates(kMediaContentIndex0);
1892 ASSERT_EQ(2u, candidates->count());
1893 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1894 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1895 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1896 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1897
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001898 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1899 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 candidate.set_component(2);
1901 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1902 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001903 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904
1905 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1906 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1907}
1908
1909// Test that a remote candidate is added to the remote session description and
1910// that it is retained if the remote session description is changed.
1911TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001912 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 cricket::Candidate candidate1;
1914 candidate1.set_component(1);
1915 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1916 candidate1);
1917 mediastream_signaling_.SendAudioVideoStream1();
1918 CreateAndSetRemoteOfferAndLocalAnswer();
1919
1920 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1921 const SessionDescriptionInterface* remote_desc =
1922 session_->remote_description();
1923 ASSERT_TRUE(remote_desc != NULL);
1924 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1925 const IceCandidateCollection* candidates =
1926 remote_desc->candidates(kMediaContentIndex0);
1927 ASSERT_EQ(1u, candidates->count());
1928 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1929
1930 // Update the RemoteSessionDescription with a new session description and
1931 // a candidate and check that the new remote session description contains both
1932 // candidates.
1933 SessionDescriptionInterface* offer = CreateRemoteOffer();
1934 cricket::Candidate candidate2;
1935 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1936 candidate2);
1937 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1938 SetRemoteDescriptionWithoutError(offer);
1939
1940 remote_desc = session_->remote_description();
1941 ASSERT_TRUE(remote_desc != NULL);
1942 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1943 candidates = remote_desc->candidates(kMediaContentIndex0);
1944 ASSERT_EQ(2u, candidates->count());
1945 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1946 // Username and password have be updated with the TransportInfo of the
1947 // SessionDescription, won't be equal to the original one.
1948 candidate2.set_username(candidates->at(0)->candidate().username());
1949 candidate2.set_password(candidates->at(0)->candidate().password());
1950 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1951 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1952 // No need to verify the username and password.
1953 candidate1.set_username(candidates->at(1)->candidate().username());
1954 candidate1.set_password(candidates->at(1)->candidate().password());
1955 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1956
1957 // Test that the candidate is ignored if we can add the same candidate again.
1958 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1959}
1960
1961// Test that local candidates are added to the local session description and
1962// that they are retained if the local session description is changed.
1963TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001964 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001965 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 mediastream_signaling_.SendAudioVideoStream1();
1967 CreateAndSetRemoteOfferAndLocalAnswer();
1968
1969 const SessionDescriptionInterface* local_desc = session_->local_description();
1970 const IceCandidateCollection* candidates =
1971 local_desc->candidates(kMediaContentIndex0);
1972 ASSERT_TRUE(candidates != NULL);
1973 EXPECT_EQ(0u, candidates->count());
1974
1975 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1976
1977 local_desc = session_->local_description();
1978 candidates = local_desc->candidates(kMediaContentIndex0);
1979 ASSERT_TRUE(candidates != NULL);
1980 EXPECT_LT(0u, candidates->count());
1981 candidates = local_desc->candidates(1);
1982 ASSERT_TRUE(candidates != NULL);
1983 EXPECT_LT(0u, candidates->count());
1984
1985 // Update the session descriptions.
1986 mediastream_signaling_.SendAudioVideoStream1();
1987 CreateAndSetRemoteOfferAndLocalAnswer();
1988
1989 local_desc = session_->local_description();
1990 candidates = local_desc->candidates(kMediaContentIndex0);
1991 ASSERT_TRUE(candidates != NULL);
1992 EXPECT_LT(0u, candidates->count());
1993 candidates = local_desc->candidates(1);
1994 ASSERT_TRUE(candidates != NULL);
1995 EXPECT_LT(0u, candidates->count());
1996}
1997
1998// Test that we can set a remote session description with remote candidates.
1999TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002000 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001
2002 cricket::Candidate candidate1;
2003 candidate1.set_component(1);
2004 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2005 candidate1);
2006 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002007 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008
2009 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2010 SetRemoteDescriptionWithoutError(offer);
2011
2012 const SessionDescriptionInterface* remote_desc =
2013 session_->remote_description();
2014 ASSERT_TRUE(remote_desc != NULL);
2015 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2016 const IceCandidateCollection* candidates =
2017 remote_desc->candidates(kMediaContentIndex0);
2018 ASSERT_EQ(1u, candidates->count());
2019 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2020
wu@webrtc.org91053e72013-08-10 07:18:04 +00002021 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 SetLocalDescriptionWithoutError(answer);
2023}
2024
2025// Test that offers and answers contains ice candidates when Ice candidates have
2026// been gathered.
2027TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002028 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002029 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 mediastream_signaling_.SendAudioVideoStream1();
2031 // Ice is started but candidates are not provided until SetLocalDescription
2032 // is called.
2033 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2034 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2035 CreateAndSetRemoteOfferAndLocalAnswer();
2036 // Wait until at least one local candidate has been collected.
2037 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2038 kIceCandidatesTimeout);
2039 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2040 kIceCandidatesTimeout);
2041
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002042 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2045 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2046 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2047 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2048
2049 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2050 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002051 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2053 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2054 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2055 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2056 SetLocalDescriptionWithoutError(answer);
2057}
2058
2059// Verifies TransportProxy and media channels are created with content names
2060// present in the SessionDescription.
2061TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002062 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002064 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065
2066 // CreateOffer creates session description with the content names "audio" and
2067 // "video". Goal is to modify these content names and verify transport channel
2068 // proxy in the BaseSession, as proxies are created with the content names
2069 // present in SDP.
2070 std::string sdp;
2071 EXPECT_TRUE(offer->ToString(&sdp));
2072 const std::string kAudioMid = "a=mid:audio";
2073 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2074 const std::string kVideoMid = "a=mid:video";
2075 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2076
2077 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002078 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 kAudioMidReplaceStr.c_str(),
2080 kAudioMidReplaceStr.length(),
2081 &sdp);
2082 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002083 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 kVideoMidReplaceStr.c_str(),
2085 kVideoMidReplaceStr.length(),
2086 &sdp);
2087
2088 SessionDescriptionInterface* modified_offer =
2089 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2090
2091 SetRemoteDescriptionWithoutError(modified_offer);
2092
2093 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002094 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 SetLocalDescriptionWithoutError(answer);
2096
2097 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2098 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2099 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2100 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2101}
2102
2103// Test that an offer contains the correct media content descriptions based on
2104// the send streams when no constraints have been set.
2105TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002106 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002107 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2108
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 ASSERT_TRUE(offer != NULL);
2110 const cricket::ContentInfo* content =
2111 cricket::GetFirstAudioContent(offer->description());
2112 EXPECT_TRUE(content != NULL);
2113 content = cricket::GetFirstVideoContent(offer->description());
2114 EXPECT_TRUE(content == NULL);
2115}
2116
2117// Test that an offer contains the correct media content descriptions based on
2118// the send streams when no constraints have been set.
2119TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002120 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 // Test Audio only offer.
2122 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002123 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 const cricket::ContentInfo* content =
2126 cricket::GetFirstAudioContent(offer->description());
2127 EXPECT_TRUE(content != NULL);
2128 content = cricket::GetFirstVideoContent(offer->description());
2129 EXPECT_TRUE(content == NULL);
2130
2131 // Test Audio / Video offer.
2132 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002133 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 content = cricket::GetFirstAudioContent(offer->description());
2135 EXPECT_TRUE(content != NULL);
2136 content = cricket::GetFirstVideoContent(offer->description());
2137 EXPECT_TRUE(content != NULL);
2138}
2139
2140// Test that an offer contains no media content descriptions if
2141// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2142TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002143 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002144 PeerConnectionInterface::RTCOfferAnswerOptions options;
2145 options.offer_to_receive_audio = 0;
2146 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002148 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002149 CreateOffer(options));
2150
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 ASSERT_TRUE(offer != NULL);
2152 const cricket::ContentInfo* content =
2153 cricket::GetFirstAudioContent(offer->description());
2154 EXPECT_TRUE(content == NULL);
2155 content = cricket::GetFirstVideoContent(offer->description());
2156 EXPECT_TRUE(content == NULL);
2157}
2158
2159// Test that an offer contains only audio media content descriptions if
2160// kOfferToReceiveAudio constraints are set to true.
2161TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002162 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002163 PeerConnectionInterface::RTCOfferAnswerOptions options;
2164 options.offer_to_receive_audio =
2165 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2166
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002167 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002168 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169
2170 const cricket::ContentInfo* content =
2171 cricket::GetFirstAudioContent(offer->description());
2172 EXPECT_TRUE(content != NULL);
2173 content = cricket::GetFirstVideoContent(offer->description());
2174 EXPECT_TRUE(content == NULL);
2175}
2176
2177// Test that an offer contains audio and video media content descriptions if
2178// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2179TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002180 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002182 PeerConnectionInterface::RTCOfferAnswerOptions options;
2183 options.offer_to_receive_audio =
2184 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2185 options.offer_to_receive_video =
2186 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2187
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002188 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002189 CreateOffer(options));
2190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 const cricket::ContentInfo* content =
2192 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002193 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002194
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 content = cricket::GetFirstVideoContent(offer->description());
2196 EXPECT_TRUE(content != NULL);
2197
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002198 // Sets constraints to false and verifies that audio/video contents are
2199 // removed.
2200 options.offer_to_receive_audio = 0;
2201 options.offer_to_receive_video = 0;
2202 offer.reset(CreateOffer(options));
2203
2204 content = cricket::GetFirstAudioContent(offer->description());
2205 EXPECT_TRUE(content == NULL);
2206 content = cricket::GetFirstVideoContent(offer->description());
2207 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208}
2209
2210// Test that an answer can not be created if the last remote description is not
2211// an offer.
2212TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002213 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002214 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 SetLocalDescriptionWithoutError(offer);
2216 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2217 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002218 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219}
2220
2221// Test that an answer contains the correct media content descriptions when no
2222// constraints have been set.
2223TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002224 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002226 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002228 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002229 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 const cricket::ContentInfo* content =
2231 cricket::GetFirstAudioContent(answer->description());
2232 ASSERT_TRUE(content != NULL);
2233 EXPECT_FALSE(content->rejected);
2234
2235 content = cricket::GetFirstVideoContent(answer->description());
2236 ASSERT_TRUE(content != NULL);
2237 EXPECT_FALSE(content->rejected);
2238}
2239
2240// Test that an answer contains the correct media content descriptions when no
2241// constraints have been set and the offer only contain audio.
2242TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002243 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 // Create a remote offer with audio only.
2245 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002246
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002247 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 CreateRemoteOffer(options));
2249 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2250 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2251
2252 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002253 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002254 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 const cricket::ContentInfo* content =
2256 cricket::GetFirstAudioContent(answer->description());
2257 ASSERT_TRUE(content != NULL);
2258 EXPECT_FALSE(content->rejected);
2259
2260 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2261}
2262
2263// Test that an answer contains the correct media content descriptions when no
2264// constraints have been set.
2265TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002266 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002268 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 SetRemoteDescriptionWithoutError(offer.release());
2270 // Test with a stream with tracks.
2271 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002272 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002273 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 const cricket::ContentInfo* content =
2275 cricket::GetFirstAudioContent(answer->description());
2276 ASSERT_TRUE(content != NULL);
2277 EXPECT_FALSE(content->rejected);
2278
2279 content = cricket::GetFirstVideoContent(answer->description());
2280 ASSERT_TRUE(content != NULL);
2281 EXPECT_FALSE(content->rejected);
2282}
2283
2284// Test that an answer contains the correct media content descriptions when
2285// constraints have been set but no stream is sent.
2286TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002287 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002289 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 SetRemoteDescriptionWithoutError(offer.release());
2291
2292 webrtc::FakeConstraints constraints_no_receive;
2293 constraints_no_receive.SetMandatoryReceiveAudio(false);
2294 constraints_no_receive.SetMandatoryReceiveVideo(false);
2295
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002296 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002297 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 const cricket::ContentInfo* content =
2299 cricket::GetFirstAudioContent(answer->description());
2300 ASSERT_TRUE(content != NULL);
2301 EXPECT_TRUE(content->rejected);
2302
2303 content = cricket::GetFirstVideoContent(answer->description());
2304 ASSERT_TRUE(content != NULL);
2305 EXPECT_TRUE(content->rejected);
2306}
2307
2308// Test that an answer contains the correct media content descriptions when
2309// constraints have been set and streams are sent.
2310TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002311 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002313 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 SetRemoteDescriptionWithoutError(offer.release());
2315
2316 webrtc::FakeConstraints constraints_no_receive;
2317 constraints_no_receive.SetMandatoryReceiveAudio(false);
2318 constraints_no_receive.SetMandatoryReceiveVideo(false);
2319
2320 // Test with a stream with tracks.
2321 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002322 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002323 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324
2325 // TODO(perkj): Should the direction be set to SEND_ONLY?
2326 const cricket::ContentInfo* content =
2327 cricket::GetFirstAudioContent(answer->description());
2328 ASSERT_TRUE(content != NULL);
2329 EXPECT_FALSE(content->rejected);
2330
2331 // TODO(perkj): Should the direction be set to SEND_ONLY?
2332 content = cricket::GetFirstVideoContent(answer->description());
2333 ASSERT_TRUE(content != NULL);
2334 EXPECT_FALSE(content->rejected);
2335}
2336
2337TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2338 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002339 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002340 PeerConnectionInterface::RTCOfferAnswerOptions options;
2341 options.offer_to_receive_audio =
2342 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2343 options.voice_activity_detection = false;
2344
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002345 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002346 CreateOffer(options));
2347
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 const cricket::ContentInfo* content =
2349 cricket::GetFirstAudioContent(offer->description());
2350 EXPECT_TRUE(content != NULL);
2351 EXPECT_TRUE(VerifyNoCNCodecs(content));
2352}
2353
2354TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2355 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002356 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002358 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 SetRemoteDescriptionWithoutError(offer.release());
2360
2361 webrtc::FakeConstraints constraints;
2362 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002363 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002364 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 const cricket::ContentInfo* content =
2366 cricket::GetFirstAudioContent(answer->description());
2367 ASSERT_TRUE(content != NULL);
2368 EXPECT_TRUE(VerifyNoCNCodecs(content));
2369}
2370
2371// This test verifies the call setup when remote answer with audio only and
2372// later updates with video.
2373TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002374 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2376 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2377
2378 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002379 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380
2381 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2383
2384 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2385 // and answer;
2386 SetLocalDescriptionWithoutError(offer);
2387 SetRemoteDescriptionWithoutError(answer);
2388
2389 video_channel_ = media_engine_->GetVideoChannel(0);
2390 voice_channel_ = media_engine_->GetVoiceChannel(0);
2391
2392 ASSERT_TRUE(video_channel_ == NULL);
2393
2394 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2395 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2396 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2397
2398 // Let the remote end update the session descriptions, with Audio and Video.
2399 mediastream_signaling_.SendAudioVideoStream2();
2400 CreateAndSetRemoteOfferAndLocalAnswer();
2401
2402 video_channel_ = media_engine_->GetVideoChannel(0);
2403 voice_channel_ = media_engine_->GetVoiceChannel(0);
2404
2405 ASSERT_TRUE(video_channel_ != NULL);
2406 ASSERT_TRUE(voice_channel_ != NULL);
2407
2408 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2409 ASSERT_EQ(1u, video_channel_->send_streams().size());
2410 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2411 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2412 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2413 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2414 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2415 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2416
2417 // Change session back to audio only.
2418 mediastream_signaling_.UseOptionsAudioOnly();
2419 CreateAndSetRemoteOfferAndLocalAnswer();
2420
2421 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2422 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2423 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2424 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2425 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2426}
2427
2428// This test verifies the call setup when remote answer with video only and
2429// later updates with audio.
2430TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002431 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2433 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2434 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002435 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436
2437 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002438 options.recv_audio = false;
2439 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2441 offer, options, cricket::SEC_ENABLED);
2442
2443 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2444 // and answer.
2445 SetLocalDescriptionWithoutError(offer);
2446 SetRemoteDescriptionWithoutError(answer);
2447
2448 video_channel_ = media_engine_->GetVideoChannel(0);
2449 voice_channel_ = media_engine_->GetVoiceChannel(0);
2450
2451 ASSERT_TRUE(voice_channel_ == NULL);
2452 ASSERT_TRUE(video_channel_ != NULL);
2453
2454 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2455 ASSERT_EQ(1u, video_channel_->send_streams().size());
2456 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2457
2458 // Update the session descriptions, with Audio and Video.
2459 mediastream_signaling_.SendAudioVideoStream2();
2460 CreateAndSetRemoteOfferAndLocalAnswer();
2461
2462 voice_channel_ = media_engine_->GetVoiceChannel(0);
2463 ASSERT_TRUE(voice_channel_ != NULL);
2464
2465 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2466 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2467 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2468 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2469
2470 // Change session back to video only.
2471 mediastream_signaling_.UseOptionsVideoOnly();
2472 CreateAndSetRemoteOfferAndLocalAnswer();
2473
2474 video_channel_ = media_engine_->GetVideoChannel(0);
2475 voice_channel_ = media_engine_->GetVoiceChannel(0);
2476
2477 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2478 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2479 ASSERT_EQ(1u, video_channel_->send_streams().size());
2480 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2481}
2482
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002484 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002486 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 VerifyCryptoParams(offer->description());
2488 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002489 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 VerifyCryptoParams(answer->description());
2491}
2492
2493TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002494 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002497 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 VerifyNoCryptoParams(offer->description(), false);
2499}
2500
2501TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002502 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 VerifyAnswerFromNonCryptoOffer();
2504}
2505
2506TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002507 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 VerifyAnswerFromCryptoOffer();
2509}
2510
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002511// This test verifies that setLocalDescription fails if
2512// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2513TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002514 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002515 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002516 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2517
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002518 std::string sdp;
2519 RemoveIceUfragPwdLines(offer.get(), &sdp);
2520 SessionDescriptionInterface* modified_offer =
2521 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002522 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002523}
2524
2525// This test verifies that setRemoteDescription fails if
2526// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2527TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002528 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002529 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002530 std::string sdp;
2531 RemoveIceUfragPwdLines(offer.get(), &sdp);
2532 SessionDescriptionInterface* modified_offer =
2533 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002534 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002535}
2536
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002537// This test verifies that setLocalDescription fails if local offer has
2538// too short ice ufrag and pwd strings.
2539TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
pthatcherfa301802015-08-11 04:12:56 -07002541 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002542 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002543 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2544
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002545 std::string sdp;
2546 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2547 // recommended values of 4 and 22 bytes respectively.
2548 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2549 SessionDescriptionInterface* modified_offer =
2550 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2551 std::string error;
2552 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2553
2554 // Test with string greater than 256.
2555 sdp.clear();
2556 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2557 &sdp);
2558 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2559 NULL);
2560 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2561}
2562
2563// This test verifies that setRemoteDescription fails if remote offer has
2564// too short ice ufrag and pwd strings.
2565TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002566 Init();
pthatcherfa301802015-08-11 04:12:56 -07002567 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002568 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002569 std::string sdp;
2570 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2571 // recommended values of 4 and 22 bytes respectively.
2572 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2573 SessionDescriptionInterface* modified_offer =
2574 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2575 std::string error;
2576 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2577
2578 sdp.clear();
2579 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2580 &sdp);
2581 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2582 NULL);
2583 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2584}
2585
honghaiz503726c2015-07-31 12:37:38 -07002586// Test that if the remote description indicates the peer requested ICE restart
2587// (via a new ufrag or pwd), the old ICE candidates are not copied,
2588// and vice versa.
2589TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2590 Init();
2591 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2592
2593 // Create the first offer.
2594 std::string sdp;
2595 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2596 "abcdefghijklmnopqrstuvwx", &sdp);
2597 SessionDescriptionInterface* offer1 =
2598 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2599 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2600 0, "", "", "relay", 0, "");
2601 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2602 candidate1);
2603 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2604 SetRemoteDescriptionWithoutError(offer1);
2605 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2606
2607 // The second offer has the same ufrag and pwd but different address.
2608 sdp.clear();
2609 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2610 "abcdefghijklmnopqrstuvwx", &sdp);
2611 SessionDescriptionInterface* offer2 =
2612 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2613 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2614 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2615 candidate1);
2616 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2617 SetRemoteDescriptionWithoutError(offer2);
2618 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2619
2620 // The third offer has a different ufrag and different address.
2621 sdp.clear();
2622 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2623 "abcdefghijklmnopqrstuvwx", &sdp);
2624 SessionDescriptionInterface* offer3 =
2625 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2626 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2627 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2628 candidate1);
2629 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2630 SetRemoteDescriptionWithoutError(offer3);
2631 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2632
2633 // The fourth offer has no candidate but a different ufrag/pwd.
2634 sdp.clear();
2635 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2636 "abcdefghijklmnopqrstuvyz", &sdp);
2637 SessionDescriptionInterface* offer4 =
2638 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2639 SetRemoteDescriptionWithoutError(offer4);
2640 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2641}
2642
Donald Curtisd4f769d2015-05-28 09:48:21 -07002643// Test that candidates sent to the "video" transport do not get pushed down to
2644// the "audio" transport channel when bundling using TransportProxy.
2645TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2646 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2647
2648 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2649 mediastream_signaling_.SendAudioVideoStream1();
2650
2651 PeerConnectionInterface::RTCOfferAnswerOptions options;
2652 options.use_rtp_mux = true;
2653
2654 SessionDescriptionInterface* offer = CreateRemoteOffer();
2655 SetRemoteDescriptionWithoutError(offer);
2656
2657 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2658 SetLocalDescriptionWithoutError(answer);
2659
2660 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2661 session_->GetTransportProxy("video")->impl());
2662
2663 cricket::Transport* t = session_->GetTransport("audio");
2664
2665 // Checks if one of the transport channels contains a connection using a given
2666 // port.
2667 auto connection_with_remote_port = [t](int port) {
2668 cricket::TransportStats stats;
2669 t->GetStats(&stats);
2670 for (auto& chan_stat : stats.channel_stats) {
2671 for (auto& conn_info : chan_stat.connection_infos) {
2672 if (conn_info.remote_candidate.address().port() == port) {
2673 return true;
2674 }
2675 }
2676 }
2677 return false;
2678 };
2679
2680 EXPECT_FALSE(connection_with_remote_port(5000));
2681 EXPECT_FALSE(connection_with_remote_port(5001));
2682 EXPECT_FALSE(connection_with_remote_port(6000));
2683
2684 // The way the *_WAIT checks work is they only wait if the condition fails,
2685 // which does not help in the case where state is not changing. This is
2686 // problematic in this test since we want to verify that adding a video
2687 // candidate does _not_ change state. So we interleave candidates and assume
2688 // that messages are executed in the order they were posted.
2689
2690 // First audio candidate.
2691 cricket::Candidate candidate0;
2692 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2693 candidate0.set_component(1);
2694 candidate0.set_protocol("udp");
2695 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2696 candidate0);
2697 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2698
2699 // Video candidate.
2700 cricket::Candidate candidate1;
2701 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2702 candidate1.set_component(1);
2703 candidate1.set_protocol("udp");
2704 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2705 candidate1);
2706 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2707
2708 // Second audio candidate.
2709 cricket::Candidate candidate2;
2710 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2711 candidate2.set_component(1);
2712 candidate2.set_protocol("udp");
2713 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2714 candidate2);
2715 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2716
2717 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2718 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2719
2720 // No need here for a _WAIT check since we are checking that state hasn't
2721 // changed: if this is false we would be doing waits for nothing and if this
2722 // is true then there will be no messages processed anyways.
2723 EXPECT_FALSE(connection_with_remote_port(6000));
2724}
2725
Peter Thatcher4eddf182015-04-30 10:55:59 -07002726// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002727TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2728 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002730
2731 PeerConnectionInterface::RTCOfferAnswerOptions options;
2732 options.use_rtp_mux = true;
2733
2734 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002736
2737 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2738 session_->GetTransportProxy("video")->impl());
2739
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002741 SessionDescriptionInterface* answer =
2742 CreateRemoteAnswer(session_->local_description());
2743 SetRemoteDescriptionWithoutError(answer);
2744
2745 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2746 session_->GetTransportProxy("video")->impl());
2747}
2748
2749// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2750TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2751 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2752 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002753
Donald Curtis0e209b02015-03-24 09:29:54 -07002754 PeerConnectionInterface::RTCOfferAnswerOptions options;
2755 options.use_rtp_mux = true;
2756
2757 SessionDescriptionInterface* offer = CreateOffer(options);
2758 SetLocalDescriptionWithoutError(offer);
2759
2760 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2761 session_->GetTransportProxy("video")->impl());
2762
2763 mediastream_signaling_.SendAudioVideoStream2();
2764
2765 // Remove BUNDLE from the answer.
2766 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2767 CreateRemoteAnswer(session_->local_description()));
2768 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2769 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2770 JsepSessionDescription* modified_answer =
2771 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2772 modified_answer->Initialize(answer_copy, "1", "1");
2773 SetRemoteDescriptionWithoutError(modified_answer); //
2774
2775 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2776 session_->GetTransportProxy("video")->impl());
2777}
2778
2779// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2780TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2781 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2782 mediastream_signaling_.SendAudioVideoStream1();
2783
2784 PeerConnectionInterface::RTCOfferAnswerOptions options;
2785 options.use_rtp_mux = true;
2786
2787 SessionDescriptionInterface* offer = CreateOffer(options);
2788 SetLocalDescriptionWithoutError(offer);
2789
2790 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2791 session_->GetTransportProxy("video")->impl());
2792
2793 mediastream_signaling_.SendAudioVideoStream2();
2794 SessionDescriptionInterface* answer =
2795 CreateRemoteAnswer(session_->local_description());
2796 SetRemoteDescriptionWithoutError(answer);
2797
2798 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2799 session_->GetTransportProxy("video")->impl());
2800}
2801
2802// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2803TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2804 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2805 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002806
Donald Curtis0e209b02015-03-24 09:29:54 -07002807 PeerConnectionInterface::RTCOfferAnswerOptions options;
2808 options.use_rtp_mux = true;
2809
2810 SessionDescriptionInterface* offer = CreateOffer(options);
2811 SetLocalDescriptionWithoutError(offer);
2812
2813 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2814 session_->GetTransportProxy("video")->impl());
2815
2816 mediastream_signaling_.SendAudioVideoStream2();
2817
2818 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002819 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 CreateRemoteAnswer(session_->local_description()));
2821 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2822 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2823 JsepSessionDescription* modified_answer =
2824 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2825 modified_answer->Initialize(answer_copy, "1", "1");
2826 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827
Donald Curtis0e209b02015-03-24 09:29:54 -07002828 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2829 session_->GetTransportProxy("video")->impl());
2830}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831
Peter Thatcher4eddf182015-04-30 10:55:59 -07002832// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002833TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2834 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2835 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836
Donald Curtis0e209b02015-03-24 09:29:54 -07002837 PeerConnectionInterface::RTCOfferAnswerOptions options;
2838 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839
Donald Curtis0e209b02015-03-24 09:29:54 -07002840 SessionDescriptionInterface* offer = CreateOffer(options);
2841 SetLocalDescriptionWithoutError(offer);
2842
2843 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2844 session_->GetTransportProxy("video")->impl());
2845
2846 mediastream_signaling_.SendAudioVideoStream2();
2847 SessionDescriptionInterface* answer =
2848 CreateRemoteAnswer(session_->local_description());
2849 SetRemoteDescriptionWithoutError(answer);
2850
2851 // This should lead to an audio-only call but isn't implemented
2852 // correctly yet.
2853 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2854 session_->GetTransportProxy("video")->impl());
2855}
2856
2857// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2858TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2859 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2860 mediastream_signaling_.SendAudioVideoStream1();
2861 PeerConnectionInterface::RTCOfferAnswerOptions options;
2862 options.use_rtp_mux = true;
2863
2864 SessionDescriptionInterface* offer = CreateOffer(options);
2865 SetLocalDescriptionWithoutError(offer);
2866
2867 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2868 session_->GetTransportProxy("video")->impl());
2869
2870 mediastream_signaling_.SendAudioVideoStream2();
2871
2872 // Remove BUNDLE from the answer.
2873 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2874 CreateRemoteAnswer(session_->local_description()));
2875 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2876 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2877 JsepSessionDescription* modified_answer =
2878 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2879 modified_answer->Initialize(answer_copy, "1", "1");
2880 SetRemoteDescriptionWithoutError(modified_answer); //
2881
2882 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2883 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884}
2885
Peter Thatcher4eddf182015-04-30 10:55:59 -07002886// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2887TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2888 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2889 mediastream_signaling_.SendAudioVideoStream1();
2890
2891 PeerConnectionInterface::RTCOfferAnswerOptions options;
2892 options.use_rtp_mux = true;
2893
2894 SessionDescriptionInterface* offer = CreateOffer(options);
2895 SetRemoteDescriptionWithoutError(offer);
2896
2897 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2898 session_->GetTransportProxy("video")->impl());
2899}
2900
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002901TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2902 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2903 mediastream_signaling_.SendAudioVideoStream1();
2904
2905 PeerConnectionInterface::RTCOfferAnswerOptions options;
2906 SessionDescriptionInterface* offer = CreateOffer(options);
2907 SetLocalDescriptionWithoutError(offer);
2908
2909 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2910 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2911
2912 mediastream_signaling_.SendAudioVideoStream2();
2913 SessionDescriptionInterface* answer =
2914 CreateRemoteAnswer(session_->local_description());
2915 SetRemoteDescriptionWithoutError(answer);
2916
2917 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2918 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2919}
2920
2921TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2922 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2923 mediastream_signaling_.SendAudioVideoStream1();
2924
2925 PeerConnectionInterface::RTCOfferAnswerOptions options;
2926 SessionDescriptionInterface* offer = CreateOffer(options);
2927 SetLocalDescriptionWithoutError(offer);
2928
2929 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2930 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2931
2932 mediastream_signaling_.SendAudioVideoStream2();
2933 SessionDescriptionInterface* answer =
2934 CreateRemoteAnswer(session_->local_description());
2935 SetRemoteDescriptionWithoutError(answer);
2936
2937 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2938 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2939}
2940
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002941// This test verifies that SetLocalDescription and SetRemoteDescription fails
2942// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2943TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002944 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002945 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002946
2947 PeerConnectionInterface::RTCOfferAnswerOptions options;
2948 options.use_rtp_mux = true;
2949
2950 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002951 std::string offer_str;
2952 offer->ToString(&offer_str);
2953 // Disable rtcp-mux
2954 const std::string rtcp_mux = "rtcp-mux";
2955 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002956 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002957 xrtcp_mux.c_str(), xrtcp_mux.length(),
2958 &offer_str);
2959 JsepSessionDescription *local_offer =
2960 new JsepSessionDescription(JsepSessionDescription::kOffer);
2961 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002962 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002963 JsepSessionDescription *remote_offer =
2964 new JsepSessionDescription(JsepSessionDescription::kOffer);
2965 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002966 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002967 // Trying unmodified SDP.
2968 SetLocalDescriptionWithoutError(offer);
2969}
2970
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002972 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 mediastream_signaling_.SendAudioVideoStream1();
2974 CreateAndSetRemoteOfferAndLocalAnswer();
2975 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2976 ASSERT_TRUE(channel != NULL);
2977 ASSERT_EQ(1u, channel->recv_streams().size());
2978 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2979 double left_vol, right_vol;
2980 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2981 EXPECT_EQ(1, left_vol);
2982 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002983 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002984 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2986 EXPECT_EQ(0, left_vol);
2987 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002988 EXPECT_EQ(0, renderer->channel_id());
2989 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2991 EXPECT_EQ(1, left_vol);
2992 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002993 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994}
2995
2996TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002997 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 mediastream_signaling_.SendAudioVideoStream1();
2999 CreateAndSetRemoteOfferAndLocalAnswer();
3000 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3001 ASSERT_TRUE(channel != NULL);
3002 ASSERT_EQ(1u, channel->send_streams().size());
3003 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3004 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3005
3006 cricket::AudioOptions options;
3007 options.echo_cancellation.Set(true);
3008
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003009 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003010 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3012 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003013 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003014 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003016 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003017 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3019 bool value;
3020 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3021 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003022 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003023 EXPECT_TRUE(renderer->sink() == NULL);
3024}
3025
3026TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003027 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003028 mediastream_signaling_.SendAudioVideoStream1();
3029 CreateAndSetRemoteOfferAndLocalAnswer();
3030 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3031 ASSERT_TRUE(channel != NULL);
3032 ASSERT_EQ(1u, channel->send_streams().size());
3033 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3034
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003035 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003036 cricket::AudioOptions options;
3037 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3038 EXPECT_TRUE(renderer->sink() != NULL);
3039
3040 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3041 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3042 // SetSink(NULL) callback afterwards.
3043 renderer.reset();
3044
3045 // This will trigger SetSink(NULL) if no OnClose() callback.
3046 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047}
3048
3049TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003050 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051 mediastream_signaling_.SendAudioVideoStream1();
3052 CreateAndSetRemoteOfferAndLocalAnswer();
3053 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3054 ASSERT_TRUE(channel != NULL);
3055 ASSERT_LT(0u, channel->renderers().size());
3056 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3057 ASSERT_EQ(1u, channel->recv_streams().size());
3058 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3059 cricket::FakeVideoRenderer renderer;
3060 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3061 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3062 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3063 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3064}
3065
3066TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003067 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003068 mediastream_signaling_.SendAudioVideoStream1();
3069 CreateAndSetRemoteOfferAndLocalAnswer();
3070 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3071 ASSERT_TRUE(channel != NULL);
3072 ASSERT_EQ(1u, channel->send_streams().size());
3073 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3074 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3075 cricket::VideoOptions* options = NULL;
3076 session_->SetVideoSend(send_ssrc, false, options);
3077 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3078 session_->SetVideoSend(send_ssrc, true, options);
3079 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3080}
3081
3082TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3083 TestCanInsertDtmf(false);
3084}
3085
3086TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3087 TestCanInsertDtmf(true);
3088}
3089
3090TEST_F(WebRtcSessionTest, InsertDtmf) {
3091 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003092 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093 mediastream_signaling_.SendAudioVideoStream1();
3094 CreateAndSetRemoteOfferAndLocalAnswer();
3095 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3096 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3097
3098 // Insert DTMF
3099 const int expected_flags = DF_SEND;
3100 const int expected_duration = 90;
3101 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3102 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3103 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3104
3105 // Verify
3106 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3107 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3108 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3109 expected_duration, expected_flags));
3110 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3111 expected_duration, expected_flags));
3112 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3113 expected_duration, expected_flags));
3114}
3115
3116// This test verifies the |initiator| flag when session initiates the call.
3117TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003118 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003119 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003120 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3122 SetLocalDescriptionWithoutError(offer);
3123 EXPECT_TRUE(session_->initiator());
3124 SetRemoteDescriptionWithoutError(answer);
3125 EXPECT_TRUE(session_->initiator());
3126}
3127
3128// This test verifies the |initiator| flag when session receives the call.
3129TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003130 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131 EXPECT_FALSE(session_->initiator());
3132 SessionDescriptionInterface* offer = CreateRemoteOffer();
3133 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003134 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135
3136 EXPECT_FALSE(session_->initiator());
3137 SetLocalDescriptionWithoutError(answer);
3138 EXPECT_FALSE(session_->initiator());
3139}
3140
pthatcherfa301802015-08-11 04:12:56 -07003141// This test verifies the ice protocol type at initiator of the call
3142// if |a=ice-options:google-ice| is present in answer.
3143TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
3144 Init();
3145 mediastream_signaling_.SendAudioVideoStream1();
3146 SessionDescriptionInterface* offer = CreateOffer();
3147 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3148 CreateRemoteAnswer(offer));
3149 SetLocalDescriptionWithoutError(offer);
3150 std::string sdp;
3151 EXPECT_TRUE(answer->ToString(&sdp));
3152 // Adding ice-options to the session level.
3153 InjectAfter("t=0 0\r\n",
3154 "a=ice-options:google-ice\r\n",
3155 &sdp);
3156 SessionDescriptionInterface* answer_with_gice =
3157 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3158 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3159 // only gice to fail.
3160 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
3161}
3162
3163// This test verifies the ice protocol type at initiator of the call
3164// if ICE RFC5245 is supported in answer.
3165TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
3166 Init();
3167 mediastream_signaling_.SendAudioVideoStream1();
3168 SessionDescriptionInterface* offer = CreateOffer();
3169 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3170 SetLocalDescriptionWithoutError(offer);
3171
3172 SetRemoteDescriptionWithoutError(answer);
3173 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3174 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3175}
3176
3177// This test verifies the ice protocol type at receiver side of the call if
3178// receiver decides to use ice RFC 5245.
3179TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
3180 Init();
3181 mediastream_signaling_.SendAudioVideoStream1();
3182 SessionDescriptionInterface* offer = CreateOffer();
3183 SetRemoteDescriptionWithoutError(offer);
3184 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3185 SetLocalDescriptionWithoutError(answer);
3186 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3187 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3188}
3189
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3191TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003192 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003194 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003195 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003196 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197 CreateRemoteAnswer(session_->local_description()));
3198
3199 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3200 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003201 JsepSessionDescription* modified_answer =
3202 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203
3204 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3205 answer->session_id(),
3206 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003207 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208
wu@webrtc.org4e393072014-04-07 17:04:35 +00003209 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 std::string sdp;
3211 EXPECT_TRUE(answer->ToString(&sdp));
3212 const std::string kAudioMid = "a=mid:audio";
3213 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003214 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003215 kAudioMidReplaceStr.c_str(),
3216 kAudioMidReplaceStr.length(),
3217 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003218 SessionDescriptionInterface* modified_answer1 =
3219 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003220 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003221
wu@webrtc.org4e393072014-04-07 17:04:35 +00003222 // Different media types.
3223 EXPECT_TRUE(answer->ToString(&sdp));
3224 const std::string kAudioMline = "m=audio";
3225 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003226 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003227 kAudioMlineReplaceStr.c_str(),
3228 kAudioMlineReplaceStr.length(),
3229 &sdp);
3230 SessionDescriptionInterface* modified_answer2 =
3231 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3232 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234 SetRemoteDescriptionWithoutError(answer.release());
3235}
3236
3237// Verifying remote offer and local answer have matching m-lines as per
3238// RFC 3264.
3239TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003240 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003241 mediastream_signaling_.SendAudioVideoStream1();
3242 SessionDescriptionInterface* offer = CreateRemoteOffer();
3243 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003244 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
3246 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3247 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003248 JsepSessionDescription* modified_answer =
3249 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250
3251 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3252 answer->session_id(),
3253 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003254 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255 SetLocalDescriptionWithoutError(answer);
3256}
3257
3258// This test verifies that WebRtcSession does not start candidate allocation
3259// before SetLocalDescription is called.
3260TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003261 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003262 mediastream_signaling_.SendAudioVideoStream1();
3263 SessionDescriptionInterface* offer = CreateRemoteOffer();
3264 cricket::Candidate candidate;
3265 candidate.set_component(1);
3266 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3267 candidate);
3268 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3269 cricket::Candidate candidate1;
3270 candidate1.set_component(1);
3271 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3272 candidate1);
3273 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3274 SetRemoteDescriptionWithoutError(offer);
3275 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3276 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3277
3278 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003279 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3281 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3282
wu@webrtc.org91053e72013-08-10 07:18:04 +00003283 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284 SetLocalDescriptionWithoutError(answer);
3285 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3286 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3287 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3288}
3289
3290// This test verifies that crypto parameter is updated in local session
3291// description as per security policy set in MediaSessionDescriptionFactory.
3292TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003293 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003295 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296
3297 // Making sure SetLocalDescription correctly sets crypto value in
3298 // SessionDescription object after de-serialization of sdp string. The value
3299 // will be set as per MediaSessionDescriptionFactory.
3300 std::string offer_str;
3301 offer->ToString(&offer_str);
3302 SessionDescriptionInterface* jsep_offer_str =
3303 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3304 SetLocalDescriptionWithoutError(jsep_offer_str);
3305 EXPECT_TRUE(session_->voice_channel()->secure_required());
3306 EXPECT_TRUE(session_->video_channel()->secure_required());
3307}
3308
3309// This test verifies the crypto parameter when security is disabled.
3310TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003311 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003312 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003314 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315
3316 // Making sure SetLocalDescription correctly sets crypto value in
3317 // SessionDescription object after de-serialization of sdp string. The value
3318 // will be set as per MediaSessionDescriptionFactory.
3319 std::string offer_str;
3320 offer->ToString(&offer_str);
3321 SessionDescriptionInterface *jsep_offer_str =
3322 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3323 SetLocalDescriptionWithoutError(jsep_offer_str);
3324 EXPECT_FALSE(session_->voice_channel()->secure_required());
3325 EXPECT_FALSE(session_->video_channel()->secure_required());
3326}
3327
3328// This test verifies that an answer contains new ufrag and password if an offer
3329// with new ufrag and password is received.
3330TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003331 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003333 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003334 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335 CreateRemoteOffer(options));
3336 SetRemoteDescriptionWithoutError(offer.release());
3337
3338 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003339 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003340 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341 SetLocalDescriptionWithoutError(answer.release());
3342
3343 // Receive an offer with new ufrag and password.
3344 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003345 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003346 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347 SetRemoteDescriptionWithoutError(updated_offer1.release());
3348
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003350 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351
3352 CompareIceUfragAndPassword(updated_answer1->description(),
3353 session_->local_description()->description(),
3354 false);
3355
3356 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003357}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358
wu@webrtc.org91053e72013-08-10 07:18:04 +00003359// This test verifies that an answer contains old ufrag and password if an offer
3360// with old ufrag and password is received.
3361TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003362 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003363 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003364 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003365 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003366 CreateRemoteOffer(options));
3367 SetRemoteDescriptionWithoutError(offer.release());
3368
3369 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003370 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003371 CreateAnswer(NULL));
3372 SetLocalDescriptionWithoutError(answer.release());
3373
3374 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003376 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003377 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 SetRemoteDescriptionWithoutError(updated_offer2.release());
3379
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003380 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003381 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382
3383 CompareIceUfragAndPassword(updated_answer2->description(),
3384 session_->local_description()->description(),
3385 true);
3386
3387 SetLocalDescriptionWithoutError(updated_answer2.release());
3388}
3389
3390TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003391 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003393 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 const std::string session_id_orig = offer->session_id();
3395 const std::string session_version_orig = offer->session_version();
3396 SetLocalDescriptionWithoutError(offer);
3397
3398 video_channel_ = media_engine_->GetVideoChannel(0);
3399 video_channel_->set_fail_set_send_codecs(true);
3400
3401 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003402 SessionDescriptionInterface* answer =
3403 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003404 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405}
3406
3407// Runs the loopback call test with BUNDLE and STUN disabled.
3408TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3409 // Lets try with only UDP ports.
pthatcherfa301802015-08-11 04:12:56 -07003410 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3411 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003412 cricket::PORTALLOCATOR_DISABLE_STUN |
3413 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 TestLoopbackCall();
3415}
3416
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003417TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
pthatcherfa301802015-08-11 04:12:56 -07003418 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3419 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003420 cricket::PORTALLOCATOR_DISABLE_STUN |
3421 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3422 cricket::PORTALLOCATOR_DISABLE_RELAY);
3423
3424 // best connection is IPv6 since it has higher network preference.
3425 LoopbackNetworkConfiguration config;
3426 config.test_ipv6_network_ = true;
3427 config.best_connection_after_initial_ice_converged_ =
3428 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3429
3430 TestLoopbackCall(config);
3431}
3432
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003433// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003434TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
pthatcherfa301802015-08-11 04:12:56 -07003435 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3436 cricket::PORTALLOCATOR_DISABLE_TCP |
3437 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003438 TestLoopbackCall();
3439}
3440
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003441TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003442 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003444 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003446 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3447 std::string error_code_str = "ERROR_CONTENT";
3448 std::string error_desc = "Fake session error description.";
3449 session_->SetError(error_code, error_desc);
3450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3452 SessionDescriptionInterface* answer =
3453 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003454
3455 std::string action;
3456 std::ostringstream session_error_msg;
3457 session_error_msg << kSessionError << error_code_str << ". ";
3458 session_error_msg << kSessionErrorDesc << error_desc << ".";
3459 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3460 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461}
3462
3463TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3464 constraints_.reset(new FakeConstraints());
3465 constraints_->AddOptional(
3466 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003467 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468
3469 SetLocalDescriptionWithDataChannel();
3470 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3471}
3472
3473TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003474 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475
3476 constraints_.reset(new FakeConstraints());
3477 constraints_->AddOptional(
3478 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003479 options_.disable_sctp_data_channels = false;
3480
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003481 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482
3483 SetLocalDescriptionWithDataChannel();
3484 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3485}
3486
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003487TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003488 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003489
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003490 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003491
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003492 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003493 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003494 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3495}
3496
3497TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003498 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003499 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003500 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003501
3502 // Create remote offer with SCTP.
3503 cricket::MediaSessionOptions options;
3504 options.data_channel_type = cricket::DCT_SCTP;
3505 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003506 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003507 SetRemoteDescriptionWithoutError(offer);
3508
3509 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003510 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003511 EXPECT_TRUE(answer != NULL);
3512 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3513 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003514}
3515
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3517 constraints_.reset(new FakeConstraints());
3518 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003519 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003520 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521
3522 SetLocalDescriptionWithDataChannel();
3523 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3524}
3525
3526TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003527 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003529 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530
3531 SetLocalDescriptionWithDataChannel();
3532 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3533}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003534
wu@webrtc.org97077a32013-10-25 21:18:33 +00003535TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003536 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003537 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003538 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003539
3540 SetLocalDescriptionWithDataChannel();
3541 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3542}
3543
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003544TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003545 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003546 const int new_send_port = 9998;
3547 const int new_recv_port = 7775;
3548
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003549 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003550 SetFactoryDtlsSrtp();
3551
3552 // By default, don't actually add the codecs to desc_factory_; they don't
3553 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3554 // let the session description get parsed. That'll get the proper codecs
3555 // into the stream.
3556 cricket::MediaSessionOptions options;
3557 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3558 "stream1", new_send_port, options);
3559
3560 // SetRemoteDescription will take the ownership of the offer.
3561 SetRemoteDescriptionWithoutError(offer);
3562
3563 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3564 new_recv_port, CreateAnswer(NULL));
3565 ASSERT_TRUE(answer != NULL);
3566
3567 // Now set the local description, which'll take ownership of the answer.
3568 SetLocalDescriptionWithoutError(answer);
3569
3570 // TEST PLAN: Set the port number to something new, set it in the SDP,
3571 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003572 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003573 dci.reliable = true;
3574 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003575 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003576 session_->CreateDataChannel("datachannel", &dci);
3577
3578 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3579 int portnum = -1;
3580 ASSERT_TRUE(ch != NULL);
3581 ASSERT_EQ(1UL, ch->send_codecs().size());
3582 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003583 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003584 ch->send_codecs()[0].name.c_str()));
3585 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3586 &portnum));
3587 EXPECT_EQ(new_send_port, portnum);
3588
3589 ASSERT_EQ(1UL, ch->recv_codecs().size());
3590 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003591 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003592 ch->recv_codecs()[0].name.c_str()));
3593 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3594 &portnum));
3595 EXPECT_EQ(new_recv_port, portnum);
3596}
3597
wu@webrtc.org91053e72013-08-10 07:18:04 +00003598// Verifies that CreateOffer succeeds when CreateOffer is called before async
3599// identity generation is finished.
3600TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003601 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003602 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003603
3604 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003605 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003606 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3607
wu@webrtc.org91053e72013-08-10 07:18:04 +00003608 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003609 VerifyNoCryptoParams(offer->description(), true);
3610 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003611}
3612
3613// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3614// identity generation is finished.
3615TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003616 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003617 InitWithDtls();
3618 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003619
3620 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003621 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003622 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003623 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003624 ASSERT_TRUE(offer.get() != NULL);
3625 SetRemoteDescriptionWithoutError(offer.release());
3626
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003627 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003628 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003629 VerifyNoCryptoParams(answer->description(), true);
3630 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003631}
3632
3633// Verifies that CreateOffer succeeds when CreateOffer is called after async
3634// identity generation is finished.
3635TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003636 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003637 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003638
3639 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003640
3641 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003642 EXPECT_TRUE(offer != NULL);
3643}
3644
3645// Verifies that CreateOffer fails when CreateOffer is called after async
3646// identity generation fails.
3647TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003648 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003649 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003650
3651 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003652
3653 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003654 EXPECT_TRUE(offer == NULL);
3655}
3656
3657// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3658// before async identity generation is finished.
3659TEST_F(WebRtcSessionTest,
3660 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003661 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003662 VerifyMultipleAsyncCreateDescription(
3663 true, CreateSessionDescriptionRequest::kOffer);
3664}
3665
3666// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3667// before async identity generation fails.
3668TEST_F(WebRtcSessionTest,
3669 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003670 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003671 VerifyMultipleAsyncCreateDescription(
3672 false, CreateSessionDescriptionRequest::kOffer);
3673}
3674
3675// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3676// before async identity generation is finished.
3677TEST_F(WebRtcSessionTest,
3678 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003679 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003680 VerifyMultipleAsyncCreateDescription(
3681 true, CreateSessionDescriptionRequest::kAnswer);
3682}
3683
3684// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3685// before async identity generation fails.
3686TEST_F(WebRtcSessionTest,
3687 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003688 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003689 VerifyMultipleAsyncCreateDescription(
3690 false, CreateSessionDescriptionRequest::kAnswer);
3691}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003692
3693// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3694// offer has no SDES crypto but only DTLS fingerprint.
3695TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3696 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003697 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003698 // Create a remote offer with secured transport disabled.
3699 cricket::MediaSessionOptions options;
3700 JsepSessionDescription* offer(CreateRemoteOffer(
3701 options, cricket::SEC_DISABLED));
3702 // Adds a DTLS fingerprint to the remote offer.
3703 cricket::SessionDescription* sdp = offer->description();
3704 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3705 ASSERT_TRUE(audio != NULL);
3706 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3707 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003708 rtc::SSLFingerprint::CreateFromRfc4572(
3709 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003710 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003711 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003712}
3713
wu@webrtc.orgde305012013-10-31 15:40:38 +00003714// This test verifies DSCP is properly applied on the media channels.
3715TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3716 constraints_.reset(new FakeConstraints());
3717 constraints_->AddOptional(
3718 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003719 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003720 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003721 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003722
3723 SetLocalDescriptionWithoutError(offer);
3724
3725 video_channel_ = media_engine_->GetVideoChannel(0);
3726 voice_channel_ = media_engine_->GetVoiceChannel(0);
3727
3728 ASSERT_TRUE(video_channel_ != NULL);
3729 ASSERT_TRUE(voice_channel_ != NULL);
3730 cricket::AudioOptions audio_options;
3731 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3732 cricket::VideoOptions video_options;
3733 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3734 EXPECT_TRUE(audio_options.dscp.IsSet());
3735 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3736 EXPECT_TRUE(video_options.dscp.IsSet());
3737 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3738}
3739
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003740TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3741 constraints_.reset(new FakeConstraints());
3742 constraints_->AddOptional(
3743 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3744 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003745 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003746 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003747 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003748
3749 SetLocalDescriptionWithoutError(offer);
3750
3751 video_channel_ = media_engine_->GetVideoChannel(0);
3752
3753 ASSERT_TRUE(video_channel_ != NULL);
3754 cricket::VideoOptions video_options;
3755 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3756 EXPECT_TRUE(
3757 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3758}
3759
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003760TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3761 // Number of unsignalled receiving streams should be between 0 and
3762 // kMaxUnsignalledRecvStreams.
3763 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3764 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3765 kMaxUnsignalledRecvStreams);
3766 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3767}
3768
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003769TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3770 constraints_.reset(new FakeConstraints());
3771 constraints_->AddOptional(
3772 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3773 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003774 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003775 mediastream_signaling_.SendAudioVideoStream1();
3776 SessionDescriptionInterface* offer = CreateOffer();
3777
3778 SetLocalDescriptionWithoutError(offer);
3779
3780 voice_channel_ = media_engine_->GetVoiceChannel(0);
3781
3782 ASSERT_TRUE(voice_channel_ != NULL);
3783 cricket::AudioOptions audio_options;
3784 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3785 EXPECT_TRUE(
3786 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3787}
3788
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003789// Tests that we can renegotiate new media content with ICE candidates in the
3790// new remote SDP.
3791TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003792 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003793 InitWithDtls();
3794 SetFactoryDtlsSrtp();
3795
3796 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003797 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003798 SetLocalDescriptionWithoutError(offer);
3799
3800 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3801 SetRemoteDescriptionWithoutError(answer);
3802
3803 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003804 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003805 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3806
3807 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003808 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003809 candidate1.set_component(1);
3810 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3811 candidate1);
3812 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3813 SetRemoteDescriptionWithoutError(offer);
3814
3815 answer = CreateAnswer(NULL);
3816 SetLocalDescriptionWithoutError(answer);
3817}
3818
3819// Tests that we can renegotiate new media content with ICE candidates separated
3820// from the remote SDP.
3821TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003822 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003823 InitWithDtls();
3824 SetFactoryDtlsSrtp();
3825
3826 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003827 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003828 SetLocalDescriptionWithoutError(offer);
3829
3830 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3831 SetRemoteDescriptionWithoutError(answer);
3832
3833 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003834 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003835 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3836 SetRemoteDescriptionWithoutError(offer);
3837
3838 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003839 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003840 candidate1.set_component(1);
3841 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3842 candidate1);
3843 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3844
3845 answer = CreateAnswer(NULL);
3846 SetLocalDescriptionWithoutError(answer);
3847}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003848// Tests that RTX codec is removed from the answer when it isn't supported
3849// by local side.
3850TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3851 Init();
3852 mediastream_signaling_.SendAudioVideoStream1();
3853 std::string offer_sdp(kSdpWithRtx);
3854
3855 SessionDescriptionInterface* offer =
3856 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3857 EXPECT_TRUE(offer->ToString(&offer_sdp));
3858
3859 // Offer SDP contains the RTX codec.
3860 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3861 SetRemoteDescriptionWithoutError(offer);
3862
3863 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3864 std::string answer_sdp;
3865 answer->ToString(&answer_sdp);
3866 // Answer SDP removes the unsupported RTX codec.
3867 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3868 SetLocalDescriptionWithoutError(answer);
3869}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003870
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003871// This verifies that the voice channel after bundle has both options from video
3872// and voice channels.
3873TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3874 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3875 mediastream_signaling_.SendAudioVideoStream1();
3876
3877 PeerConnectionInterface::RTCOfferAnswerOptions options;
3878 options.use_rtp_mux = true;
3879
3880 SessionDescriptionInterface* offer = CreateOffer(options);
3881 SetLocalDescriptionWithoutError(offer);
3882
3883 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3884 rtc::Socket::Option::OPT_SNDBUF, 4000);
3885
3886 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3887 rtc::Socket::Option::OPT_RCVBUF, 8000);
3888
3889 int option_val;
3890 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3891 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3892 EXPECT_EQ(4000, option_val);
3893 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3894 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3895
3896 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3897 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3898 EXPECT_EQ(8000, option_val);
3899 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3900 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3901
3902 EXPECT_NE(session_->voice_channel()->transport_channel(),
3903 session_->video_channel()->transport_channel());
3904
3905 mediastream_signaling_.SendAudioVideoStream2();
3906 SessionDescriptionInterface* answer =
3907 CreateRemoteAnswer(session_->local_description());
3908 SetRemoteDescriptionWithoutError(answer);
3909
3910 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3911 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3912 EXPECT_EQ(4000, option_val);
3913
3914 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3915 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3916 EXPECT_EQ(8000, option_val);
3917}
3918
tommi0f620f42015-07-09 03:25:02 -07003919// Test creating a session, request multiple offers, destroy the session
3920// and make sure we got success/failure callbacks for all of the requests.
3921// Background: crbug.com/507307
3922TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3923 Init();
3924
3925 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3926 PeerConnectionInterface::RTCOfferAnswerOptions options;
3927 options.offer_to_receive_audio =
3928 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3929
3930 for (auto& o : observers) {
3931 o = new WebRtcSessionCreateSDPObserverForTest();
3932 session_->CreateOffer(o, options);
3933 }
3934
3935 session_.reset();
3936
3937 // Make sure we process pending messages on the current (signaling) thread
3938 // before checking we we got our callbacks. Quit() will do this and then
3939 // immediately exit. We won't need the queue after this point anyway.
3940 rtc::Thread::Current()->Quit();
3941
3942 for (auto& o : observers) {
3943 // We expect to have received a notification now even if the session was
3944 // terminated. The offer creation may or may not have succeeded, but we
3945 // must have received a notification which, so the only invalid state
3946 // is kInit.
3947 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3948 }
3949}
3950
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003951// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3952// currently fails because upon disconnection and reconnection OnIceComplete is
3953// called more than once without returning to IceGatheringGathering.