blob: 06e10b0cbb27c2ad08981f7bd2a5a6ba35d177e2 [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());
543 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000544 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
546 }
547
548 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
549 bool expected) {
550 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
551 ASSERT_TRUE(audio != NULL);
552 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 const TransportInfo* video = sdp->GetTransportInfoByName("video");
554 ASSERT_TRUE(video != NULL);
555 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 }
557
558 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000559 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000561 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000562 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000564 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000566 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
567 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000568 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 // Answer should be NULL as no crypto params in offer.
570 ASSERT_TRUE(answer == NULL);
571 }
572
573 void VerifyAnswerFromCryptoOffer() {
574 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000575 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 options.bundle_enabled = true;
577 scoped_ptr<JsepSessionDescription> offer(
578 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
579 ASSERT_TRUE(offer.get() != NULL);
580 VerifyCryptoParams(offer->description());
581 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000582 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 ASSERT_TRUE(answer.get() != NULL);
584 VerifyCryptoParams(answer->description());
585 }
586
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000587 void SetAndVerifyNumUnsignalledRecvStreams(
588 int value_set, int value_expected) {
589 constraints_.reset(new FakeConstraints());
590 constraints_->AddOptional(
591 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
592 value_set);
593 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000594 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000595 mediastream_signaling_.SendAudioVideoStream1();
596 SessionDescriptionInterface* offer = CreateOffer();
597
598 SetLocalDescriptionWithoutError(offer);
599
600 video_channel_ = media_engine_->GetVideoChannel(0);
601
602 ASSERT_TRUE(video_channel_ != NULL);
603 cricket::VideoOptions video_options;
604 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
605 EXPECT_EQ(value_expected,
606 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
607 }
608
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
610 const cricket::SessionDescription* desc2,
611 bool expect_equal) {
612 if (desc1->contents().size() != desc2->contents().size()) {
613 EXPECT_FALSE(expect_equal);
614 return;
615 }
616
617 const cricket::ContentInfos& contents = desc1->contents();
618 cricket::ContentInfos::const_iterator it = contents.begin();
619
620 for (; it != contents.end(); ++it) {
621 const cricket::TransportDescription* transport_desc1 =
622 desc1->GetTransportDescriptionByName(it->name);
623 const cricket::TransportDescription* transport_desc2 =
624 desc2->GetTransportDescriptionByName(it->name);
625 if (!transport_desc1 || !transport_desc2) {
626 EXPECT_FALSE(expect_equal);
627 return;
628 }
629 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
630 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
631 EXPECT_FALSE(expect_equal);
632 return;
633 }
634 }
635 EXPECT_TRUE(expect_equal);
636 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000637
638 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
639 std::string *sdp) {
640 const cricket::SessionDescription* desc = current_desc->description();
641 EXPECT_TRUE(current_desc->ToString(sdp));
642
643 const cricket::ContentInfos& contents = desc->contents();
644 cricket::ContentInfos::const_iterator it = contents.begin();
645 // Replace ufrag and pwd lines with empty strings.
646 for (; it != contents.end(); ++it) {
647 const cricket::TransportDescription* transport_desc =
648 desc->GetTransportDescriptionByName(it->name);
649 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
650 + "\r\n";
651 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
652 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000653 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000654 "", 0,
655 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000656 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000657 "", 0,
658 sdp);
659 }
660 }
661
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000662 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
663 const std::string& modified_ice_ufrag,
664 const std::string& modified_ice_pwd,
665 std::string* sdp) {
666 const cricket::SessionDescription* desc = current_desc->description();
667 EXPECT_TRUE(current_desc->ToString(sdp));
668
669 const cricket::ContentInfos& contents = desc->contents();
670 cricket::ContentInfos::const_iterator it = contents.begin();
671 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
672 // |modified_ice_pwd| strings.
673 for (; it != contents.end(); ++it) {
674 const cricket::TransportDescription* transport_desc =
675 desc->GetTransportDescriptionByName(it->name);
676 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
677 + "\r\n";
678 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
679 + "\r\n";
680 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
681 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000682 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000683 mod_ufrag.c_str(), mod_ufrag.length(),
684 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000685 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000686 mod_pwd.c_str(), mod_pwd.length(),
687 sdp);
688 }
689 }
690
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 // Creates a remote offer and and applies it as a remote description,
692 // creates a local answer and applies is as a local description.
693 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
694 // to decide which local and remote streams to create.
695 void CreateAndSetRemoteOfferAndLocalAnswer() {
696 SessionDescriptionInterface* offer = CreateRemoteOffer();
697 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000698 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 SetLocalDescriptionWithoutError(answer);
700 }
701 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
702 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
703 }
704 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
705 BaseSession::State expected_state) {
706 SetLocalDescriptionWithoutError(desc);
707 EXPECT_EQ(expected_state, session_->state());
708 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000709 void SetLocalDescriptionExpectError(const std::string& action,
710 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 SessionDescriptionInterface* desc) {
712 std::string error;
713 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000714 std::string sdp_type = "local ";
715 sdp_type.append(action);
716 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 EXPECT_NE(std::string::npos, error.find(expected_error));
718 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000719 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
720 SessionDescriptionInterface* desc) {
721 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
722 expected_error, desc);
723 }
724 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
725 SessionDescriptionInterface* desc) {
726 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
727 expected_error, desc);
728 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
730 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
731 }
732 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
733 BaseSession::State expected_state) {
734 SetRemoteDescriptionWithoutError(desc);
735 EXPECT_EQ(expected_state, session_->state());
736 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 void SetRemoteDescriptionExpectError(const std::string& action,
738 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 SessionDescriptionInterface* desc) {
740 std::string error;
741 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 std::string sdp_type = "remote ";
743 sdp_type.append(action);
744 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 EXPECT_NE(std::string::npos, error.find(expected_error));
746 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000747 void SetRemoteDescriptionOfferExpectError(
748 const std::string& expected_error, SessionDescriptionInterface* desc) {
749 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
750 expected_error, desc);
751 }
752 void SetRemoteDescriptionPranswerExpectError(
753 const std::string& expected_error, SessionDescriptionInterface* desc) {
754 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
755 expected_error, desc);
756 }
757 void SetRemoteDescriptionAnswerExpectError(
758 const std::string& expected_error, SessionDescriptionInterface* desc) {
759 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
760 expected_error, desc);
761 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
764 SessionDescriptionInterface** nocrypto_answer) {
765 // Create a SDP without Crypto.
766 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000767 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 options.bundle_enabled = true;
769 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
770 ASSERT_TRUE(*offer != NULL);
771 VerifyCryptoParams((*offer)->description());
772
773 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
774 cricket::SEC_DISABLED);
775 EXPECT_TRUE(*nocrypto_answer != NULL);
776 }
777
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000778 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
779 SessionDescriptionInterface** nodtls_answer) {
780 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000781 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000782 options.bundle_enabled = true;
783
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000784 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000785 CreateRemoteOffer(options, cricket::SEC_ENABLED));
786
787 *nodtls_answer =
788 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
789 EXPECT_TRUE(*nodtls_answer != NULL);
790 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
791 VerifyCryptoParams((*nodtls_answer)->description());
792
793 SetFactoryDtlsSrtp();
794 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
795 ASSERT_TRUE(*offer != NULL);
796 VerifyFingerprintStatus((*offer)->description(), true);
797 VerifyCryptoParams((*offer)->description());
798 }
799
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 JsepSessionDescription* CreateRemoteOfferWithVersion(
801 cricket::MediaSessionOptions options,
802 cricket::SecurePolicy secure_policy,
803 const std::string& session_version,
804 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000805 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 const cricket::SessionDescription* cricket_desc = NULL;
807 if (current_desc) {
808 cricket_desc = current_desc->description();
809 session_id = current_desc->session_id();
810 }
811
812 desc_factory_->set_secure(secure_policy);
813 JsepSessionDescription* offer(
814 new JsepSessionDescription(JsepSessionDescription::kOffer));
815 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
816 session_id, session_version)) {
817 delete offer;
818 offer = NULL;
819 }
820 return offer;
821 }
822 JsepSessionDescription* CreateRemoteOffer(
823 cricket::MediaSessionOptions options) {
824 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
825 kSessionVersion, NULL);
826 }
827 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000828 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
829 return CreateRemoteOfferWithVersion(
830 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 }
832 JsepSessionDescription* CreateRemoteOffer(
833 cricket::MediaSessionOptions options,
834 const SessionDescriptionInterface* current_desc) {
835 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
836 kSessionVersion, current_desc);
837 }
838
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000839 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
840 const char* sctp_stream_name, int new_port,
841 cricket::MediaSessionOptions options) {
842 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000843 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
844 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000845 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
846 }
847
848 // Takes ownership of offer_basis (and deletes it).
849 JsepSessionDescription* ChangeSDPSctpPort(
850 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
851 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
852 // SessionDescription from the mutated string.
853 const char* default_port_str = "5000";
854 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000855 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000856 std::string offer_str;
857 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000858 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000859 new_port_str, strlen(new_port_str),
860 &offer_str);
861 JsepSessionDescription* offer = new JsepSessionDescription(
862 offer_basis->type());
863 delete offer_basis;
864 offer->Initialize(offer_str, NULL);
865 return offer;
866 }
867
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
869 // before this function to decide which streams to create.
870 JsepSessionDescription* CreateRemoteOffer() {
871 cricket::MediaSessionOptions options;
872 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
873 return CreateRemoteOffer(options, session_->remote_description());
874 }
875
876 JsepSessionDescription* CreateRemoteAnswer(
877 const SessionDescriptionInterface* offer,
878 cricket::MediaSessionOptions options,
879 cricket::SecurePolicy policy) {
880 desc_factory_->set_secure(policy);
881 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000882 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 JsepSessionDescription* answer(
884 new JsepSessionDescription(JsepSessionDescription::kAnswer));
885 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
886 options, NULL),
887 session_id, kSessionVersion)) {
888 delete answer;
889 answer = NULL;
890 }
891 return answer;
892 }
893
894 JsepSessionDescription* CreateRemoteAnswer(
895 const SessionDescriptionInterface* offer,
896 cricket::MediaSessionOptions options) {
897 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
898 }
899
900 // Creates an answer session description with streams based on
901 // |mediastream_signaling_|. Call
902 // mediastream_signaling_.UseOptionsWithStreamX() before this function
903 // to decide which streams to create.
904 JsepSessionDescription* CreateRemoteAnswer(
905 const SessionDescriptionInterface* offer) {
906 cricket::MediaSessionOptions options;
907 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
908 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
909 }
910
911 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000912 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000913 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000915
916 PeerConnectionInterface::RTCOfferAnswerOptions options;
917 options.use_rtp_mux = bundle;
918
919 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
921 // and answer.
922 SetLocalDescriptionWithoutError(offer);
923
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000924 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000925 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 std::string sdp;
927 EXPECT_TRUE(answer->ToString(&sdp));
928
929 size_t expected_candidate_num = 2;
930 if (!rtcp_mux) {
931 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
932 // for rtp and rtcp.
933 expected_candidate_num = 4;
934 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 const std::string kRtcpMux = "a=rtcp-mux";
936 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000937 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 kXRtcpMux.c_str(), kXRtcpMux.length(),
939 &sdp);
940 }
941
942 SessionDescriptionInterface* new_answer = CreateSessionDescription(
943 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944
945 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000946 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
948 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
949 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
950 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
951 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
952 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
953 if (bundle) {
954 EXPECT_TRUE(c0.IsEquivalent(c1));
955 } else {
956 EXPECT_FALSE(c0.IsEquivalent(c1));
957 }
958 }
959 }
960 // Tests that we can only send DTMF when the dtmf codec is supported.
961 void TestCanInsertDtmf(bool can) {
962 if (can) {
963 InitWithDtmfCodec();
964 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000965 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 }
967 mediastream_signaling_.SendAudioVideoStream1();
968 CreateAndSetRemoteOfferAndLocalAnswer();
969 EXPECT_FALSE(session_->CanInsertDtmf(""));
970 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
971 }
972
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000973 // Helper class to configure loopback network and verify Best
974 // Connection using right IP protocol for TestLoopbackCall
975 // method. LoopbackNetworkManager applies firewall rules to block
976 // all ping traffic once ICE completed, and remove them to observe
977 // ICE reconnected again. This LoopbackNetworkConfiguration struct
978 // verifies the best connection is using the right IP protocol after
979 // initial ICE convergences.
980
981 class LoopbackNetworkConfiguration {
982 public:
983 LoopbackNetworkConfiguration()
984 : test_ipv6_network_(false),
985 test_extra_ipv4_network_(false),
986 best_connection_after_initial_ice_converged_(1, 0) {}
987
988 // Used to track the expected best connection count in each IP protocol.
989 struct ExpectedBestConnection {
990 ExpectedBestConnection(int ipv4_count, int ipv6_count)
991 : ipv4_count_(ipv4_count),
992 ipv6_count_(ipv6_count) {}
993
994 int ipv4_count_;
995 int ipv6_count_;
996 };
997
998 bool test_ipv6_network_;
999 bool test_extra_ipv4_network_;
1000 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1001
1002 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001003 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001004 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1005 }
1006
1007 private:
jbauchac8869e2015-07-03 01:36:14 -07001008 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001009 const ExpectedBestConnection& expected) const {
1010 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001011 metrics_observer->GetCounter(webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001012 expected.ipv4_count_);
1013 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001014 metrics_observer->GetCounter(webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001015 expected.ipv6_count_);
1016 }
1017 };
1018
1019 class LoopbackNetworkManager {
1020 public:
1021 LoopbackNetworkManager(WebRtcSessionTest* session,
1022 const LoopbackNetworkConfiguration& config)
1023 : config_(config) {
1024 session->AddInterface(
1025 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1026 if (config_.test_extra_ipv4_network_) {
1027 session->AddInterface(
1028 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1029 }
1030 if (config_.test_ipv6_network_) {
1031 session->AddInterface(
1032 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1033 }
1034 }
1035
1036 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1037 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1038 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1039 if (config_.test_extra_ipv4_network_) {
1040 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1041 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1042 }
1043 if (config_.test_ipv6_network_) {
1044 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1045 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1046 }
1047 }
1048
1049 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1050
1051 private:
1052 LoopbackNetworkConfiguration config_;
1053 };
1054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 // The method sets up a call from the session to itself, in a loopback
1056 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001057 // disconnection, and then a permanent disconnection.
1058 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1060 // While running the call, this method also checks if the session goes through
1061 // the correct sequence of ICE states when a connection is established,
1062 // broken, and re-established.
1063 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001064 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1065 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001067
1068 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1069 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001070 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001072 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073
1074 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1075 observer_.ice_gathering_state_);
1076 SetLocalDescriptionWithoutError(offer);
1077 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1078 observer_.ice_connection_state_);
1079 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1080 observer_.ice_gathering_state_,
1081 kIceCandidatesTimeout);
1082 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1083 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1084 observer_.ice_gathering_state_,
1085 kIceCandidatesTimeout);
1086
1087 std::string sdp;
1088 offer->ToString(&sdp);
1089 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001090 webrtc::CreateSessionDescription(
1091 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 ASSERT_TRUE(desc != NULL);
1093 SetRemoteDescriptionWithoutError(desc);
1094
1095 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1096 observer_.ice_connection_state_,
1097 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001098
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001099 // The ice connection state is "Connected" too briefly to catch in a test.
1100 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 observer_.ice_connection_state_,
1102 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001104 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 // Adding firewall rule to block ping requests, which should cause
1106 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001107
1108 loopback_network_manager.ApplyFirewallRules(fss_.get());
1109
1110 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1112 observer_.ice_connection_state_,
1113 kIceCandidatesTimeout);
1114
jbauchac8869e2015-07-03 01:36:14 -07001115 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001116
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001118 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 // Session is automatically calling OnSignalingReady after creation of
1120 // new portallocator session which will allocate new set of candidates.
1121
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001122 LOG(LS_INFO) << "Firewall Rules cleared";
1123
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001124 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 observer_.ice_connection_state_,
1126 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001127
1128 // Now we block ping requests and wait until the ICE connection transitions
1129 // to the Failed state. This will take at least 30 seconds because it must
1130 // wait for the Port to timeout.
1131 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132
1133 loopback_network_manager.ApplyFirewallRules(fss_.get());
1134 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001135 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001136 observer_.ice_connection_state_,
1137 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 }
1139
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001140 void TestLoopbackCall() {
1141 LoopbackNetworkConfiguration config;
1142 TestLoopbackCall(config);
1143 }
1144
pthatcherfa301802015-08-11 04:12:56 -07001145 void VerifyTransportType(const std::string& content_name,
1146 cricket::TransportProtocol protocol) {
1147 const cricket::Transport* transport = session_->GetTransport(content_name);
1148 ASSERT_TRUE(transport != NULL);
1149 EXPECT_EQ(protocol, transport->protocol());
1150 }
1151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1153 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001154 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1155 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1156
1157 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1159 codecs.push_back(kCNCodec1);
1160 codecs.push_back(kCNCodec2);
1161 media_engine_->SetAudioCodecs(codecs);
1162 desc_factory_->set_audio_codecs(codecs);
1163 }
1164
1165 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1166 const cricket::ContentDescription* description = content->description;
1167 ASSERT(description != NULL);
1168 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001169 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 ASSERT(audio_content_desc != NULL);
1171 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1172 if (audio_content_desc->codecs()[i].name == "CN")
1173 return false;
1174 }
1175 return true;
1176 }
1177
1178 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001179 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 dci.reliable = false;
1181 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001182 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 SetLocalDescriptionWithoutError(offer);
1184 }
1185
wu@webrtc.org91053e72013-08-10 07:18:04 +00001186 void VerifyMultipleAsyncCreateDescription(
1187 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001188 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001189 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001190 if (type == CreateSessionDescriptionRequest::kAnswer) {
1191 cricket::MediaSessionOptions options;
1192 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001193 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001194 ASSERT_TRUE(offer.get() != NULL);
1195 SetRemoteDescriptionWithoutError(offer.release());
1196 }
1197
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001198 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001199 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001200 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001201 observers[kNumber];
1202 for (int i = 0; i < kNumber; ++i) {
1203 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1204 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001205 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001206 } else {
1207 session_->CreateAnswer(observers[i], NULL);
1208 }
1209 }
1210
1211 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1212 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1213 WebRtcSessionCreateSDPObserverForTest::kFailed;
1214
1215 for (int i = 0; i < kNumber; ++i) {
1216 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1217 if (success) {
1218 EXPECT_TRUE(observers[i]->description() != NULL);
1219 } else {
1220 EXPECT_TRUE(observers[i]->description() == NULL);
1221 }
1222 }
1223 }
1224
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001225 void ConfigureAllocatorWithTurn() {
1226 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1227 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1228 relay_server.credentials = credentials;
1229 relay_server.ports.push_back(cricket::ProtocolAddress(
1230 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1231 allocator_->AddRelay(relay_server);
1232 allocator_->set_step_delay(cricket::kMinimumStepDelay);
pthatcherfa301802015-08-11 04:12:56 -07001233 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1234 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001235 }
1236
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 cricket::FakeMediaEngine* media_engine_;
1238 cricket::FakeDataEngine* data_engine_;
1239 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001240 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1241 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1242 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1243 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1244 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1245 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1246 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1247 rtc::SocketServerScope ss_scope_;
1248 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001249 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001250 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001251 rtc::FakeNetworkManager network_manager_;
1252 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001253 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001254 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001256 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 MockIceObserver observer_;
1258 cricket::FakeVideoMediaChannel* video_channel_;
1259 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001260 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261};
1262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1264 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001265 // SDES is disabled when DTLS is on.
1266 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267}
1268
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001269TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001270 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001271 // SDES is required if DTLS is off.
1272 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001273}
1274
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1276 TestSessionCandidatesWithBundleRtcpMux(false, false);
1277}
1278
1279// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1280// with rtcp-mux and/or bundle.
1281TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1282 TestSessionCandidatesWithBundleRtcpMux(false, true);
1283}
1284
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1286 TestSessionCandidatesWithBundleRtcpMux(true, true);
1287}
1288
1289TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001290 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1291 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001292 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 mediastream_signaling_.SendAudioVideoStream1();
1294 InitiateCall();
1295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1296 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1297 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1298}
1299
1300TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001301 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1302 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001303 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001304 rtc::FP_UDP,
1305 rtc::FD_ANY,
1306 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001307 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 mediastream_signaling_.SendAudioVideoStream1();
1309 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001310 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1312 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1313 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1314}
1315
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001316// Test session delivers no candidates gathered when constraint set to "none".
1317TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1318 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001319 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001320 mediastream_signaling_.SendAudioVideoStream1();
1321 InitiateCall();
1322 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1323 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1324 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1325}
1326
1327// Test session delivers only relay candidates gathered when constaint set to
1328// "relay".
1329TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1330 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1331 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001332 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001333 mediastream_signaling_.SendAudioVideoStream1();
1334 InitiateCall();
1335 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1336 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1337 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1338 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1339 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1340 observer_.mline_0_candidates_[i].type());
1341 }
1342 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1343 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1344 observer_.mline_1_candidates_[i].type());
1345 }
1346}
1347
1348// Test session delivers all candidates gathered when constaint set to "all".
1349TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1350 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001351 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001352 mediastream_signaling_.SendAudioVideoStream1();
1353 InitiateCall();
1354 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1355 // Host + STUN. By default allocator is disabled to gather relay candidates.
1356 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1357 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1358}
1359
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001360TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001361 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001362 SessionDescriptionInterface* offer = NULL;
1363 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1364 std::string unknown_action;
1365 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1366 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1367}
1368
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369// Test creating offers and receive answers and make sure the
1370// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001371TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001372 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001374 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 const std::string session_id_orig = offer->session_id();
1376 const std::string session_version_orig = offer->session_version();
1377 SetLocalDescriptionWithoutError(offer);
1378
1379 mediastream_signaling_.SendAudioVideoStream2();
1380 SessionDescriptionInterface* answer =
1381 CreateRemoteAnswer(session_->local_description());
1382 SetRemoteDescriptionWithoutError(answer);
1383
1384 video_channel_ = media_engine_->GetVideoChannel(0);
1385 voice_channel_ = media_engine_->GetVoiceChannel(0);
1386
1387 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1388 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1389
1390 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1391 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1392
1393 ASSERT_EQ(1u, video_channel_->send_streams().size());
1394 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1395 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1396 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1397
1398 // Create new offer without send streams.
1399 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001400 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401
1402 // Verify the session id is the same and the session version is
1403 // increased.
1404 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001405 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1406 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407
1408 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001409 EXPECT_EQ(0u, video_channel_->send_streams().size());
1410 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411
1412 mediastream_signaling_.SendAudioVideoStream2();
1413 answer = CreateRemoteAnswer(session_->local_description());
1414 SetRemoteDescriptionWithoutError(answer);
1415
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 // Make sure the receive streams have not changed.
1417 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1418 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1419 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1420 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1421}
1422
1423// Test receiving offers and creating answers and make sure the
1424// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001425TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001426 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001428 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001429 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 SetRemoteDescriptionWithoutError(offer);
1431
1432 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001433 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001434 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 SetLocalDescriptionWithoutError(answer);
1436
1437 const std::string session_id_orig = answer->session_id();
1438 const std::string session_version_orig = answer->session_version();
1439
1440 video_channel_ = media_engine_->GetVideoChannel(0);
1441 voice_channel_ = media_engine_->GetVoiceChannel(0);
1442
1443 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1444 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1445
1446 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1447 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1448
1449 ASSERT_EQ(1u, video_channel_->send_streams().size());
1450 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1451 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1452 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1453
1454 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001455 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 SetRemoteDescriptionWithoutError(offer);
1457
1458 // Answer by turning off all send streams.
1459 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001460 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461
1462 // Verify the session id is the same and the session version is
1463 // increased.
1464 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001465 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1466 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 SetLocalDescriptionWithoutError(answer);
1468
1469 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1470 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1471 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1472 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1473 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1474 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1475
1476 // Make sure we have no send streams.
1477 EXPECT_EQ(0u, video_channel_->send_streams().size());
1478 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1479}
1480
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001481TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001483 media_engine_->set_fail_create_channel(true);
1484
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001485 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001486 ASSERT_TRUE(offer != NULL);
1487 // SetRemoteDescription and SetLocalDescription will take the ownership of
1488 // the offer.
1489 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001490 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001491 ASSERT_TRUE(offer != NULL);
1492 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1493}
1494
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001495//
1496// Tests for creating/setting SDP under different SDES/DTLS polices:
1497//
1498// --DTLS off and SDES on
1499// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1500// set local/remote offer/answer with crypto --> success
1501// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1502// failure
1503// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1504// failure
1505// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1506// failure
1507//
1508// --DTLS on and SDES off
1509// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1510// set local/remote offer/answer with DTLS fingerprint --> success
1511// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1512// fingerprint --> failure
1513// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1514// --> failure
1515// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1516// --> failure
1517//
1518// --Encryption disabled: DTLS off and SDES off
1519// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1520// answer without SDES or DTLS --> success
1521// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1522// answer without SDES or DTLS --> success
1523//
1524
1525// Test that we return a failure when applying a remote/local offer that doesn't
1526// have cryptos enabled when DTLS is off.
1527TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001528 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001530 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 JsepSessionDescription* offer = CreateRemoteOffer(
1532 options, cricket::SEC_DISABLED);
1533 ASSERT_TRUE(offer != NULL);
1534 VerifyNoCryptoParams(offer->description(), false);
1535 // SetRemoteDescription and SetLocalDescription will take the ownership of
1536 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001537 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1539 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541}
1542
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001543// Test that we return a failure when applying a local answer that doesn't have
1544// cryptos enabled when DTLS is off.
1545TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001546 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 SessionDescriptionInterface* offer = NULL;
1548 SessionDescriptionInterface* answer = NULL;
1549 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1550 // SetRemoteDescription and SetLocalDescription will take the ownership of
1551 // the offer.
1552 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554}
1555
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001556// Test we will return fail when apply an remote answer that doesn't have
1557// crypto enabled when DTLS is off.
1558TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001559 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 SessionDescriptionInterface* offer = NULL;
1561 SessionDescriptionInterface* answer = NULL;
1562 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1563 // SetRemoteDescription and SetLocalDescription will take the ownership of
1564 // the offer.
1565 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001566 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567}
1568
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001569// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1570// and that we return an answer with a DTLS fingerprint.
1571TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001572 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 InitWithDtls();
1575 SetFactoryDtlsSrtp();
1576 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001577 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001578 JsepSessionDescription* offer =
1579 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 ASSERT_TRUE(offer != NULL);
1581 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583
1584 // SetRemoteDescription will take the ownership of the offer.
1585 SetRemoteDescriptionWithoutError(offer);
1586
1587 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001588 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 ASSERT_TRUE(answer != NULL);
1590 VerifyFingerprintStatus(answer->description(), true);
1591 // Check that we don't have an a=crypto line in the answer.
1592 VerifyNoCryptoParams(answer->description(), true);
1593
1594 // Now set the local description, which should work, even without a=crypto.
1595 SetLocalDescriptionWithoutError(answer);
1596}
1597
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1599// and then we accept a remote answer with a DTLS fingerprint successfully.
1600TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001601 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001602 mediastream_signaling_.SendAudioVideoStream1();
1603 InitWithDtls();
1604 SetFactoryDtlsSrtp();
1605
1606 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001607 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001608 ASSERT_TRUE(offer != NULL);
1609 VerifyFingerprintStatus(offer->description(), true);
1610 // Check that we don't have an a=crypto line in the offer.
1611 VerifyNoCryptoParams(offer->description(), true);
1612
1613 // Now set the local description, which should work, even without a=crypto.
1614 SetLocalDescriptionWithoutError(offer);
1615
1616 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001617 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001618 JsepSessionDescription* answer =
1619 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1620 ASSERT_TRUE(answer != NULL);
1621 VerifyFingerprintStatus(answer->description(), true);
1622 VerifyNoCryptoParams(answer->description(), true);
1623
1624 // SetRemoteDescription will take the ownership of the answer.
1625 SetRemoteDescriptionWithoutError(answer);
1626}
1627
1628// Test that if we support DTLS and the other side didn't offer a fingerprint,
1629// we will fail to set the remote description.
1630TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001631 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 InitWithDtls();
1633 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001634 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001635 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 JsepSessionDescription* offer = CreateRemoteOffer(
1637 options, cricket::SEC_REQUIRED);
1638 ASSERT_TRUE(offer != NULL);
1639 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001640 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001642 // SetRemoteDescription will take the ownership of the offer.
1643 SetRemoteDescriptionOfferExpectError(
1644 kSdpWithoutDtlsFingerprint, offer);
1645
1646 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1647 // SetLocalDescription will take the ownership of the offer.
1648 SetLocalDescriptionOfferExpectError(
1649 kSdpWithoutDtlsFingerprint, offer);
1650}
1651
1652// Test that we return a failure when applying a local answer that doesn't have
1653// a DTLS fingerprint when DTLS is required.
1654TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001655 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001656 InitWithDtls();
1657 SessionDescriptionInterface* offer = NULL;
1658 SessionDescriptionInterface* answer = NULL;
1659 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1660
1661 // SetRemoteDescription and SetLocalDescription will take the ownership of
1662 // the offer and answer.
1663 SetRemoteDescriptionWithoutError(offer);
1664 SetLocalDescriptionAnswerExpectError(
1665 kSdpWithoutDtlsFingerprint, answer);
1666}
1667
1668// Test that we return a failure when applying a remote answer that doesn't have
1669// a DTLS fingerprint when DTLS is required.
1670TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001671 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001672 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1673 // result of using the "UDP/TLS/RTP/SAVPF" profile.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 InitWithDtls();
deadbeeff3938292015-07-15 12:20:53 -07001675 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001676 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001677 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001678 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001679 JsepSessionDescription* answer =
1680 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1681
1682 // SetRemoteDescription and SetLocalDescription will take the ownership of
1683 // the offer and answer.
1684 SetLocalDescriptionWithoutError(offer);
1685 SetRemoteDescriptionAnswerExpectError(
1686 kSdpWithoutDtlsFingerprint, answer);
1687}
1688
1689// Test that we create a local offer without SDES or DTLS and accept a remote
1690// answer without SDES or DTLS when encryption is disabled.
1691TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1692 mediastream_signaling_.SendAudioVideoStream1();
1693 options_.disable_encryption = true;
1694 InitWithDtls();
1695
1696 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001697 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001698 ASSERT_TRUE(offer != NULL);
1699 VerifyFingerprintStatus(offer->description(), false);
1700 // Check that we don't have an a=crypto line in the offer.
1701 VerifyNoCryptoParams(offer->description(), false);
1702
1703 // Now set the local description, which should work, even without a=crypto.
1704 SetLocalDescriptionWithoutError(offer);
1705
1706 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001707 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 JsepSessionDescription* answer =
1709 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1710 ASSERT_TRUE(answer != NULL);
1711 VerifyFingerprintStatus(answer->description(), false);
1712 VerifyNoCryptoParams(answer->description(), false);
1713
1714 // SetRemoteDescription will take the ownership of the answer.
1715 SetRemoteDescriptionWithoutError(answer);
1716}
1717
1718// Test that we create a local answer without SDES or DTLS and accept a remote
1719// offer without SDES or DTLS when encryption is disabled.
1720TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1721 options_.disable_encryption = true;
1722 InitWithDtls();
1723
1724 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001725 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001726 JsepSessionDescription* offer =
1727 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1728 ASSERT_TRUE(offer != NULL);
1729 VerifyFingerprintStatus(offer->description(), false);
1730 VerifyNoCryptoParams(offer->description(), false);
1731
1732 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 SetRemoteDescriptionWithoutError(offer);
1734
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001736 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 ASSERT_TRUE(answer != NULL);
1738 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001739 // Check that we don't have an a=crypto line in the answer.
1740 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 SetLocalDescriptionWithoutError(answer);
1744}
1745
1746TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 mediastream_signaling_.SendNothing();
1749 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001750 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 SetLocalDescriptionWithoutError(offer);
1752
1753 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001754 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 SetLocalDescriptionWithoutError(offer2);
1756}
1757
1758TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001759 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 mediastream_signaling_.SendNothing();
1761 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001762 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 SetRemoteDescriptionWithoutError(offer);
1764
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001765 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 SetRemoteDescriptionWithoutError(offer2);
1767}
1768
1769TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001770 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001772 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001774 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001775 SetRemoteDescriptionOfferExpectError(
1776 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777}
1778
1779TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001782 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001784 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001785 SetLocalDescriptionOfferExpectError(
1786 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
1789TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001790 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 mediastream_signaling_.SendNothing();
1792 SessionDescriptionInterface* offer = CreateRemoteOffer();
1793 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1794
1795 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001796 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1798 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1799
1800 mediastream_signaling_.SendAudioVideoStream1();
1801 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001802 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1804
1805 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1806
1807 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001808 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1810}
1811
1812TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001813 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001815 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1817
1818 JsepSessionDescription* pranswer =
1819 CreateRemoteAnswer(session_->local_description());
1820 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1821
1822 SetRemoteDescriptionExpectState(pranswer,
1823 BaseSession::STATE_RECEIVEDPRACCEPT);
1824
1825 mediastream_signaling_.SendAudioVideoStream1();
1826 JsepSessionDescription* pranswer2 =
1827 CreateRemoteAnswer(session_->local_description());
1828 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1829
1830 SetRemoteDescriptionExpectState(pranswer2,
1831 BaseSession::STATE_RECEIVEDPRACCEPT);
1832
1833 mediastream_signaling_.SendAudioVideoStream2();
1834 SessionDescriptionInterface* answer =
1835 CreateRemoteAnswer(session_->local_description());
1836 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1837}
1838
1839TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001840 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001842 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1843
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 SessionDescriptionInterface* answer =
1845 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001846 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1847 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848}
1849
1850TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001851 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001853 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1854
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 SessionDescriptionInterface* answer =
1856 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001857 SetRemoteDescriptionAnswerExpectError(
1858 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859}
1860
1861TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001862 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 mediastream_signaling_.SendAudioVideoStream1();
1864
1865 cricket::Candidate candidate;
1866 candidate.set_component(1);
1867 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1868
1869 // Fail since we have not set a offer description.
1870 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1871
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001872 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 SetLocalDescriptionWithoutError(offer);
1874 // Candidate should be allowed to add before remote description.
1875 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1876 candidate.set_component(2);
1877 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1878 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1879
1880 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1881 session_->local_description());
1882 SetRemoteDescriptionWithoutError(answer);
1883
1884 // Verifying the candidates are copied properly from internal vector.
1885 const SessionDescriptionInterface* remote_desc =
1886 session_->remote_description();
1887 ASSERT_TRUE(remote_desc != NULL);
1888 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1889 const IceCandidateCollection* candidates =
1890 remote_desc->candidates(kMediaContentIndex0);
1891 ASSERT_EQ(2u, candidates->count());
1892 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1893 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1894 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1895 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1896
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001897 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1898 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 candidate.set_component(2);
1900 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1901 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001902 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903
1904 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1905 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1906}
1907
1908// Test that a remote candidate is added to the remote session description and
1909// that it is retained if the remote session description is changed.
1910TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001911 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 cricket::Candidate candidate1;
1913 candidate1.set_component(1);
1914 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1915 candidate1);
1916 mediastream_signaling_.SendAudioVideoStream1();
1917 CreateAndSetRemoteOfferAndLocalAnswer();
1918
1919 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1920 const SessionDescriptionInterface* remote_desc =
1921 session_->remote_description();
1922 ASSERT_TRUE(remote_desc != NULL);
1923 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1924 const IceCandidateCollection* candidates =
1925 remote_desc->candidates(kMediaContentIndex0);
1926 ASSERT_EQ(1u, candidates->count());
1927 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1928
1929 // Update the RemoteSessionDescription with a new session description and
1930 // a candidate and check that the new remote session description contains both
1931 // candidates.
1932 SessionDescriptionInterface* offer = CreateRemoteOffer();
1933 cricket::Candidate candidate2;
1934 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1935 candidate2);
1936 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1937 SetRemoteDescriptionWithoutError(offer);
1938
1939 remote_desc = session_->remote_description();
1940 ASSERT_TRUE(remote_desc != NULL);
1941 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1942 candidates = remote_desc->candidates(kMediaContentIndex0);
1943 ASSERT_EQ(2u, candidates->count());
1944 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1945 // Username and password have be updated with the TransportInfo of the
1946 // SessionDescription, won't be equal to the original one.
1947 candidate2.set_username(candidates->at(0)->candidate().username());
1948 candidate2.set_password(candidates->at(0)->candidate().password());
1949 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1950 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1951 // No need to verify the username and password.
1952 candidate1.set_username(candidates->at(1)->candidate().username());
1953 candidate1.set_password(candidates->at(1)->candidate().password());
1954 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1955
1956 // Test that the candidate is ignored if we can add the same candidate again.
1957 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1958}
1959
1960// Test that local candidates are added to the local session description and
1961// that they are retained if the local session description is changed.
1962TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001963 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001964 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 mediastream_signaling_.SendAudioVideoStream1();
1966 CreateAndSetRemoteOfferAndLocalAnswer();
1967
1968 const SessionDescriptionInterface* local_desc = session_->local_description();
1969 const IceCandidateCollection* candidates =
1970 local_desc->candidates(kMediaContentIndex0);
1971 ASSERT_TRUE(candidates != NULL);
1972 EXPECT_EQ(0u, candidates->count());
1973
1974 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1975
1976 local_desc = session_->local_description();
1977 candidates = local_desc->candidates(kMediaContentIndex0);
1978 ASSERT_TRUE(candidates != NULL);
1979 EXPECT_LT(0u, candidates->count());
1980 candidates = local_desc->candidates(1);
1981 ASSERT_TRUE(candidates != NULL);
1982 EXPECT_LT(0u, candidates->count());
1983
1984 // Update the session descriptions.
1985 mediastream_signaling_.SendAudioVideoStream1();
1986 CreateAndSetRemoteOfferAndLocalAnswer();
1987
1988 local_desc = session_->local_description();
1989 candidates = local_desc->candidates(kMediaContentIndex0);
1990 ASSERT_TRUE(candidates != NULL);
1991 EXPECT_LT(0u, candidates->count());
1992 candidates = local_desc->candidates(1);
1993 ASSERT_TRUE(candidates != NULL);
1994 EXPECT_LT(0u, candidates->count());
1995}
1996
1997// Test that we can set a remote session description with remote candidates.
1998TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001999 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000
2001 cricket::Candidate candidate1;
2002 candidate1.set_component(1);
2003 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2004 candidate1);
2005 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002006 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007
2008 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2009 SetRemoteDescriptionWithoutError(offer);
2010
2011 const SessionDescriptionInterface* remote_desc =
2012 session_->remote_description();
2013 ASSERT_TRUE(remote_desc != NULL);
2014 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2015 const IceCandidateCollection* candidates =
2016 remote_desc->candidates(kMediaContentIndex0);
2017 ASSERT_EQ(1u, candidates->count());
2018 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2019
wu@webrtc.org91053e72013-08-10 07:18:04 +00002020 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SetLocalDescriptionWithoutError(answer);
2022}
2023
2024// Test that offers and answers contains ice candidates when Ice candidates have
2025// been gathered.
2026TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002027 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002028 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 mediastream_signaling_.SendAudioVideoStream1();
2030 // Ice is started but candidates are not provided until SetLocalDescription
2031 // is called.
2032 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2033 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2034 CreateAndSetRemoteOfferAndLocalAnswer();
2035 // Wait until at least one local candidate has been collected.
2036 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2037 kIceCandidatesTimeout);
2038 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2039 kIceCandidatesTimeout);
2040
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002041 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2042
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2044 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2045 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2046 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2047
2048 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2049 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002050 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2052 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2053 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2054 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2055 SetLocalDescriptionWithoutError(answer);
2056}
2057
2058// Verifies TransportProxy and media channels are created with content names
2059// present in the SessionDescription.
2060TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002061 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064
2065 // CreateOffer creates session description with the content names "audio" and
2066 // "video". Goal is to modify these content names and verify transport channel
2067 // proxy in the BaseSession, as proxies are created with the content names
2068 // present in SDP.
2069 std::string sdp;
2070 EXPECT_TRUE(offer->ToString(&sdp));
2071 const std::string kAudioMid = "a=mid:audio";
2072 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2073 const std::string kVideoMid = "a=mid:video";
2074 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2075
2076 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002077 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 kAudioMidReplaceStr.c_str(),
2079 kAudioMidReplaceStr.length(),
2080 &sdp);
2081 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002082 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 kVideoMidReplaceStr.c_str(),
2084 kVideoMidReplaceStr.length(),
2085 &sdp);
2086
2087 SessionDescriptionInterface* modified_offer =
2088 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2089
2090 SetRemoteDescriptionWithoutError(modified_offer);
2091
2092 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002093 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 SetLocalDescriptionWithoutError(answer);
2095
2096 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2097 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2098 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2099 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2100}
2101
2102// Test that an offer contains the correct media content descriptions based on
2103// the send streams when no constraints have been set.
2104TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002105 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002106 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2107
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 ASSERT_TRUE(offer != NULL);
2109 const cricket::ContentInfo* content =
2110 cricket::GetFirstAudioContent(offer->description());
2111 EXPECT_TRUE(content != NULL);
2112 content = cricket::GetFirstVideoContent(offer->description());
2113 EXPECT_TRUE(content == NULL);
2114}
2115
2116// Test that an offer contains the correct media content descriptions based on
2117// the send streams when no constraints have been set.
2118TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002119 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 // Test Audio only offer.
2121 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002122 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 const cricket::ContentInfo* content =
2125 cricket::GetFirstAudioContent(offer->description());
2126 EXPECT_TRUE(content != NULL);
2127 content = cricket::GetFirstVideoContent(offer->description());
2128 EXPECT_TRUE(content == NULL);
2129
2130 // Test Audio / Video offer.
2131 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002132 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 content = cricket::GetFirstAudioContent(offer->description());
2134 EXPECT_TRUE(content != NULL);
2135 content = cricket::GetFirstVideoContent(offer->description());
2136 EXPECT_TRUE(content != NULL);
2137}
2138
2139// Test that an offer contains no media content descriptions if
2140// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2141TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002142 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002143 PeerConnectionInterface::RTCOfferAnswerOptions options;
2144 options.offer_to_receive_audio = 0;
2145 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002147 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002148 CreateOffer(options));
2149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 ASSERT_TRUE(offer != NULL);
2151 const cricket::ContentInfo* content =
2152 cricket::GetFirstAudioContent(offer->description());
2153 EXPECT_TRUE(content == NULL);
2154 content = cricket::GetFirstVideoContent(offer->description());
2155 EXPECT_TRUE(content == NULL);
2156}
2157
2158// Test that an offer contains only audio media content descriptions if
2159// kOfferToReceiveAudio constraints are set to true.
2160TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002161 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002162 PeerConnectionInterface::RTCOfferAnswerOptions options;
2163 options.offer_to_receive_audio =
2164 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2165
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002166 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002167 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168
2169 const cricket::ContentInfo* content =
2170 cricket::GetFirstAudioContent(offer->description());
2171 EXPECT_TRUE(content != NULL);
2172 content = cricket::GetFirstVideoContent(offer->description());
2173 EXPECT_TRUE(content == NULL);
2174}
2175
2176// Test that an offer contains audio and video media content descriptions if
2177// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2178TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002179 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002181 PeerConnectionInterface::RTCOfferAnswerOptions options;
2182 options.offer_to_receive_audio =
2183 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2184 options.offer_to_receive_video =
2185 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2186
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002187 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002188 CreateOffer(options));
2189
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 const cricket::ContentInfo* content =
2191 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002192 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 content = cricket::GetFirstVideoContent(offer->description());
2195 EXPECT_TRUE(content != NULL);
2196
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002197 // Sets constraints to false and verifies that audio/video contents are
2198 // removed.
2199 options.offer_to_receive_audio = 0;
2200 options.offer_to_receive_video = 0;
2201 offer.reset(CreateOffer(options));
2202
2203 content = cricket::GetFirstAudioContent(offer->description());
2204 EXPECT_TRUE(content == NULL);
2205 content = cricket::GetFirstVideoContent(offer->description());
2206 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207}
2208
2209// Test that an answer can not be created if the last remote description is not
2210// an offer.
2211TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002212 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002213 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 SetLocalDescriptionWithoutError(offer);
2215 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2216 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002217 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218}
2219
2220// Test that an answer contains the correct media content descriptions when no
2221// constraints have been set.
2222TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002223 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002225 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002227 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002228 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 const cricket::ContentInfo* content =
2230 cricket::GetFirstAudioContent(answer->description());
2231 ASSERT_TRUE(content != NULL);
2232 EXPECT_FALSE(content->rejected);
2233
2234 content = cricket::GetFirstVideoContent(answer->description());
2235 ASSERT_TRUE(content != NULL);
2236 EXPECT_FALSE(content->rejected);
2237}
2238
2239// Test that an answer contains the correct media content descriptions when no
2240// constraints have been set and the offer only contain audio.
2241TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002242 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 // Create a remote offer with audio only.
2244 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002245
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002246 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 CreateRemoteOffer(options));
2248 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2249 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2250
2251 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002252 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002253 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 const cricket::ContentInfo* content =
2255 cricket::GetFirstAudioContent(answer->description());
2256 ASSERT_TRUE(content != NULL);
2257 EXPECT_FALSE(content->rejected);
2258
2259 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2260}
2261
2262// Test that an answer contains the correct media content descriptions when no
2263// constraints have been set.
2264TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002265 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002267 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 SetRemoteDescriptionWithoutError(offer.release());
2269 // Test with a stream with tracks.
2270 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002271 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002272 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 const cricket::ContentInfo* content =
2274 cricket::GetFirstAudioContent(answer->description());
2275 ASSERT_TRUE(content != NULL);
2276 EXPECT_FALSE(content->rejected);
2277
2278 content = cricket::GetFirstVideoContent(answer->description());
2279 ASSERT_TRUE(content != NULL);
2280 EXPECT_FALSE(content->rejected);
2281}
2282
2283// Test that an answer contains the correct media content descriptions when
2284// constraints have been set but no stream is sent.
2285TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002286 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002288 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 SetRemoteDescriptionWithoutError(offer.release());
2290
2291 webrtc::FakeConstraints constraints_no_receive;
2292 constraints_no_receive.SetMandatoryReceiveAudio(false);
2293 constraints_no_receive.SetMandatoryReceiveVideo(false);
2294
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002295 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002296 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 const cricket::ContentInfo* content =
2298 cricket::GetFirstAudioContent(answer->description());
2299 ASSERT_TRUE(content != NULL);
2300 EXPECT_TRUE(content->rejected);
2301
2302 content = cricket::GetFirstVideoContent(answer->description());
2303 ASSERT_TRUE(content != NULL);
2304 EXPECT_TRUE(content->rejected);
2305}
2306
2307// Test that an answer contains the correct media content descriptions when
2308// constraints have been set and streams are sent.
2309TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002310 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002312 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 SetRemoteDescriptionWithoutError(offer.release());
2314
2315 webrtc::FakeConstraints constraints_no_receive;
2316 constraints_no_receive.SetMandatoryReceiveAudio(false);
2317 constraints_no_receive.SetMandatoryReceiveVideo(false);
2318
2319 // Test with a stream with tracks.
2320 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002321 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002322 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323
2324 // TODO(perkj): Should the direction be set to SEND_ONLY?
2325 const cricket::ContentInfo* content =
2326 cricket::GetFirstAudioContent(answer->description());
2327 ASSERT_TRUE(content != NULL);
2328 EXPECT_FALSE(content->rejected);
2329
2330 // TODO(perkj): Should the direction be set to SEND_ONLY?
2331 content = cricket::GetFirstVideoContent(answer->description());
2332 ASSERT_TRUE(content != NULL);
2333 EXPECT_FALSE(content->rejected);
2334}
2335
2336TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2337 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002338 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002339 PeerConnectionInterface::RTCOfferAnswerOptions options;
2340 options.offer_to_receive_audio =
2341 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2342 options.voice_activity_detection = false;
2343
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002344 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002345 CreateOffer(options));
2346
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 const cricket::ContentInfo* content =
2348 cricket::GetFirstAudioContent(offer->description());
2349 EXPECT_TRUE(content != NULL);
2350 EXPECT_TRUE(VerifyNoCNCodecs(content));
2351}
2352
2353TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2354 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002355 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002357 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 SetRemoteDescriptionWithoutError(offer.release());
2359
2360 webrtc::FakeConstraints constraints;
2361 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002362 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002363 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 const cricket::ContentInfo* content =
2365 cricket::GetFirstAudioContent(answer->description());
2366 ASSERT_TRUE(content != NULL);
2367 EXPECT_TRUE(VerifyNoCNCodecs(content));
2368}
2369
2370// This test verifies the call setup when remote answer with audio only and
2371// later updates with video.
2372TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002373 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2375 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2376
2377 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002378 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2382
2383 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2384 // and answer;
2385 SetLocalDescriptionWithoutError(offer);
2386 SetRemoteDescriptionWithoutError(answer);
2387
2388 video_channel_ = media_engine_->GetVideoChannel(0);
2389 voice_channel_ = media_engine_->GetVoiceChannel(0);
2390
2391 ASSERT_TRUE(video_channel_ == NULL);
2392
2393 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2394 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2395 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2396
2397 // Let the remote end update the session descriptions, with Audio and Video.
2398 mediastream_signaling_.SendAudioVideoStream2();
2399 CreateAndSetRemoteOfferAndLocalAnswer();
2400
2401 video_channel_ = media_engine_->GetVideoChannel(0);
2402 voice_channel_ = media_engine_->GetVoiceChannel(0);
2403
2404 ASSERT_TRUE(video_channel_ != NULL);
2405 ASSERT_TRUE(voice_channel_ != NULL);
2406
2407 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2408 ASSERT_EQ(1u, video_channel_->send_streams().size());
2409 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2410 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2411 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2412 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2413 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2414 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2415
2416 // Change session back to audio only.
2417 mediastream_signaling_.UseOptionsAudioOnly();
2418 CreateAndSetRemoteOfferAndLocalAnswer();
2419
2420 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2421 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2422 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2423 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2424 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2425}
2426
2427// This test verifies the call setup when remote answer with video only and
2428// later updates with audio.
2429TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2432 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2433 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435
2436 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002437 options.recv_audio = false;
2438 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2440 offer, options, cricket::SEC_ENABLED);
2441
2442 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2443 // and answer.
2444 SetLocalDescriptionWithoutError(offer);
2445 SetRemoteDescriptionWithoutError(answer);
2446
2447 video_channel_ = media_engine_->GetVideoChannel(0);
2448 voice_channel_ = media_engine_->GetVoiceChannel(0);
2449
2450 ASSERT_TRUE(voice_channel_ == NULL);
2451 ASSERT_TRUE(video_channel_ != NULL);
2452
2453 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2454 ASSERT_EQ(1u, video_channel_->send_streams().size());
2455 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2456
2457 // Update the session descriptions, with Audio and Video.
2458 mediastream_signaling_.SendAudioVideoStream2();
2459 CreateAndSetRemoteOfferAndLocalAnswer();
2460
2461 voice_channel_ = media_engine_->GetVoiceChannel(0);
2462 ASSERT_TRUE(voice_channel_ != NULL);
2463
2464 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2465 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2466 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2467 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2468
2469 // Change session back to video only.
2470 mediastream_signaling_.UseOptionsVideoOnly();
2471 CreateAndSetRemoteOfferAndLocalAnswer();
2472
2473 video_channel_ = media_engine_->GetVideoChannel(0);
2474 voice_channel_ = media_engine_->GetVoiceChannel(0);
2475
2476 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2477 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2478 ASSERT_EQ(1u, video_channel_->send_streams().size());
2479 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2480}
2481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002483 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002485 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 VerifyCryptoParams(offer->description());
2487 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002488 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 VerifyCryptoParams(answer->description());
2490}
2491
2492TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002493 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002494 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002496 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 VerifyNoCryptoParams(offer->description(), false);
2498}
2499
2500TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002501 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 VerifyAnswerFromNonCryptoOffer();
2503}
2504
2505TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002506 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 VerifyAnswerFromCryptoOffer();
2508}
2509
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002510// This test verifies that setLocalDescription fails if
2511// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2512TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002513 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002514 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002515 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2516
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002517 std::string sdp;
2518 RemoveIceUfragPwdLines(offer.get(), &sdp);
2519 SessionDescriptionInterface* modified_offer =
2520 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002521 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002522}
2523
2524// This test verifies that setRemoteDescription fails if
2525// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2526TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002527 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002528 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002529 std::string sdp;
2530 RemoveIceUfragPwdLines(offer.get(), &sdp);
2531 SessionDescriptionInterface* modified_offer =
2532 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002533 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002534}
2535
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002536// This test verifies that setLocalDescription fails if local offer has
2537// too short ice ufrag and pwd strings.
2538TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002539 Init();
pthatcherfa301802015-08-11 04:12:56 -07002540 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002541 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002542 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2543
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002544 std::string sdp;
2545 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2546 // recommended values of 4 and 22 bytes respectively.
2547 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2548 SessionDescriptionInterface* modified_offer =
2549 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2550 std::string error;
2551 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2552
2553 // Test with string greater than 256.
2554 sdp.clear();
2555 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2556 &sdp);
2557 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2558 NULL);
2559 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2560}
2561
2562// This test verifies that setRemoteDescription fails if remote offer has
2563// too short ice ufrag and pwd strings.
2564TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
pthatcherfa301802015-08-11 04:12:56 -07002566 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002567 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002568 std::string sdp;
2569 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2570 // recommended values of 4 and 22 bytes respectively.
2571 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2572 SessionDescriptionInterface* modified_offer =
2573 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2574 std::string error;
2575 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2576
2577 sdp.clear();
2578 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2579 &sdp);
2580 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2581 NULL);
2582 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2583}
2584
honghaiz503726c2015-07-31 12:37:38 -07002585// Test that if the remote description indicates the peer requested ICE restart
2586// (via a new ufrag or pwd), the old ICE candidates are not copied,
2587// and vice versa.
2588TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2589 Init();
2590 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2591
2592 // Create the first offer.
2593 std::string sdp;
2594 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2595 "abcdefghijklmnopqrstuvwx", &sdp);
2596 SessionDescriptionInterface* offer1 =
2597 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2598 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2599 0, "", "", "relay", 0, "");
2600 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2601 candidate1);
2602 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2603 SetRemoteDescriptionWithoutError(offer1);
2604 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2605
2606 // The second offer has the same ufrag and pwd but different address.
2607 sdp.clear();
2608 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2609 "abcdefghijklmnopqrstuvwx", &sdp);
2610 SessionDescriptionInterface* offer2 =
2611 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2612 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2613 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2614 candidate1);
2615 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2616 SetRemoteDescriptionWithoutError(offer2);
2617 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2618
2619 // The third offer has a different ufrag and different address.
2620 sdp.clear();
2621 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2622 "abcdefghijklmnopqrstuvwx", &sdp);
2623 SessionDescriptionInterface* offer3 =
2624 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2625 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2626 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2627 candidate1);
2628 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2629 SetRemoteDescriptionWithoutError(offer3);
2630 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2631
2632 // The fourth offer has no candidate but a different ufrag/pwd.
2633 sdp.clear();
2634 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2635 "abcdefghijklmnopqrstuvyz", &sdp);
2636 SessionDescriptionInterface* offer4 =
2637 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2638 SetRemoteDescriptionWithoutError(offer4);
2639 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2640}
2641
Donald Curtisd4f769d2015-05-28 09:48:21 -07002642// Test that candidates sent to the "video" transport do not get pushed down to
2643// the "audio" transport channel when bundling using TransportProxy.
2644TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2645 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2646
2647 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2648 mediastream_signaling_.SendAudioVideoStream1();
2649
2650 PeerConnectionInterface::RTCOfferAnswerOptions options;
2651 options.use_rtp_mux = true;
2652
2653 SessionDescriptionInterface* offer = CreateRemoteOffer();
2654 SetRemoteDescriptionWithoutError(offer);
2655
2656 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2657 SetLocalDescriptionWithoutError(answer);
2658
2659 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2660 session_->GetTransportProxy("video")->impl());
2661
2662 cricket::Transport* t = session_->GetTransport("audio");
2663
2664 // Checks if one of the transport channels contains a connection using a given
2665 // port.
2666 auto connection_with_remote_port = [t](int port) {
2667 cricket::TransportStats stats;
2668 t->GetStats(&stats);
2669 for (auto& chan_stat : stats.channel_stats) {
2670 for (auto& conn_info : chan_stat.connection_infos) {
2671 if (conn_info.remote_candidate.address().port() == port) {
2672 return true;
2673 }
2674 }
2675 }
2676 return false;
2677 };
2678
2679 EXPECT_FALSE(connection_with_remote_port(5000));
2680 EXPECT_FALSE(connection_with_remote_port(5001));
2681 EXPECT_FALSE(connection_with_remote_port(6000));
2682
2683 // The way the *_WAIT checks work is they only wait if the condition fails,
2684 // which does not help in the case where state is not changing. This is
2685 // problematic in this test since we want to verify that adding a video
2686 // candidate does _not_ change state. So we interleave candidates and assume
2687 // that messages are executed in the order they were posted.
2688
2689 // First audio candidate.
2690 cricket::Candidate candidate0;
2691 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2692 candidate0.set_component(1);
2693 candidate0.set_protocol("udp");
2694 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2695 candidate0);
2696 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2697
2698 // Video candidate.
2699 cricket::Candidate candidate1;
2700 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2701 candidate1.set_component(1);
2702 candidate1.set_protocol("udp");
2703 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2704 candidate1);
2705 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2706
2707 // Second audio candidate.
2708 cricket::Candidate candidate2;
2709 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2710 candidate2.set_component(1);
2711 candidate2.set_protocol("udp");
2712 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2713 candidate2);
2714 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2715
2716 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2717 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2718
2719 // No need here for a _WAIT check since we are checking that state hasn't
2720 // changed: if this is false we would be doing waits for nothing and if this
2721 // is true then there will be no messages processed anyways.
2722 EXPECT_FALSE(connection_with_remote_port(6000));
2723}
2724
Peter Thatcher4eddf182015-04-30 10:55:59 -07002725// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002726TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2727 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002729
2730 PeerConnectionInterface::RTCOfferAnswerOptions options;
2731 options.use_rtp_mux = true;
2732
2733 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002735
2736 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2737 session_->GetTransportProxy("video")->impl());
2738
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002740 SessionDescriptionInterface* answer =
2741 CreateRemoteAnswer(session_->local_description());
2742 SetRemoteDescriptionWithoutError(answer);
2743
2744 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2745 session_->GetTransportProxy("video")->impl());
2746}
2747
2748// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2749TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2750 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2751 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002752
Donald Curtis0e209b02015-03-24 09:29:54 -07002753 PeerConnectionInterface::RTCOfferAnswerOptions options;
2754 options.use_rtp_mux = true;
2755
2756 SessionDescriptionInterface* offer = CreateOffer(options);
2757 SetLocalDescriptionWithoutError(offer);
2758
2759 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2760 session_->GetTransportProxy("video")->impl());
2761
2762 mediastream_signaling_.SendAudioVideoStream2();
2763
2764 // Remove BUNDLE from the answer.
2765 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2766 CreateRemoteAnswer(session_->local_description()));
2767 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2768 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2769 JsepSessionDescription* modified_answer =
2770 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2771 modified_answer->Initialize(answer_copy, "1", "1");
2772 SetRemoteDescriptionWithoutError(modified_answer); //
2773
2774 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2775 session_->GetTransportProxy("video")->impl());
2776}
2777
2778// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2779TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2780 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2781 mediastream_signaling_.SendAudioVideoStream1();
2782
2783 PeerConnectionInterface::RTCOfferAnswerOptions options;
2784 options.use_rtp_mux = true;
2785
2786 SessionDescriptionInterface* offer = CreateOffer(options);
2787 SetLocalDescriptionWithoutError(offer);
2788
2789 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2790 session_->GetTransportProxy("video")->impl());
2791
2792 mediastream_signaling_.SendAudioVideoStream2();
2793 SessionDescriptionInterface* answer =
2794 CreateRemoteAnswer(session_->local_description());
2795 SetRemoteDescriptionWithoutError(answer);
2796
2797 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2798 session_->GetTransportProxy("video")->impl());
2799}
2800
2801// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2802TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2803 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2804 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002805
Donald Curtis0e209b02015-03-24 09:29:54 -07002806 PeerConnectionInterface::RTCOfferAnswerOptions options;
2807 options.use_rtp_mux = true;
2808
2809 SessionDescriptionInterface* offer = CreateOffer(options);
2810 SetLocalDescriptionWithoutError(offer);
2811
2812 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2813 session_->GetTransportProxy("video")->impl());
2814
2815 mediastream_signaling_.SendAudioVideoStream2();
2816
2817 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002818 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 CreateRemoteAnswer(session_->local_description()));
2820 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2821 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2822 JsepSessionDescription* modified_answer =
2823 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2824 modified_answer->Initialize(answer_copy, "1", "1");
2825 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826
Donald Curtis0e209b02015-03-24 09:29:54 -07002827 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2828 session_->GetTransportProxy("video")->impl());
2829}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830
Peter Thatcher4eddf182015-04-30 10:55:59 -07002831// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002832TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2833 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2834 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835
Donald Curtis0e209b02015-03-24 09:29:54 -07002836 PeerConnectionInterface::RTCOfferAnswerOptions options;
2837 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838
Donald Curtis0e209b02015-03-24 09:29:54 -07002839 SessionDescriptionInterface* offer = CreateOffer(options);
2840 SetLocalDescriptionWithoutError(offer);
2841
2842 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2843 session_->GetTransportProxy("video")->impl());
2844
2845 mediastream_signaling_.SendAudioVideoStream2();
2846 SessionDescriptionInterface* answer =
2847 CreateRemoteAnswer(session_->local_description());
2848 SetRemoteDescriptionWithoutError(answer);
2849
2850 // This should lead to an audio-only call but isn't implemented
2851 // correctly yet.
2852 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2853 session_->GetTransportProxy("video")->impl());
2854}
2855
2856// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2857TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2858 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2859 mediastream_signaling_.SendAudioVideoStream1();
2860 PeerConnectionInterface::RTCOfferAnswerOptions options;
2861 options.use_rtp_mux = true;
2862
2863 SessionDescriptionInterface* offer = CreateOffer(options);
2864 SetLocalDescriptionWithoutError(offer);
2865
2866 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2867 session_->GetTransportProxy("video")->impl());
2868
2869 mediastream_signaling_.SendAudioVideoStream2();
2870
2871 // Remove BUNDLE from the answer.
2872 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2873 CreateRemoteAnswer(session_->local_description()));
2874 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2875 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2876 JsepSessionDescription* modified_answer =
2877 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2878 modified_answer->Initialize(answer_copy, "1", "1");
2879 SetRemoteDescriptionWithoutError(modified_answer); //
2880
2881 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2882 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883}
2884
Peter Thatcher4eddf182015-04-30 10:55:59 -07002885// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2886TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2887 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2888 mediastream_signaling_.SendAudioVideoStream1();
2889
2890 PeerConnectionInterface::RTCOfferAnswerOptions options;
2891 options.use_rtp_mux = true;
2892
2893 SessionDescriptionInterface* offer = CreateOffer(options);
2894 SetRemoteDescriptionWithoutError(offer);
2895
2896 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2897 session_->GetTransportProxy("video")->impl());
2898}
2899
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002900TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2901 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2902 mediastream_signaling_.SendAudioVideoStream1();
2903
2904 PeerConnectionInterface::RTCOfferAnswerOptions options;
2905 SessionDescriptionInterface* offer = CreateOffer(options);
2906 SetLocalDescriptionWithoutError(offer);
2907
2908 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2909 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2910
2911 mediastream_signaling_.SendAudioVideoStream2();
2912 SessionDescriptionInterface* answer =
2913 CreateRemoteAnswer(session_->local_description());
2914 SetRemoteDescriptionWithoutError(answer);
2915
2916 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2917 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2918}
2919
2920TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2921 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2922 mediastream_signaling_.SendAudioVideoStream1();
2923
2924 PeerConnectionInterface::RTCOfferAnswerOptions options;
2925 SessionDescriptionInterface* offer = CreateOffer(options);
2926 SetLocalDescriptionWithoutError(offer);
2927
2928 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2929 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2930
2931 mediastream_signaling_.SendAudioVideoStream2();
2932 SessionDescriptionInterface* answer =
2933 CreateRemoteAnswer(session_->local_description());
2934 SetRemoteDescriptionWithoutError(answer);
2935
2936 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2937 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2938}
2939
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002940// This test verifies that SetLocalDescription and SetRemoteDescription fails
2941// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2942TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002943 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002944 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002945
2946 PeerConnectionInterface::RTCOfferAnswerOptions options;
2947 options.use_rtp_mux = true;
2948
2949 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002950 std::string offer_str;
2951 offer->ToString(&offer_str);
2952 // Disable rtcp-mux
2953 const std::string rtcp_mux = "rtcp-mux";
2954 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002955 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002956 xrtcp_mux.c_str(), xrtcp_mux.length(),
2957 &offer_str);
2958 JsepSessionDescription *local_offer =
2959 new JsepSessionDescription(JsepSessionDescription::kOffer);
2960 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002961 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002962 JsepSessionDescription *remote_offer =
2963 new JsepSessionDescription(JsepSessionDescription::kOffer);
2964 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002965 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002966 // Trying unmodified SDP.
2967 SetLocalDescriptionWithoutError(offer);
2968}
2969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002971 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 mediastream_signaling_.SendAudioVideoStream1();
2973 CreateAndSetRemoteOfferAndLocalAnswer();
2974 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2975 ASSERT_TRUE(channel != NULL);
2976 ASSERT_EQ(1u, channel->recv_streams().size());
2977 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2978 double left_vol, right_vol;
2979 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2980 EXPECT_EQ(1, left_vol);
2981 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002982 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002983 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2985 EXPECT_EQ(0, left_vol);
2986 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002987 EXPECT_EQ(0, renderer->channel_id());
2988 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2990 EXPECT_EQ(1, left_vol);
2991 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002992 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993}
2994
2995TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002996 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997 mediastream_signaling_.SendAudioVideoStream1();
2998 CreateAndSetRemoteOfferAndLocalAnswer();
2999 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3000 ASSERT_TRUE(channel != NULL);
3001 ASSERT_EQ(1u, channel->send_streams().size());
3002 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3003 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3004
3005 cricket::AudioOptions options;
3006 options.echo_cancellation.Set(true);
3007
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003008 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003009 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3011 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003012 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003013 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003015 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003016 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3018 bool value;
3019 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3020 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003021 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003022 EXPECT_TRUE(renderer->sink() == NULL);
3023}
3024
3025TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003026 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003027 mediastream_signaling_.SendAudioVideoStream1();
3028 CreateAndSetRemoteOfferAndLocalAnswer();
3029 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3030 ASSERT_TRUE(channel != NULL);
3031 ASSERT_EQ(1u, channel->send_streams().size());
3032 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3033
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003034 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003035 cricket::AudioOptions options;
3036 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3037 EXPECT_TRUE(renderer->sink() != NULL);
3038
3039 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3040 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3041 // SetSink(NULL) callback afterwards.
3042 renderer.reset();
3043
3044 // This will trigger SetSink(NULL) if no OnClose() callback.
3045 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046}
3047
3048TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003049 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 mediastream_signaling_.SendAudioVideoStream1();
3051 CreateAndSetRemoteOfferAndLocalAnswer();
3052 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3053 ASSERT_TRUE(channel != NULL);
3054 ASSERT_LT(0u, channel->renderers().size());
3055 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3056 ASSERT_EQ(1u, channel->recv_streams().size());
3057 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3058 cricket::FakeVideoRenderer renderer;
3059 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3060 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3061 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3062 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3063}
3064
3065TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003066 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067 mediastream_signaling_.SendAudioVideoStream1();
3068 CreateAndSetRemoteOfferAndLocalAnswer();
3069 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3070 ASSERT_TRUE(channel != NULL);
3071 ASSERT_EQ(1u, channel->send_streams().size());
3072 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3073 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3074 cricket::VideoOptions* options = NULL;
3075 session_->SetVideoSend(send_ssrc, false, options);
3076 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3077 session_->SetVideoSend(send_ssrc, true, options);
3078 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3079}
3080
3081TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3082 TestCanInsertDtmf(false);
3083}
3084
3085TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3086 TestCanInsertDtmf(true);
3087}
3088
3089TEST_F(WebRtcSessionTest, InsertDtmf) {
3090 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003091 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 mediastream_signaling_.SendAudioVideoStream1();
3093 CreateAndSetRemoteOfferAndLocalAnswer();
3094 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3095 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3096
3097 // Insert DTMF
3098 const int expected_flags = DF_SEND;
3099 const int expected_duration = 90;
3100 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3101 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3102 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3103
3104 // Verify
3105 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3106 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3107 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3108 expected_duration, expected_flags));
3109 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3110 expected_duration, expected_flags));
3111 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3112 expected_duration, expected_flags));
3113}
3114
3115// This test verifies the |initiator| flag when session initiates the call.
3116TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003117 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003119 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3121 SetLocalDescriptionWithoutError(offer);
3122 EXPECT_TRUE(session_->initiator());
3123 SetRemoteDescriptionWithoutError(answer);
3124 EXPECT_TRUE(session_->initiator());
3125}
3126
3127// This test verifies the |initiator| flag when session receives the call.
3128TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003129 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130 EXPECT_FALSE(session_->initiator());
3131 SessionDescriptionInterface* offer = CreateRemoteOffer();
3132 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003133 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134
3135 EXPECT_FALSE(session_->initiator());
3136 SetLocalDescriptionWithoutError(answer);
3137 EXPECT_FALSE(session_->initiator());
3138}
3139
pthatcherfa301802015-08-11 04:12:56 -07003140// This test verifies the ice protocol type at initiator of the call
3141// if |a=ice-options:google-ice| is present in answer.
3142TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
3143 Init();
3144 mediastream_signaling_.SendAudioVideoStream1();
3145 SessionDescriptionInterface* offer = CreateOffer();
3146 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3147 CreateRemoteAnswer(offer));
3148 SetLocalDescriptionWithoutError(offer);
3149 std::string sdp;
3150 EXPECT_TRUE(answer->ToString(&sdp));
3151 // Adding ice-options to the session level.
3152 InjectAfter("t=0 0\r\n",
3153 "a=ice-options:google-ice\r\n",
3154 &sdp);
3155 SessionDescriptionInterface* answer_with_gice =
3156 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3157 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3158 // only gice to fail.
3159 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
3160}
3161
3162// This test verifies the ice protocol type at initiator of the call
3163// if ICE RFC5245 is supported in answer.
3164TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
3165 Init();
3166 mediastream_signaling_.SendAudioVideoStream1();
3167 SessionDescriptionInterface* offer = CreateOffer();
3168 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3169 SetLocalDescriptionWithoutError(offer);
3170
3171 SetRemoteDescriptionWithoutError(answer);
3172 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3173 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3174}
3175
3176// This test verifies the ice protocol type at receiver side of the call if
3177// receiver decides to use ice RFC 5245.
3178TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
3179 Init();
3180 mediastream_signaling_.SendAudioVideoStream1();
3181 SessionDescriptionInterface* offer = CreateOffer();
3182 SetRemoteDescriptionWithoutError(offer);
3183 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3184 SetLocalDescriptionWithoutError(answer);
3185 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3186 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3187}
3188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3190TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003191 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003192 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003193 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003195 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196 CreateRemoteAnswer(session_->local_description()));
3197
3198 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3199 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003200 JsepSessionDescription* modified_answer =
3201 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
3203 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3204 answer->session_id(),
3205 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003206 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207
wu@webrtc.org4e393072014-04-07 17:04:35 +00003208 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209 std::string sdp;
3210 EXPECT_TRUE(answer->ToString(&sdp));
3211 const std::string kAudioMid = "a=mid:audio";
3212 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003213 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214 kAudioMidReplaceStr.c_str(),
3215 kAudioMidReplaceStr.length(),
3216 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003217 SessionDescriptionInterface* modified_answer1 =
3218 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003219 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220
wu@webrtc.org4e393072014-04-07 17:04:35 +00003221 // Different media types.
3222 EXPECT_TRUE(answer->ToString(&sdp));
3223 const std::string kAudioMline = "m=audio";
3224 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003225 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003226 kAudioMlineReplaceStr.c_str(),
3227 kAudioMlineReplaceStr.length(),
3228 &sdp);
3229 SessionDescriptionInterface* modified_answer2 =
3230 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3231 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233 SetRemoteDescriptionWithoutError(answer.release());
3234}
3235
3236// Verifying remote offer and local answer have matching m-lines as per
3237// RFC 3264.
3238TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003239 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240 mediastream_signaling_.SendAudioVideoStream1();
3241 SessionDescriptionInterface* offer = CreateRemoteOffer();
3242 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003243 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244
3245 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3246 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003247 JsepSessionDescription* modified_answer =
3248 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249
3250 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3251 answer->session_id(),
3252 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003253 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254 SetLocalDescriptionWithoutError(answer);
3255}
3256
3257// This test verifies that WebRtcSession does not start candidate allocation
3258// before SetLocalDescription is called.
3259TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003260 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261 mediastream_signaling_.SendAudioVideoStream1();
3262 SessionDescriptionInterface* offer = CreateRemoteOffer();
3263 cricket::Candidate candidate;
3264 candidate.set_component(1);
3265 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3266 candidate);
3267 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3268 cricket::Candidate candidate1;
3269 candidate1.set_component(1);
3270 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3271 candidate1);
3272 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3273 SetRemoteDescriptionWithoutError(offer);
3274 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3275 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3276
3277 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003278 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3280 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3281
wu@webrtc.org91053e72013-08-10 07:18:04 +00003282 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283 SetLocalDescriptionWithoutError(answer);
3284 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3285 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3286 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3287}
3288
3289// This test verifies that crypto parameter is updated in local session
3290// description as per security policy set in MediaSessionDescriptionFactory.
3291TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003292 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003294 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295
3296 // Making sure SetLocalDescription correctly sets crypto value in
3297 // SessionDescription object after de-serialization of sdp string. The value
3298 // will be set as per MediaSessionDescriptionFactory.
3299 std::string offer_str;
3300 offer->ToString(&offer_str);
3301 SessionDescriptionInterface* jsep_offer_str =
3302 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3303 SetLocalDescriptionWithoutError(jsep_offer_str);
3304 EXPECT_TRUE(session_->voice_channel()->secure_required());
3305 EXPECT_TRUE(session_->video_channel()->secure_required());
3306}
3307
3308// This test verifies the crypto parameter when security is disabled.
3309TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003310 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003311 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003313 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314
3315 // Making sure SetLocalDescription correctly sets crypto value in
3316 // SessionDescription object after de-serialization of sdp string. The value
3317 // will be set as per MediaSessionDescriptionFactory.
3318 std::string offer_str;
3319 offer->ToString(&offer_str);
3320 SessionDescriptionInterface *jsep_offer_str =
3321 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3322 SetLocalDescriptionWithoutError(jsep_offer_str);
3323 EXPECT_FALSE(session_->voice_channel()->secure_required());
3324 EXPECT_FALSE(session_->video_channel()->secure_required());
3325}
3326
3327// This test verifies that an answer contains new ufrag and password if an offer
3328// with new ufrag and password is received.
3329TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003330 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003332 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003333 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 CreateRemoteOffer(options));
3335 SetRemoteDescriptionWithoutError(offer.release());
3336
3337 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003338 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003339 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 SetLocalDescriptionWithoutError(answer.release());
3341
3342 // Receive an offer with new ufrag and password.
3343 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003344 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003345 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 SetRemoteDescriptionWithoutError(updated_offer1.release());
3347
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003348 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003349 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350
3351 CompareIceUfragAndPassword(updated_answer1->description(),
3352 session_->local_description()->description(),
3353 false);
3354
3355 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003356}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003357
wu@webrtc.org91053e72013-08-10 07:18:04 +00003358// This test verifies that an answer contains old ufrag and password if an offer
3359// with old ufrag and password is received.
3360TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003361 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003362 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003363 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003364 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003365 CreateRemoteOffer(options));
3366 SetRemoteDescriptionWithoutError(offer.release());
3367
3368 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003369 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003370 CreateAnswer(NULL));
3371 SetLocalDescriptionWithoutError(answer.release());
3372
3373 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003375 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003376 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377 SetRemoteDescriptionWithoutError(updated_offer2.release());
3378
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003379 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003380 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381
3382 CompareIceUfragAndPassword(updated_answer2->description(),
3383 session_->local_description()->description(),
3384 true);
3385
3386 SetLocalDescriptionWithoutError(updated_answer2.release());
3387}
3388
3389TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003390 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003392 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003393 const std::string session_id_orig = offer->session_id();
3394 const std::string session_version_orig = offer->session_version();
3395 SetLocalDescriptionWithoutError(offer);
3396
3397 video_channel_ = media_engine_->GetVideoChannel(0);
3398 video_channel_->set_fail_set_send_codecs(true);
3399
3400 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003401 SessionDescriptionInterface* answer =
3402 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003403 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404}
3405
3406// Runs the loopback call test with BUNDLE and STUN disabled.
3407TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3408 // Lets try with only UDP ports.
pthatcherfa301802015-08-11 04:12:56 -07003409 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3410 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003411 cricket::PORTALLOCATOR_DISABLE_STUN |
3412 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 TestLoopbackCall();
3414}
3415
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003416TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
pthatcherfa301802015-08-11 04:12:56 -07003417 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3418 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003419 cricket::PORTALLOCATOR_DISABLE_STUN |
3420 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3421 cricket::PORTALLOCATOR_DISABLE_RELAY);
3422
3423 // best connection is IPv6 since it has higher network preference.
3424 LoopbackNetworkConfiguration config;
3425 config.test_ipv6_network_ = true;
3426 config.best_connection_after_initial_ice_converged_ =
3427 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3428
3429 TestLoopbackCall(config);
3430}
3431
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003432// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003433TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
pthatcherfa301802015-08-11 04:12:56 -07003434 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3435 cricket::PORTALLOCATOR_DISABLE_TCP |
3436 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003437 TestLoopbackCall();
3438}
3439
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003440TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003441 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003443 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003445 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3446 std::string error_code_str = "ERROR_CONTENT";
3447 std::string error_desc = "Fake session error description.";
3448 session_->SetError(error_code, error_desc);
3449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3451 SessionDescriptionInterface* answer =
3452 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003453
3454 std::string action;
3455 std::ostringstream session_error_msg;
3456 session_error_msg << kSessionError << error_code_str << ". ";
3457 session_error_msg << kSessionErrorDesc << error_desc << ".";
3458 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3459 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460}
3461
3462TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3463 constraints_.reset(new FakeConstraints());
3464 constraints_->AddOptional(
3465 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003466 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467
3468 SetLocalDescriptionWithDataChannel();
3469 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3470}
3471
3472TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003473 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474
3475 constraints_.reset(new FakeConstraints());
3476 constraints_->AddOptional(
3477 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003478 options_.disable_sctp_data_channels = false;
3479
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003480 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481
3482 SetLocalDescriptionWithDataChannel();
3483 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3484}
3485
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003486TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003487 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003488
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003489 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003490
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003491 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003492 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003493 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3494}
3495
3496TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003497 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003498 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003499 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003500
3501 // Create remote offer with SCTP.
3502 cricket::MediaSessionOptions options;
3503 options.data_channel_type = cricket::DCT_SCTP;
3504 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003505 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003506 SetRemoteDescriptionWithoutError(offer);
3507
3508 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003509 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003510 EXPECT_TRUE(answer != NULL);
3511 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3512 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003513}
3514
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3516 constraints_.reset(new FakeConstraints());
3517 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003518 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003519 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520
3521 SetLocalDescriptionWithDataChannel();
3522 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3523}
3524
3525TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003526 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003528 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529
3530 SetLocalDescriptionWithDataChannel();
3531 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3532}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003533
wu@webrtc.org97077a32013-10-25 21:18:33 +00003534TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003535 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003536 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003537 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003538
3539 SetLocalDescriptionWithDataChannel();
3540 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3541}
3542
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003543TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003544 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003545 const int new_send_port = 9998;
3546 const int new_recv_port = 7775;
3547
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003548 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003549 SetFactoryDtlsSrtp();
3550
3551 // By default, don't actually add the codecs to desc_factory_; they don't
3552 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3553 // let the session description get parsed. That'll get the proper codecs
3554 // into the stream.
3555 cricket::MediaSessionOptions options;
3556 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3557 "stream1", new_send_port, options);
3558
3559 // SetRemoteDescription will take the ownership of the offer.
3560 SetRemoteDescriptionWithoutError(offer);
3561
3562 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3563 new_recv_port, CreateAnswer(NULL));
3564 ASSERT_TRUE(answer != NULL);
3565
3566 // Now set the local description, which'll take ownership of the answer.
3567 SetLocalDescriptionWithoutError(answer);
3568
3569 // TEST PLAN: Set the port number to something new, set it in the SDP,
3570 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003571 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003572 dci.reliable = true;
3573 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003574 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003575 session_->CreateDataChannel("datachannel", &dci);
3576
3577 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3578 int portnum = -1;
3579 ASSERT_TRUE(ch != NULL);
3580 ASSERT_EQ(1UL, ch->send_codecs().size());
3581 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003582 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003583 ch->send_codecs()[0].name.c_str()));
3584 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3585 &portnum));
3586 EXPECT_EQ(new_send_port, portnum);
3587
3588 ASSERT_EQ(1UL, ch->recv_codecs().size());
3589 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003590 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003591 ch->recv_codecs()[0].name.c_str()));
3592 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3593 &portnum));
3594 EXPECT_EQ(new_recv_port, portnum);
3595}
3596
wu@webrtc.org91053e72013-08-10 07:18:04 +00003597// Verifies that CreateOffer succeeds when CreateOffer is called before async
3598// identity generation is finished.
3599TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003600 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003601 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003602
3603 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003604 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003605 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3606
wu@webrtc.org91053e72013-08-10 07:18:04 +00003607 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003608 VerifyNoCryptoParams(offer->description(), true);
3609 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003610}
3611
3612// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3613// identity generation is finished.
3614TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003615 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003616 InitWithDtls();
3617 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003618
3619 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003620 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003621 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003622 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003623 ASSERT_TRUE(offer.get() != NULL);
3624 SetRemoteDescriptionWithoutError(offer.release());
3625
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003626 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003627 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003628 VerifyNoCryptoParams(answer->description(), true);
3629 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003630}
3631
3632// Verifies that CreateOffer succeeds when CreateOffer is called after async
3633// identity generation is finished.
3634TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003635 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003636 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003637
3638 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003639
3640 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003641 EXPECT_TRUE(offer != NULL);
3642}
3643
3644// Verifies that CreateOffer fails when CreateOffer is called after async
3645// identity generation fails.
3646TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003647 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003648 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003649
3650 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003651
3652 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003653 EXPECT_TRUE(offer == NULL);
3654}
3655
3656// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3657// before async identity generation is finished.
3658TEST_F(WebRtcSessionTest,
3659 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003660 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003661 VerifyMultipleAsyncCreateDescription(
3662 true, CreateSessionDescriptionRequest::kOffer);
3663}
3664
3665// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3666// before async identity generation fails.
3667TEST_F(WebRtcSessionTest,
3668 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670 VerifyMultipleAsyncCreateDescription(
3671 false, CreateSessionDescriptionRequest::kOffer);
3672}
3673
3674// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3675// before async identity generation is finished.
3676TEST_F(WebRtcSessionTest,
3677 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003678 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003679 VerifyMultipleAsyncCreateDescription(
3680 true, CreateSessionDescriptionRequest::kAnswer);
3681}
3682
3683// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3684// before async identity generation fails.
3685TEST_F(WebRtcSessionTest,
3686 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003687 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003688 VerifyMultipleAsyncCreateDescription(
3689 false, CreateSessionDescriptionRequest::kAnswer);
3690}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003691
3692// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3693// offer has no SDES crypto but only DTLS fingerprint.
3694TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3695 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003696 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003697 // Create a remote offer with secured transport disabled.
3698 cricket::MediaSessionOptions options;
3699 JsepSessionDescription* offer(CreateRemoteOffer(
3700 options, cricket::SEC_DISABLED));
3701 // Adds a DTLS fingerprint to the remote offer.
3702 cricket::SessionDescription* sdp = offer->description();
3703 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3704 ASSERT_TRUE(audio != NULL);
3705 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3706 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003707 rtc::SSLFingerprint::CreateFromRfc4572(
3708 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003709 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003710 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003711}
3712
wu@webrtc.orgde305012013-10-31 15:40:38 +00003713// This test verifies DSCP is properly applied on the media channels.
3714TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3715 constraints_.reset(new FakeConstraints());
3716 constraints_->AddOptional(
3717 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003718 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003719 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003720 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003721
3722 SetLocalDescriptionWithoutError(offer);
3723
3724 video_channel_ = media_engine_->GetVideoChannel(0);
3725 voice_channel_ = media_engine_->GetVoiceChannel(0);
3726
3727 ASSERT_TRUE(video_channel_ != NULL);
3728 ASSERT_TRUE(voice_channel_ != NULL);
3729 cricket::AudioOptions audio_options;
3730 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3731 cricket::VideoOptions video_options;
3732 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3733 EXPECT_TRUE(audio_options.dscp.IsSet());
3734 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3735 EXPECT_TRUE(video_options.dscp.IsSet());
3736 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3737}
3738
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003739TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3740 constraints_.reset(new FakeConstraints());
3741 constraints_->AddOptional(
3742 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3743 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003744 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003745 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003746 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003747
3748 SetLocalDescriptionWithoutError(offer);
3749
3750 video_channel_ = media_engine_->GetVideoChannel(0);
3751
3752 ASSERT_TRUE(video_channel_ != NULL);
3753 cricket::VideoOptions video_options;
3754 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3755 EXPECT_TRUE(
3756 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3757}
3758
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003759TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3760 // Number of unsignalled receiving streams should be between 0 and
3761 // kMaxUnsignalledRecvStreams.
3762 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3763 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3764 kMaxUnsignalledRecvStreams);
3765 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3766}
3767
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003768TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3769 constraints_.reset(new FakeConstraints());
3770 constraints_->AddOptional(
3771 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3772 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003773 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003774 mediastream_signaling_.SendAudioVideoStream1();
3775 SessionDescriptionInterface* offer = CreateOffer();
3776
3777 SetLocalDescriptionWithoutError(offer);
3778
3779 voice_channel_ = media_engine_->GetVoiceChannel(0);
3780
3781 ASSERT_TRUE(voice_channel_ != NULL);
3782 cricket::AudioOptions audio_options;
3783 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3784 EXPECT_TRUE(
3785 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3786}
3787
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003788// Tests that we can renegotiate new media content with ICE candidates in the
3789// new remote SDP.
3790TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003791 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003792 InitWithDtls();
3793 SetFactoryDtlsSrtp();
3794
3795 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003796 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003797 SetLocalDescriptionWithoutError(offer);
3798
3799 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3800 SetRemoteDescriptionWithoutError(answer);
3801
3802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003803 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003804 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3805
3806 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003807 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003808 candidate1.set_component(1);
3809 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3810 candidate1);
3811 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3812 SetRemoteDescriptionWithoutError(offer);
3813
3814 answer = CreateAnswer(NULL);
3815 SetLocalDescriptionWithoutError(answer);
3816}
3817
3818// Tests that we can renegotiate new media content with ICE candidates separated
3819// from the remote SDP.
3820TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003822 InitWithDtls();
3823 SetFactoryDtlsSrtp();
3824
3825 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003826 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003827 SetLocalDescriptionWithoutError(offer);
3828
3829 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3830 SetRemoteDescriptionWithoutError(answer);
3831
3832 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003833 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003834 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3835 SetRemoteDescriptionWithoutError(offer);
3836
3837 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003838 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003839 candidate1.set_component(1);
3840 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3841 candidate1);
3842 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3843
3844 answer = CreateAnswer(NULL);
3845 SetLocalDescriptionWithoutError(answer);
3846}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003847// Tests that RTX codec is removed from the answer when it isn't supported
3848// by local side.
3849TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3850 Init();
3851 mediastream_signaling_.SendAudioVideoStream1();
3852 std::string offer_sdp(kSdpWithRtx);
3853
3854 SessionDescriptionInterface* offer =
3855 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3856 EXPECT_TRUE(offer->ToString(&offer_sdp));
3857
3858 // Offer SDP contains the RTX codec.
3859 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3860 SetRemoteDescriptionWithoutError(offer);
3861
3862 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3863 std::string answer_sdp;
3864 answer->ToString(&answer_sdp);
3865 // Answer SDP removes the unsupported RTX codec.
3866 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3867 SetLocalDescriptionWithoutError(answer);
3868}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003869
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003870// This verifies that the voice channel after bundle has both options from video
3871// and voice channels.
3872TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3873 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3874 mediastream_signaling_.SendAudioVideoStream1();
3875
3876 PeerConnectionInterface::RTCOfferAnswerOptions options;
3877 options.use_rtp_mux = true;
3878
3879 SessionDescriptionInterface* offer = CreateOffer(options);
3880 SetLocalDescriptionWithoutError(offer);
3881
3882 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3883 rtc::Socket::Option::OPT_SNDBUF, 4000);
3884
3885 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3886 rtc::Socket::Option::OPT_RCVBUF, 8000);
3887
3888 int option_val;
3889 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3890 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3891 EXPECT_EQ(4000, option_val);
3892 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3893 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3894
3895 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3896 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3897 EXPECT_EQ(8000, option_val);
3898 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3899 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3900
3901 EXPECT_NE(session_->voice_channel()->transport_channel(),
3902 session_->video_channel()->transport_channel());
3903
3904 mediastream_signaling_.SendAudioVideoStream2();
3905 SessionDescriptionInterface* answer =
3906 CreateRemoteAnswer(session_->local_description());
3907 SetRemoteDescriptionWithoutError(answer);
3908
3909 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3910 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3911 EXPECT_EQ(4000, option_val);
3912
3913 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3914 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3915 EXPECT_EQ(8000, option_val);
3916}
3917
tommi0f620f42015-07-09 03:25:02 -07003918// Test creating a session, request multiple offers, destroy the session
3919// and make sure we got success/failure callbacks for all of the requests.
3920// Background: crbug.com/507307
3921TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3922 Init();
3923
3924 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3925 PeerConnectionInterface::RTCOfferAnswerOptions options;
3926 options.offer_to_receive_audio =
3927 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3928
3929 for (auto& o : observers) {
3930 o = new WebRtcSessionCreateSDPObserverForTest();
3931 session_->CreateOffer(o, options);
3932 }
3933
3934 session_.reset();
3935
3936 // Make sure we process pending messages on the current (signaling) thread
3937 // before checking we we got our callbacks. Quit() will do this and then
3938 // immediately exit. We won't need the queue after this point anyway.
3939 rtc::Thread::Current()->Quit();
3940
3941 for (auto& o : observers) {
3942 // We expect to have received a notification now even if the session was
3943 // terminated. The offer creation may or may not have succeeded, but we
3944 // must have received a notification which, so the only invalid state
3945 // is kInit.
3946 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3947 }
3948}
3949
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003950// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3951// currently fails because upon disconnection and reconnection OnIceComplete is
3952// called more than once without returning to IceGatheringGathering.