blob: e442cf158bb2ea22518a8b4eef9636750b5e17a8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/audiotrack.h"
jbauchac8869e2015-07-03 01:36:14 -070029#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/jsepicecandidate.h"
31#include "talk/app/webrtc/jsepsessiondescription.h"
32#include "talk/app/webrtc/mediastreamsignaling.h"
33#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020035#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000036#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000039#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "talk/media/base/fakemediaengine.h"
41#include "talk/media/base/fakevideorenderer.h"
42#include "talk/media/base/mediachannel.h"
43#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000047#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/channelmanager.h"
50#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051#include "webrtc/base/fakenetwork.h"
52#include "webrtc/base/firewallsocketserver.h"
53#include "webrtc/base/gunit.h"
54#include "webrtc/base/logging.h"
55#include "webrtc/base/network.h"
56#include "webrtc/base/physicalsocketserver.h"
57#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020058#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059#include "webrtc/base/sslstreamadapter.h"
60#include "webrtc/base/stringutils.h"
61#include "webrtc/base/thread.h"
62#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64#define MAYBE_SKIP_TEST(feature) \
65 if (!(feature())) { \
66 LOG(LS_INFO) << "Feature disabled... skipping"; \
67 return; \
68 }
69
70using cricket::BaseSession;
71using cricket::DF_PLAY;
72using cricket::DF_SEND;
73using cricket::FakeVoiceMediaChannel;
pthatcherfa301802015-08-11 04:12:56 -070074using cricket::NS_GINGLE_P2P;
75using cricket::NS_JINGLE_ICE_UDP;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020083using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070085using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::IceCandidateCollection;
87using webrtc::JsepIceCandidate;
88using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000089using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::PeerConnectionInterface;
91using webrtc::SessionDescriptionInterface;
92using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000093using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000094using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kCreateChannelFailed;
96using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000099using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000100using webrtc::kSdpWithoutDtlsFingerprint;
101using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000103using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000104using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000106typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
107
wu@webrtc.org364f2042013-11-20 21:49:41 +0000108static const int kClientAddrPort = 0;
109static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000110static const char kClientIPv6AddrHost1[] =
111 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000112static const char kClientAddrHost2[] = "22.22.22.22";
113static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000114static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
115static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000116static const char kTurnUsername[] = "test";
117static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
119static const char kSessionVersion[] = "1";
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121// Media index of candidates belonging to the first media content.
122static const int kMediaContentIndex0 = 0;
123static const char kMediaContentName0[] = "audio";
124
125// Media index of candidates belonging to the second media content.
126static const int kMediaContentIndex1 = 1;
127static const char kMediaContentName1[] = "video";
128
129static const int kIceCandidatesTimeout = 10000;
130
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000131static const char kFakeDtlsFingerprint[] =
132 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
133 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
134
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000135static const char kTooLongIceUfragPwd[] =
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
140
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000141static const char kSdpWithRtx[] =
142 "v=0\r\n"
143 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
144 "s=-\r\n"
145 "t=0 0\r\n"
146 "a=msid-semantic: WMS stream1\r\n"
147 "m=video 9 RTP/SAVPF 0 96\r\n"
148 "c=IN IP4 0.0.0.0\r\n"
149 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
150 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
151 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
152 "a=mid:video\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
156 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
157 "a=rtpmap:0 fake_video_codec/90000\r\n"
158 "a=rtpmap:96 rtx/90000\r\n"
159 "a=fmtp:96 apt=0\r\n";
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161// Add some extra |newlines| to the |message| after |line|.
162static void InjectAfter(const std::string& line,
163 const std::string& newlines,
164 std::string* message) {
165 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 tmp.c_str(), tmp.length(), message);
168}
169
170class MockIceObserver : public webrtc::IceObserver {
171 public:
172 MockIceObserver()
173 : oncandidatesready_(false),
174 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
175 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
176 }
177
178 virtual void OnIceConnectionChange(
179 PeerConnectionInterface::IceConnectionState new_state) {
180 ice_connection_state_ = new_state;
181 }
182 virtual void OnIceGatheringChange(
183 PeerConnectionInterface::IceGatheringState new_state) {
184 // We can never transition back to "new".
185 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
186 ice_gathering_state_ = new_state;
187
188 // oncandidatesready_ really means "ICE gathering is complete".
189 // This if statement ensures that this value remains correct when we
190 // transition from kIceGatheringComplete to kIceGatheringGathering.
191 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
192 oncandidatesready_ = false;
193 }
194 }
195
196 // Found a new candidate.
197 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000198 switch (candidate->sdp_mline_index()) {
199 case kMediaContentIndex0:
200 mline_0_candidates_.push_back(candidate->candidate());
201 break;
202 case kMediaContentIndex1:
203 mline_1_candidates_.push_back(candidate->candidate());
204 break;
205 default:
206 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000208
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // The ICE gathering state should always be Gathering when a candidate is
210 // received (or possibly Completed in the case of the final candidate).
211 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
212 }
213
214 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
215 virtual void OnIceComplete() {
216 EXPECT_FALSE(oncandidatesready_);
217 oncandidatesready_ = true;
218
219 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
220 // be called approximately simultaneously. For ease of testing, this
221 // check additionally requires that they be called in the above order.
222 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
223 ice_gathering_state_);
224 }
225
226 bool oncandidatesready_;
227 std::vector<cricket::Candidate> mline_0_candidates_;
228 std::vector<cricket::Candidate> mline_1_candidates_;
229 PeerConnectionInterface::IceConnectionState ice_connection_state_;
230 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
231};
232
233class WebRtcSessionForTest : public webrtc::WebRtcSession {
234 public:
235 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::Thread* signaling_thread,
237 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 cricket::PortAllocator* port_allocator,
239 webrtc::IceObserver* ice_observer,
240 webrtc::MediaStreamSignaling* mediastream_signaling)
241 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
242 mediastream_signaling) {
243 RegisterIceObserver(ice_observer);
244 }
245 virtual ~WebRtcSessionForTest() {}
246
247 using cricket::BaseSession::GetTransportProxy;
248 using webrtc::WebRtcSession::SetAudioPlayout;
249 using webrtc::WebRtcSession::SetAudioSend;
250 using webrtc::WebRtcSession::SetCaptureDevice;
251 using webrtc::WebRtcSession::SetVideoPlayout;
252 using webrtc::WebRtcSession::SetVideoSend;
253};
254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000258 enum State {
259 kInit,
260 kFailed,
261 kSucceeded,
262 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000263 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264
265 // CreateSessionDescriptionObserver implementation.
266 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000267 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000268 state_ = kSucceeded;
269 }
270 virtual void OnFailure(const std::string& error) {
271 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 SessionDescriptionInterface* description() { return description_.get(); }
275
276 SessionDescriptionInterface* ReleaseDescription() {
277 return description_.release();
278 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 protected:
283 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
285 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288};
289
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290class FakeAudioRenderer : public cricket::AudioRenderer {
291 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000292 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
293 virtual ~FakeAudioRenderer() {
294 if (sink_)
295 sink_->OnClose();
296 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000298 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299 ASSERT(channel_id_ == -1);
300 channel_id_ = channel_id;
301 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000302 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 ASSERT(channel_id == channel_id_);
304 channel_id_ = -1;
305 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307
308 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 private:
311 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000312 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313};
314
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315class WebRtcSessionTest : public testing::Test {
316 protected:
317 // TODO Investigate why ChannelManager crashes, if it's created
318 // after stun_server.
319 WebRtcSessionTest()
320 : media_engine_(new cricket::FakeMediaEngine()),
321 data_engine_(new cricket::FakeDataEngine()),
322 device_manager_(new cricket::FakeDeviceManager()),
323 channel_manager_(new cricket::ChannelManager(
324 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000325 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 tdesc_factory_(new cricket::TransportDescriptionFactory()),
327 desc_factory_(new cricket::MediaSessionDescriptionFactory(
328 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000329 pss_(new rtc::PhysicalSocketServer),
330 vss_(new rtc::VirtualSocketServer(pss_.get())),
331 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000334 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000335 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
336 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000337 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700338 mediastream_signaling_(channel_manager_.get()),
339 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
pthatcherfa301802015-08-11 04:12:56 -0700340 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
341
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000342 cricket::ServerAddresses stun_servers;
343 stun_servers.insert(stun_socket_addr_);
344 allocator_.reset(new cricket::BasicPortAllocator(
345 &network_manager_,
346 stun_servers,
347 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000348 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
pthatcherfa301802015-08-11 04:12:56 -0700349 cricket::PORTALLOCATOR_DISABLE_RELAY |
350 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 EXPECT_TRUE(channel_manager_->Init());
352 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000353 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
355
356 void AddInterface(const SocketAddress& addr) {
357 network_manager_.AddInterface(addr);
358 }
359
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000360 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200361 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200362 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 ASSERT_TRUE(session_.get() == NULL);
364 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 channel_manager_.get(), rtc::Thread::Current(),
366 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 &observer_,
368 &mediastream_signaling_));
369
370 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
371 observer_.ice_connection_state_);
372 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
373 observer_.ice_gathering_state_);
374
Henrik Boström5e56c592015-08-11 10:33:13 +0200375 EXPECT_TRUE(session_->Initialize(
376 options_, constraints_.get(), dtls_identity_store.Pass(),
377 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700378 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 }
380
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000381 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200382 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200383 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 }
385
386 void InitWithIceTransport(
387 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200388 PeerConnectionInterface::RTCConfiguration configuration;
389 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200390 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000391 }
392
393 void InitWithBundlePolicy(
394 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200395 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200396 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200397 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700398 }
399
400 void InitWithRtcpMuxPolicy(
401 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
402 PeerConnectionInterface::RTCConfiguration configuration;
403 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200404 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000405 }
406
407 void InitWithDtls(bool identity_request_should_fail = false) {
Henrik Boström5e56c592015-08-11 10:33:13 +0200408 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
409 new FakeDtlsIdentityStore());
410 dtls_identity_store->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200411 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200412 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 }
414
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 void InitWithDtmfCodec() {
416 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000417 const cricket::AudioCodec kTelephoneEventCodec(
418 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 std::vector<cricket::AudioCodec> codecs;
420 codecs.push_back(kTelephoneEventCodec);
421 media_engine_->SetAudioCodecs(codecs);
422 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000423 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 }
425
426 // Creates a local offer and applies it. Starts ice.
427 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
428 // to decide which streams to create.
429 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000430 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 SetLocalDescriptionWithoutError(offer);
432 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
433 observer_.ice_gathering_state_,
434 kIceCandidatesTimeout);
435 }
436
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000437 SessionDescriptionInterface* CreateOffer() {
438 PeerConnectionInterface::RTCOfferAnswerOptions options;
439 options.offer_to_receive_audio =
440 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
441
442 return CreateOffer(options);
443 }
444
wu@webrtc.org91053e72013-08-10 07:18:04 +0000445 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000446 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000447 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000448 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000449 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000450 EXPECT_TRUE_WAIT(
451 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000452 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000453 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000454 }
455
456 SessionDescriptionInterface* CreateAnswer(
457 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000458 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000459 = new WebRtcSessionCreateSDPObserverForTest();
460 session_->CreateAnswer(observer, constraints);
461 EXPECT_TRUE_WAIT(
462 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000463 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000464 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000465 }
466
wu@webrtc.org364f2042013-11-20 21:49:41 +0000467 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 return (session_->voice_channel() != NULL &&
469 session_->video_channel() != NULL);
470 }
471
wu@webrtc.org364f2042013-11-20 21:49:41 +0000472 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
474 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
475 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
476 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
477 }
478
479 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
480 ASSERT_TRUE(session_.get() != NULL);
481 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
482 ASSERT_TRUE(content != NULL);
483 const cricket::AudioContentDescription* audio_content =
484 static_cast<const cricket::AudioContentDescription*>(
485 content->description);
486 ASSERT_TRUE(audio_content != NULL);
487 ASSERT_EQ(1U, audio_content->cryptos().size());
488 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
489 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
490 audio_content->cryptos()[0].cipher_suite);
491 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
492 audio_content->protocol());
493
494 content = cricket::GetFirstVideoContent(sdp);
495 ASSERT_TRUE(content != NULL);
496 const cricket::VideoContentDescription* video_content =
497 static_cast<const cricket::VideoContentDescription*>(
498 content->description);
499 ASSERT_TRUE(video_content != NULL);
500 ASSERT_EQ(1U, video_content->cryptos().size());
501 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
502 video_content->cryptos()[0].cipher_suite);
503 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
504 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
505 video_content->protocol());
506 }
507
508 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
509 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
510 ASSERT_TRUE(content != NULL);
511 const cricket::AudioContentDescription* audio_content =
512 static_cast<const cricket::AudioContentDescription*>(
513 content->description);
514 ASSERT_TRUE(audio_content != NULL);
515 ASSERT_EQ(0U, audio_content->cryptos().size());
516
517 content = cricket::GetFirstVideoContent(sdp);
518 ASSERT_TRUE(content != NULL);
519 const cricket::VideoContentDescription* video_content =
520 static_cast<const cricket::VideoContentDescription*>(
521 content->description);
522 ASSERT_TRUE(video_content != NULL);
523 ASSERT_EQ(0U, video_content->cryptos().size());
524
525 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700526 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700528 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 video_content->protocol());
530 } else {
531 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
532 audio_content->protocol());
533 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
534 video_content->protocol());
535 }
536 }
537
538 // Set the internal fake description factories to do DTLS-SRTP.
539 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000540 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200543 // Confirmed to work with KT_RSA and KT_ECDSA.
544 identity_.reset(rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000545 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
547 }
548
549 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
550 bool expected) {
551 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
552 ASSERT_TRUE(audio != NULL);
553 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 const TransportInfo* video = sdp->GetTransportInfoByName("video");
555 ASSERT_TRUE(video != NULL);
556 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 }
558
559 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000560 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000562 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000563 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000565 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000567 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
568 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000569 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // Answer should be NULL as no crypto params in offer.
571 ASSERT_TRUE(answer == NULL);
572 }
573
574 void VerifyAnswerFromCryptoOffer() {
575 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000576 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 options.bundle_enabled = true;
578 scoped_ptr<JsepSessionDescription> offer(
579 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
580 ASSERT_TRUE(offer.get() != NULL);
581 VerifyCryptoParams(offer->description());
582 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000583 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 ASSERT_TRUE(answer.get() != NULL);
585 VerifyCryptoParams(answer->description());
586 }
587
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000588 void SetAndVerifyNumUnsignalledRecvStreams(
589 int value_set, int value_expected) {
590 constraints_.reset(new FakeConstraints());
591 constraints_->AddOptional(
592 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
593 value_set);
594 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000595 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000596 mediastream_signaling_.SendAudioVideoStream1();
597 SessionDescriptionInterface* offer = CreateOffer();
598
599 SetLocalDescriptionWithoutError(offer);
600
601 video_channel_ = media_engine_->GetVideoChannel(0);
602
603 ASSERT_TRUE(video_channel_ != NULL);
604 cricket::VideoOptions video_options;
605 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
606 EXPECT_EQ(value_expected,
607 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
608 }
609
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
611 const cricket::SessionDescription* desc2,
612 bool expect_equal) {
613 if (desc1->contents().size() != desc2->contents().size()) {
614 EXPECT_FALSE(expect_equal);
615 return;
616 }
617
618 const cricket::ContentInfos& contents = desc1->contents();
619 cricket::ContentInfos::const_iterator it = contents.begin();
620
621 for (; it != contents.end(); ++it) {
622 const cricket::TransportDescription* transport_desc1 =
623 desc1->GetTransportDescriptionByName(it->name);
624 const cricket::TransportDescription* transport_desc2 =
625 desc2->GetTransportDescriptionByName(it->name);
626 if (!transport_desc1 || !transport_desc2) {
627 EXPECT_FALSE(expect_equal);
628 return;
629 }
630 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
631 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
632 EXPECT_FALSE(expect_equal);
633 return;
634 }
635 }
636 EXPECT_TRUE(expect_equal);
637 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000638
639 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
640 std::string *sdp) {
641 const cricket::SessionDescription* desc = current_desc->description();
642 EXPECT_TRUE(current_desc->ToString(sdp));
643
644 const cricket::ContentInfos& contents = desc->contents();
645 cricket::ContentInfos::const_iterator it = contents.begin();
646 // Replace ufrag and pwd lines with empty strings.
647 for (; it != contents.end(); ++it) {
648 const cricket::TransportDescription* transport_desc =
649 desc->GetTransportDescriptionByName(it->name);
650 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
651 + "\r\n";
652 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
653 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000654 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000655 "", 0,
656 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000657 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000658 "", 0,
659 sdp);
660 }
661 }
662
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000663 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
664 const std::string& modified_ice_ufrag,
665 const std::string& modified_ice_pwd,
666 std::string* sdp) {
667 const cricket::SessionDescription* desc = current_desc->description();
668 EXPECT_TRUE(current_desc->ToString(sdp));
669
670 const cricket::ContentInfos& contents = desc->contents();
671 cricket::ContentInfos::const_iterator it = contents.begin();
672 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
673 // |modified_ice_pwd| strings.
674 for (; it != contents.end(); ++it) {
675 const cricket::TransportDescription* transport_desc =
676 desc->GetTransportDescriptionByName(it->name);
677 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
678 + "\r\n";
679 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
680 + "\r\n";
681 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
682 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000683 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000684 mod_ufrag.c_str(), mod_ufrag.length(),
685 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000686 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000687 mod_pwd.c_str(), mod_pwd.length(),
688 sdp);
689 }
690 }
691
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 // Creates a remote offer and and applies it as a remote description,
693 // creates a local answer and applies is as a local description.
694 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
695 // to decide which local and remote streams to create.
696 void CreateAndSetRemoteOfferAndLocalAnswer() {
697 SessionDescriptionInterface* offer = CreateRemoteOffer();
698 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000699 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 SetLocalDescriptionWithoutError(answer);
701 }
702 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
703 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
704 }
705 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
706 BaseSession::State expected_state) {
707 SetLocalDescriptionWithoutError(desc);
708 EXPECT_EQ(expected_state, session_->state());
709 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000710 void SetLocalDescriptionExpectError(const std::string& action,
711 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 SessionDescriptionInterface* desc) {
713 std::string error;
714 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000715 std::string sdp_type = "local ";
716 sdp_type.append(action);
717 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 EXPECT_NE(std::string::npos, error.find(expected_error));
719 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
721 SessionDescriptionInterface* desc) {
722 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
723 expected_error, desc);
724 }
725 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
726 SessionDescriptionInterface* desc) {
727 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
728 expected_error, desc);
729 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
731 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
732 }
733 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
734 BaseSession::State expected_state) {
735 SetRemoteDescriptionWithoutError(desc);
736 EXPECT_EQ(expected_state, session_->state());
737 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000738 void SetRemoteDescriptionExpectError(const std::string& action,
739 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 SessionDescriptionInterface* desc) {
741 std::string error;
742 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 std::string sdp_type = "remote ";
744 sdp_type.append(action);
745 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 EXPECT_NE(std::string::npos, error.find(expected_error));
747 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 void SetRemoteDescriptionOfferExpectError(
749 const std::string& expected_error, SessionDescriptionInterface* desc) {
750 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
751 expected_error, desc);
752 }
753 void SetRemoteDescriptionPranswerExpectError(
754 const std::string& expected_error, SessionDescriptionInterface* desc) {
755 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
756 expected_error, desc);
757 }
758 void SetRemoteDescriptionAnswerExpectError(
759 const std::string& expected_error, SessionDescriptionInterface* desc) {
760 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
761 expected_error, desc);
762 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
765 SessionDescriptionInterface** nocrypto_answer) {
766 // Create a SDP without Crypto.
767 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000768 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 options.bundle_enabled = true;
770 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
771 ASSERT_TRUE(*offer != NULL);
772 VerifyCryptoParams((*offer)->description());
773
774 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
775 cricket::SEC_DISABLED);
776 EXPECT_TRUE(*nocrypto_answer != NULL);
777 }
778
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000779 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
780 SessionDescriptionInterface** nodtls_answer) {
781 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000782 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000783 options.bundle_enabled = true;
784
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000785 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000786 CreateRemoteOffer(options, cricket::SEC_ENABLED));
787
788 *nodtls_answer =
789 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
790 EXPECT_TRUE(*nodtls_answer != NULL);
791 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
792 VerifyCryptoParams((*nodtls_answer)->description());
793
794 SetFactoryDtlsSrtp();
795 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
796 ASSERT_TRUE(*offer != NULL);
797 VerifyFingerprintStatus((*offer)->description(), true);
798 VerifyCryptoParams((*offer)->description());
799 }
800
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 JsepSessionDescription* CreateRemoteOfferWithVersion(
802 cricket::MediaSessionOptions options,
803 cricket::SecurePolicy secure_policy,
804 const std::string& session_version,
805 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 const cricket::SessionDescription* cricket_desc = NULL;
808 if (current_desc) {
809 cricket_desc = current_desc->description();
810 session_id = current_desc->session_id();
811 }
812
813 desc_factory_->set_secure(secure_policy);
814 JsepSessionDescription* offer(
815 new JsepSessionDescription(JsepSessionDescription::kOffer));
816 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
817 session_id, session_version)) {
818 delete offer;
819 offer = NULL;
820 }
821 return offer;
822 }
823 JsepSessionDescription* CreateRemoteOffer(
824 cricket::MediaSessionOptions options) {
825 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
826 kSessionVersion, NULL);
827 }
828 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000829 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
830 return CreateRemoteOfferWithVersion(
831 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 }
833 JsepSessionDescription* CreateRemoteOffer(
834 cricket::MediaSessionOptions options,
835 const SessionDescriptionInterface* current_desc) {
836 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
837 kSessionVersion, current_desc);
838 }
839
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
841 const char* sctp_stream_name, int new_port,
842 cricket::MediaSessionOptions options) {
843 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000844 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
845 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000846 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
847 }
848
849 // Takes ownership of offer_basis (and deletes it).
850 JsepSessionDescription* ChangeSDPSctpPort(
851 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
852 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
853 // SessionDescription from the mutated string.
854 const char* default_port_str = "5000";
855 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000856 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000857 std::string offer_str;
858 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000859 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000860 new_port_str, strlen(new_port_str),
861 &offer_str);
862 JsepSessionDescription* offer = new JsepSessionDescription(
863 offer_basis->type());
864 delete offer_basis;
865 offer->Initialize(offer_str, NULL);
866 return offer;
867 }
868
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
870 // before this function to decide which streams to create.
871 JsepSessionDescription* CreateRemoteOffer() {
872 cricket::MediaSessionOptions options;
873 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
874 return CreateRemoteOffer(options, session_->remote_description());
875 }
876
877 JsepSessionDescription* CreateRemoteAnswer(
878 const SessionDescriptionInterface* offer,
879 cricket::MediaSessionOptions options,
880 cricket::SecurePolicy policy) {
881 desc_factory_->set_secure(policy);
882 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000883 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 JsepSessionDescription* answer(
885 new JsepSessionDescription(JsepSessionDescription::kAnswer));
886 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
887 options, NULL),
888 session_id, kSessionVersion)) {
889 delete answer;
890 answer = NULL;
891 }
892 return answer;
893 }
894
895 JsepSessionDescription* CreateRemoteAnswer(
896 const SessionDescriptionInterface* offer,
897 cricket::MediaSessionOptions options) {
898 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
899 }
900
901 // Creates an answer session description with streams based on
902 // |mediastream_signaling_|. Call
903 // mediastream_signaling_.UseOptionsWithStreamX() before this function
904 // to decide which streams to create.
905 JsepSessionDescription* CreateRemoteAnswer(
906 const SessionDescriptionInterface* offer) {
907 cricket::MediaSessionOptions options;
908 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
909 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
910 }
911
912 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000913 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000914 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000916
917 PeerConnectionInterface::RTCOfferAnswerOptions options;
918 options.use_rtp_mux = bundle;
919
920 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
922 // and answer.
923 SetLocalDescriptionWithoutError(offer);
924
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000925 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000926 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 std::string sdp;
928 EXPECT_TRUE(answer->ToString(&sdp));
929
930 size_t expected_candidate_num = 2;
931 if (!rtcp_mux) {
932 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
933 // for rtp and rtcp.
934 expected_candidate_num = 4;
935 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 const std::string kRtcpMux = "a=rtcp-mux";
937 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000938 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 kXRtcpMux.c_str(), kXRtcpMux.length(),
940 &sdp);
941 }
942
943 SessionDescriptionInterface* new_answer = CreateSessionDescription(
944 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945
946 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000947 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
949 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
950 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
951 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
952 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
953 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
954 if (bundle) {
955 EXPECT_TRUE(c0.IsEquivalent(c1));
956 } else {
957 EXPECT_FALSE(c0.IsEquivalent(c1));
958 }
959 }
960 }
961 // Tests that we can only send DTMF when the dtmf codec is supported.
962 void TestCanInsertDtmf(bool can) {
963 if (can) {
964 InitWithDtmfCodec();
965 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000966 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 }
968 mediastream_signaling_.SendAudioVideoStream1();
969 CreateAndSetRemoteOfferAndLocalAnswer();
970 EXPECT_FALSE(session_->CanInsertDtmf(""));
971 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
972 }
973
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000974 // Helper class to configure loopback network and verify Best
975 // Connection using right IP protocol for TestLoopbackCall
976 // method. LoopbackNetworkManager applies firewall rules to block
977 // all ping traffic once ICE completed, and remove them to observe
978 // ICE reconnected again. This LoopbackNetworkConfiguration struct
979 // verifies the best connection is using the right IP protocol after
980 // initial ICE convergences.
981
982 class LoopbackNetworkConfiguration {
983 public:
984 LoopbackNetworkConfiguration()
985 : test_ipv6_network_(false),
986 test_extra_ipv4_network_(false),
987 best_connection_after_initial_ice_converged_(1, 0) {}
988
989 // Used to track the expected best connection count in each IP protocol.
990 struct ExpectedBestConnection {
991 ExpectedBestConnection(int ipv4_count, int ipv6_count)
992 : ipv4_count_(ipv4_count),
993 ipv6_count_(ipv6_count) {}
994
995 int ipv4_count_;
996 int ipv6_count_;
997 };
998
999 bool test_ipv6_network_;
1000 bool test_extra_ipv4_network_;
1001 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1002
1003 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001004 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001005 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1006 }
1007
1008 private:
jbauchac8869e2015-07-03 01:36:14 -07001009 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001010 const ExpectedBestConnection& expected) const {
1011 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001012 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1013 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001014 expected.ipv4_count_);
1015 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001016 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1017 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001018 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001019 // This is used in the loopback call so there is only single host to host
1020 // candidate pair.
1021 EXPECT_EQ(metrics_observer->GetEnumCounter(
1022 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1023 webrtc::kIceCandidatePairHostHost),
1024 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001025 }
1026 };
1027
1028 class LoopbackNetworkManager {
1029 public:
1030 LoopbackNetworkManager(WebRtcSessionTest* session,
1031 const LoopbackNetworkConfiguration& config)
1032 : config_(config) {
1033 session->AddInterface(
1034 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1035 if (config_.test_extra_ipv4_network_) {
1036 session->AddInterface(
1037 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1038 }
1039 if (config_.test_ipv6_network_) {
1040 session->AddInterface(
1041 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1042 }
1043 }
1044
1045 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1046 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1047 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1048 if (config_.test_extra_ipv4_network_) {
1049 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1050 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1051 }
1052 if (config_.test_ipv6_network_) {
1053 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1054 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1055 }
1056 }
1057
1058 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1059
1060 private:
1061 LoopbackNetworkConfiguration config_;
1062 };
1063
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // The method sets up a call from the session to itself, in a loopback
1065 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001066 // disconnection, and then a permanent disconnection.
1067 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1069 // While running the call, this method also checks if the session goes through
1070 // the correct sequence of ICE states when a connection is established,
1071 // broken, and re-established.
1072 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001073 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1074 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001076
1077 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1078 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001079 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001081 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082
1083 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1084 observer_.ice_gathering_state_);
1085 SetLocalDescriptionWithoutError(offer);
1086 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1087 observer_.ice_connection_state_);
1088 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1089 observer_.ice_gathering_state_,
1090 kIceCandidatesTimeout);
1091 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1092 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1093 observer_.ice_gathering_state_,
1094 kIceCandidatesTimeout);
1095
1096 std::string sdp;
1097 offer->ToString(&sdp);
1098 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001099 webrtc::CreateSessionDescription(
1100 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 ASSERT_TRUE(desc != NULL);
1102 SetRemoteDescriptionWithoutError(desc);
1103
1104 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1105 observer_.ice_connection_state_,
1106 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001107
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001108 // The ice connection state is "Connected" too briefly to catch in a test.
1109 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 observer_.ice_connection_state_,
1111 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001113 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // Adding firewall rule to block ping requests, which should cause
1115 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001116
1117 loopback_network_manager.ApplyFirewallRules(fss_.get());
1118
1119 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1121 observer_.ice_connection_state_,
1122 kIceCandidatesTimeout);
1123
jbauchac8869e2015-07-03 01:36:14 -07001124 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001127 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 // Session is automatically calling OnSignalingReady after creation of
1129 // new portallocator session which will allocate new set of candidates.
1130
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001131 LOG(LS_INFO) << "Firewall Rules cleared";
1132
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001133 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 observer_.ice_connection_state_,
1135 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001136
1137 // Now we block ping requests and wait until the ICE connection transitions
1138 // to the Failed state. This will take at least 30 seconds because it must
1139 // wait for the Port to timeout.
1140 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001141
1142 loopback_network_manager.ApplyFirewallRules(fss_.get());
1143 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001144 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001145 observer_.ice_connection_state_,
1146 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 }
1148
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001149 void TestLoopbackCall() {
1150 LoopbackNetworkConfiguration config;
1151 TestLoopbackCall(config);
1152 }
1153
pthatcherfa301802015-08-11 04:12:56 -07001154 void VerifyTransportType(const std::string& content_name,
1155 cricket::TransportProtocol protocol) {
1156 const cricket::Transport* transport = session_->GetTransport(content_name);
1157 ASSERT_TRUE(transport != NULL);
1158 EXPECT_EQ(protocol, transport->protocol());
1159 }
1160
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1162 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001163 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1164 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1165
1166 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1168 codecs.push_back(kCNCodec1);
1169 codecs.push_back(kCNCodec2);
1170 media_engine_->SetAudioCodecs(codecs);
1171 desc_factory_->set_audio_codecs(codecs);
1172 }
1173
1174 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1175 const cricket::ContentDescription* description = content->description;
1176 ASSERT(description != NULL);
1177 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001178 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 ASSERT(audio_content_desc != NULL);
1180 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1181 if (audio_content_desc->codecs()[i].name == "CN")
1182 return false;
1183 }
1184 return true;
1185 }
1186
1187 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001188 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189 dci.reliable = false;
1190 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001191 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001192 SetLocalDescriptionWithoutError(offer);
1193 }
1194
wu@webrtc.org91053e72013-08-10 07:18:04 +00001195 void VerifyMultipleAsyncCreateDescription(
1196 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001197 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001198 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001199 if (type == CreateSessionDescriptionRequest::kAnswer) {
1200 cricket::MediaSessionOptions options;
1201 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001202 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 ASSERT_TRUE(offer.get() != NULL);
1204 SetRemoteDescriptionWithoutError(offer.release());
1205 }
1206
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001207 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001208 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001209 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001210 observers[kNumber];
1211 for (int i = 0; i < kNumber; ++i) {
1212 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1213 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001214 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001215 } else {
1216 session_->CreateAnswer(observers[i], NULL);
1217 }
1218 }
1219
1220 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1221 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1222 WebRtcSessionCreateSDPObserverForTest::kFailed;
1223
1224 for (int i = 0; i < kNumber; ++i) {
1225 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1226 if (success) {
1227 EXPECT_TRUE(observers[i]->description() != NULL);
1228 } else {
1229 EXPECT_TRUE(observers[i]->description() == NULL);
1230 }
1231 }
1232 }
1233
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001234 void ConfigureAllocatorWithTurn() {
1235 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1236 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1237 relay_server.credentials = credentials;
1238 relay_server.ports.push_back(cricket::ProtocolAddress(
1239 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1240 allocator_->AddRelay(relay_server);
1241 allocator_->set_step_delay(cricket::kMinimumStepDelay);
pthatcherfa301802015-08-11 04:12:56 -07001242 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1243 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001244 }
1245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 cricket::FakeMediaEngine* media_engine_;
1247 cricket::FakeDataEngine* data_engine_;
1248 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001249 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1250 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1251 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1252 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1253 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1254 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1255 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1256 rtc::SocketServerScope ss_scope_;
1257 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001258 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001259 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001260 rtc::FakeNetworkManager network_manager_;
1261 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001262 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001263 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001265 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 MockIceObserver observer_;
1267 cricket::FakeVideoMediaChannel* video_channel_;
1268 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001269 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270};
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1273 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001274 // SDES is disabled when DTLS is on.
1275 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276}
1277
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001278TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001279 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001280 // SDES is required if DTLS is off.
1281 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001282}
1283
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1285 TestSessionCandidatesWithBundleRtcpMux(false, false);
1286}
1287
1288// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1289// with rtcp-mux and/or bundle.
1290TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1291 TestSessionCandidatesWithBundleRtcpMux(false, true);
1292}
1293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1295 TestSessionCandidatesWithBundleRtcpMux(true, true);
1296}
1297
1298TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001299 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1300 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001301 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 mediastream_signaling_.SendAudioVideoStream1();
1303 InitiateCall();
1304 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1305 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1306 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1307}
1308
1309TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001310 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1311 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001312 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001313 rtc::FP_UDP,
1314 rtc::FD_ANY,
1315 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001316 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 mediastream_signaling_.SendAudioVideoStream1();
1318 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001319 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1321 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1322 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1323}
1324
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001325// Test session delivers no candidates gathered when constraint set to "none".
1326TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1327 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001328 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001329 mediastream_signaling_.SendAudioVideoStream1();
1330 InitiateCall();
1331 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1332 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1333 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1334}
1335
1336// Test session delivers only relay candidates gathered when constaint set to
1337// "relay".
1338TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1339 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1340 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001341 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001342 mediastream_signaling_.SendAudioVideoStream1();
1343 InitiateCall();
1344 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1345 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1346 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1347 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1348 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1349 observer_.mline_0_candidates_[i].type());
1350 }
1351 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1352 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1353 observer_.mline_1_candidates_[i].type());
1354 }
1355}
1356
1357// Test session delivers all candidates gathered when constaint set to "all".
1358TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1359 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001360 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001361 mediastream_signaling_.SendAudioVideoStream1();
1362 InitiateCall();
1363 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1364 // Host + STUN. By default allocator is disabled to gather relay candidates.
1365 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1366 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1367}
1368
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001369TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001370 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001371 SessionDescriptionInterface* offer = NULL;
1372 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1373 std::string unknown_action;
1374 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1375 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1376}
1377
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378// Test creating offers and receive answers and make sure the
1379// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001380TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001381 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001383 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 const std::string session_id_orig = offer->session_id();
1385 const std::string session_version_orig = offer->session_version();
1386 SetLocalDescriptionWithoutError(offer);
1387
1388 mediastream_signaling_.SendAudioVideoStream2();
1389 SessionDescriptionInterface* answer =
1390 CreateRemoteAnswer(session_->local_description());
1391 SetRemoteDescriptionWithoutError(answer);
1392
1393 video_channel_ = media_engine_->GetVideoChannel(0);
1394 voice_channel_ = media_engine_->GetVoiceChannel(0);
1395
1396 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1397 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1398
1399 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1400 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1401
1402 ASSERT_EQ(1u, video_channel_->send_streams().size());
1403 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1404 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1405 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1406
1407 // Create new offer without send streams.
1408 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001409 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410
1411 // Verify the session id is the same and the session version is
1412 // increased.
1413 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001414 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1415 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416
1417 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001418 EXPECT_EQ(0u, video_channel_->send_streams().size());
1419 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420
1421 mediastream_signaling_.SendAudioVideoStream2();
1422 answer = CreateRemoteAnswer(session_->local_description());
1423 SetRemoteDescriptionWithoutError(answer);
1424
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 // Make sure the receive streams have not changed.
1426 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1427 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1428 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1429 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1430}
1431
1432// Test receiving offers and creating answers and make sure the
1433// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001434TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001435 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001437 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001438 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 SetRemoteDescriptionWithoutError(offer);
1440
1441 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001442 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001443 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 SetLocalDescriptionWithoutError(answer);
1445
1446 const std::string session_id_orig = answer->session_id();
1447 const std::string session_version_orig = answer->session_version();
1448
1449 video_channel_ = media_engine_->GetVideoChannel(0);
1450 voice_channel_ = media_engine_->GetVoiceChannel(0);
1451
1452 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1453 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1454
1455 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1456 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1457
1458 ASSERT_EQ(1u, video_channel_->send_streams().size());
1459 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1460 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1461 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1462
1463 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001464 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SetRemoteDescriptionWithoutError(offer);
1466
1467 // Answer by turning off all send streams.
1468 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001469 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470
1471 // Verify the session id is the same and the session version is
1472 // increased.
1473 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001474 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1475 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 SetLocalDescriptionWithoutError(answer);
1477
1478 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1479 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1480 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1481 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1482 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1483 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1484
1485 // Make sure we have no send streams.
1486 EXPECT_EQ(0u, video_channel_->send_streams().size());
1487 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1488}
1489
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001490TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001491 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001492 media_engine_->set_fail_create_channel(true);
1493
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001494 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001495 ASSERT_TRUE(offer != NULL);
1496 // SetRemoteDescription and SetLocalDescription will take the ownership of
1497 // the offer.
1498 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001499 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001500 ASSERT_TRUE(offer != NULL);
1501 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1502}
1503
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001504//
1505// Tests for creating/setting SDP under different SDES/DTLS polices:
1506//
1507// --DTLS off and SDES on
1508// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1509// set local/remote offer/answer with crypto --> success
1510// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1511// failure
1512// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1513// failure
1514// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1515// failure
1516//
1517// --DTLS on and SDES off
1518// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1519// set local/remote offer/answer with DTLS fingerprint --> success
1520// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1521// fingerprint --> failure
1522// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1523// --> failure
1524// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1525// --> failure
1526//
1527// --Encryption disabled: DTLS off and SDES off
1528// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1529// answer without SDES or DTLS --> success
1530// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1531// answer without SDES or DTLS --> success
1532//
1533
1534// Test that we return a failure when applying a remote/local offer that doesn't
1535// have cryptos enabled when DTLS is off.
1536TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001537 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001539 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 JsepSessionDescription* offer = CreateRemoteOffer(
1541 options, cricket::SEC_DISABLED);
1542 ASSERT_TRUE(offer != NULL);
1543 VerifyNoCryptoParams(offer->description(), false);
1544 // SetRemoteDescription and SetLocalDescription will take the ownership of
1545 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001546 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1548 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001549 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550}
1551
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001552// Test that we return a failure when applying a local answer that doesn't have
1553// cryptos enabled when DTLS is off.
1554TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001555 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 SessionDescriptionInterface* offer = NULL;
1557 SessionDescriptionInterface* answer = NULL;
1558 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1559 // SetRemoteDescription and SetLocalDescription will take the ownership of
1560 // the offer.
1561 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001562 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563}
1564
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001565// Test we will return fail when apply an remote answer that doesn't have
1566// crypto enabled when DTLS is off.
1567TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001568 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 SessionDescriptionInterface* offer = NULL;
1570 SessionDescriptionInterface* answer = NULL;
1571 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1572 // SetRemoteDescription and SetLocalDescription will take the ownership of
1573 // the offer.
1574 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001575 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576}
1577
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001578// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1579// and that we return an answer with a DTLS fingerprint.
1580TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001581 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 InitWithDtls();
1584 SetFactoryDtlsSrtp();
1585 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001586 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001587 JsepSessionDescription* offer =
1588 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 ASSERT_TRUE(offer != NULL);
1590 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
1593 // SetRemoteDescription will take the ownership of the offer.
1594 SetRemoteDescriptionWithoutError(offer);
1595
1596 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001597 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 ASSERT_TRUE(answer != NULL);
1599 VerifyFingerprintStatus(answer->description(), true);
1600 // Check that we don't have an a=crypto line in the answer.
1601 VerifyNoCryptoParams(answer->description(), true);
1602
1603 // Now set the local description, which should work, even without a=crypto.
1604 SetLocalDescriptionWithoutError(answer);
1605}
1606
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001607// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1608// and then we accept a remote answer with a DTLS fingerprint successfully.
1609TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001610 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001611 mediastream_signaling_.SendAudioVideoStream1();
1612 InitWithDtls();
1613 SetFactoryDtlsSrtp();
1614
1615 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001616 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 ASSERT_TRUE(offer != NULL);
1618 VerifyFingerprintStatus(offer->description(), true);
1619 // Check that we don't have an a=crypto line in the offer.
1620 VerifyNoCryptoParams(offer->description(), true);
1621
1622 // Now set the local description, which should work, even without a=crypto.
1623 SetLocalDescriptionWithoutError(offer);
1624
1625 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001626 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001627 JsepSessionDescription* answer =
1628 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1629 ASSERT_TRUE(answer != NULL);
1630 VerifyFingerprintStatus(answer->description(), true);
1631 VerifyNoCryptoParams(answer->description(), true);
1632
1633 // SetRemoteDescription will take the ownership of the answer.
1634 SetRemoteDescriptionWithoutError(answer);
1635}
1636
1637// Test that if we support DTLS and the other side didn't offer a fingerprint,
1638// we will fail to set the remote description.
1639TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001640 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 InitWithDtls();
1642 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001643 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001644 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 JsepSessionDescription* offer = CreateRemoteOffer(
1646 options, cricket::SEC_REQUIRED);
1647 ASSERT_TRUE(offer != NULL);
1648 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001649 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651 // SetRemoteDescription will take the ownership of the offer.
1652 SetRemoteDescriptionOfferExpectError(
1653 kSdpWithoutDtlsFingerprint, offer);
1654
1655 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1656 // SetLocalDescription will take the ownership of the offer.
1657 SetLocalDescriptionOfferExpectError(
1658 kSdpWithoutDtlsFingerprint, offer);
1659}
1660
1661// Test that we return a failure when applying a local answer that doesn't have
1662// a DTLS fingerprint when DTLS is required.
1663TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001664 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001665 InitWithDtls();
1666 SessionDescriptionInterface* offer = NULL;
1667 SessionDescriptionInterface* answer = NULL;
1668 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1669
1670 // SetRemoteDescription and SetLocalDescription will take the ownership of
1671 // the offer and answer.
1672 SetRemoteDescriptionWithoutError(offer);
1673 SetLocalDescriptionAnswerExpectError(
1674 kSdpWithoutDtlsFingerprint, answer);
1675}
1676
1677// Test that we return a failure when applying a remote answer that doesn't have
1678// a DTLS fingerprint when DTLS is required.
1679TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001680 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001681 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1682 // result of using the "UDP/TLS/RTP/SAVPF" profile.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001683 InitWithDtls();
deadbeeff3938292015-07-15 12:20:53 -07001684 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001685 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001686 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001687 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001688 JsepSessionDescription* answer =
1689 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1690
1691 // SetRemoteDescription and SetLocalDescription will take the ownership of
1692 // the offer and answer.
1693 SetLocalDescriptionWithoutError(offer);
1694 SetRemoteDescriptionAnswerExpectError(
1695 kSdpWithoutDtlsFingerprint, answer);
1696}
1697
1698// Test that we create a local offer without SDES or DTLS and accept a remote
1699// answer without SDES or DTLS when encryption is disabled.
1700TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1701 mediastream_signaling_.SendAudioVideoStream1();
1702 options_.disable_encryption = true;
1703 InitWithDtls();
1704
1705 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001706 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001707 ASSERT_TRUE(offer != NULL);
1708 VerifyFingerprintStatus(offer->description(), false);
1709 // Check that we don't have an a=crypto line in the offer.
1710 VerifyNoCryptoParams(offer->description(), false);
1711
1712 // Now set the local description, which should work, even without a=crypto.
1713 SetLocalDescriptionWithoutError(offer);
1714
1715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001716 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001717 JsepSessionDescription* answer =
1718 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1719 ASSERT_TRUE(answer != NULL);
1720 VerifyFingerprintStatus(answer->description(), false);
1721 VerifyNoCryptoParams(answer->description(), false);
1722
1723 // SetRemoteDescription will take the ownership of the answer.
1724 SetRemoteDescriptionWithoutError(answer);
1725}
1726
1727// Test that we create a local answer without SDES or DTLS and accept a remote
1728// offer without SDES or DTLS when encryption is disabled.
1729TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1730 options_.disable_encryption = true;
1731 InitWithDtls();
1732
1733 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001734 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001735 JsepSessionDescription* offer =
1736 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1737 ASSERT_TRUE(offer != NULL);
1738 VerifyFingerprintStatus(offer->description(), false);
1739 VerifyNoCryptoParams(offer->description(), false);
1740
1741 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 SetRemoteDescriptionWithoutError(offer);
1743
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001745 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 ASSERT_TRUE(answer != NULL);
1747 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001748 // Check that we don't have an a=crypto line in the answer.
1749 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001751 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 SetLocalDescriptionWithoutError(answer);
1753}
1754
1755TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001756 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 mediastream_signaling_.SendNothing();
1758 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001759 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 SetLocalDescriptionWithoutError(offer);
1761
1762 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001763 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 SetLocalDescriptionWithoutError(offer2);
1765}
1766
1767TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001768 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 mediastream_signaling_.SendNothing();
1770 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001771 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 SetRemoteDescriptionWithoutError(offer);
1773
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001774 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 SetRemoteDescriptionWithoutError(offer2);
1776}
1777
1778TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001779 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001781 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001783 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001784 SetRemoteDescriptionOfferExpectError(
1785 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786}
1787
1788TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001789 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001791 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001793 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001794 SetLocalDescriptionOfferExpectError(
1795 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796}
1797
1798TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001799 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 mediastream_signaling_.SendNothing();
1801 SessionDescriptionInterface* offer = CreateRemoteOffer();
1802 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1803
1804 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001805 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1807 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1808
1809 mediastream_signaling_.SendAudioVideoStream1();
1810 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001811 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1813
1814 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1815
1816 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001817 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1819}
1820
1821TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001822 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001824 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1826
1827 JsepSessionDescription* pranswer =
1828 CreateRemoteAnswer(session_->local_description());
1829 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1830
1831 SetRemoteDescriptionExpectState(pranswer,
1832 BaseSession::STATE_RECEIVEDPRACCEPT);
1833
1834 mediastream_signaling_.SendAudioVideoStream1();
1835 JsepSessionDescription* pranswer2 =
1836 CreateRemoteAnswer(session_->local_description());
1837 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1838
1839 SetRemoteDescriptionExpectState(pranswer2,
1840 BaseSession::STATE_RECEIVEDPRACCEPT);
1841
1842 mediastream_signaling_.SendAudioVideoStream2();
1843 SessionDescriptionInterface* answer =
1844 CreateRemoteAnswer(session_->local_description());
1845 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1846}
1847
1848TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001849 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001851 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1852
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 SessionDescriptionInterface* answer =
1854 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001855 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1856 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857}
1858
1859TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001860 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001862 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1863
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 SessionDescriptionInterface* answer =
1865 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001866 SetRemoteDescriptionAnswerExpectError(
1867 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868}
1869
1870TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001871 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 mediastream_signaling_.SendAudioVideoStream1();
1873
1874 cricket::Candidate candidate;
1875 candidate.set_component(1);
1876 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1877
1878 // Fail since we have not set a offer description.
1879 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1880
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001881 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 SetLocalDescriptionWithoutError(offer);
1883 // Candidate should be allowed to add before remote description.
1884 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1885 candidate.set_component(2);
1886 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1887 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1888
1889 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1890 session_->local_description());
1891 SetRemoteDescriptionWithoutError(answer);
1892
1893 // Verifying the candidates are copied properly from internal vector.
1894 const SessionDescriptionInterface* remote_desc =
1895 session_->remote_description();
1896 ASSERT_TRUE(remote_desc != NULL);
1897 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1898 const IceCandidateCollection* candidates =
1899 remote_desc->candidates(kMediaContentIndex0);
1900 ASSERT_EQ(2u, candidates->count());
1901 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1902 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1903 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1904 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1905
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001906 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1907 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 candidate.set_component(2);
1909 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1910 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001911 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912
1913 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1914 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1915}
1916
1917// Test that a remote candidate is added to the remote session description and
1918// that it is retained if the remote session description is changed.
1919TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001920 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921 cricket::Candidate candidate1;
1922 candidate1.set_component(1);
1923 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1924 candidate1);
1925 mediastream_signaling_.SendAudioVideoStream1();
1926 CreateAndSetRemoteOfferAndLocalAnswer();
1927
1928 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1929 const SessionDescriptionInterface* remote_desc =
1930 session_->remote_description();
1931 ASSERT_TRUE(remote_desc != NULL);
1932 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1933 const IceCandidateCollection* candidates =
1934 remote_desc->candidates(kMediaContentIndex0);
1935 ASSERT_EQ(1u, candidates->count());
1936 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1937
1938 // Update the RemoteSessionDescription with a new session description and
1939 // a candidate and check that the new remote session description contains both
1940 // candidates.
1941 SessionDescriptionInterface* offer = CreateRemoteOffer();
1942 cricket::Candidate candidate2;
1943 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1944 candidate2);
1945 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1946 SetRemoteDescriptionWithoutError(offer);
1947
1948 remote_desc = session_->remote_description();
1949 ASSERT_TRUE(remote_desc != NULL);
1950 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1951 candidates = remote_desc->candidates(kMediaContentIndex0);
1952 ASSERT_EQ(2u, candidates->count());
1953 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1954 // Username and password have be updated with the TransportInfo of the
1955 // SessionDescription, won't be equal to the original one.
1956 candidate2.set_username(candidates->at(0)->candidate().username());
1957 candidate2.set_password(candidates->at(0)->candidate().password());
1958 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1959 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1960 // No need to verify the username and password.
1961 candidate1.set_username(candidates->at(1)->candidate().username());
1962 candidate1.set_password(candidates->at(1)->candidate().password());
1963 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1964
1965 // Test that the candidate is ignored if we can add the same candidate again.
1966 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1967}
1968
1969// Test that local candidates are added to the local session description and
1970// that they are retained if the local session description is changed.
1971TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001972 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001973 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 mediastream_signaling_.SendAudioVideoStream1();
1975 CreateAndSetRemoteOfferAndLocalAnswer();
1976
1977 const SessionDescriptionInterface* local_desc = session_->local_description();
1978 const IceCandidateCollection* candidates =
1979 local_desc->candidates(kMediaContentIndex0);
1980 ASSERT_TRUE(candidates != NULL);
1981 EXPECT_EQ(0u, candidates->count());
1982
1983 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1984
1985 local_desc = session_->local_description();
1986 candidates = local_desc->candidates(kMediaContentIndex0);
1987 ASSERT_TRUE(candidates != NULL);
1988 EXPECT_LT(0u, candidates->count());
1989 candidates = local_desc->candidates(1);
1990 ASSERT_TRUE(candidates != NULL);
1991 EXPECT_LT(0u, candidates->count());
1992
1993 // Update the session descriptions.
1994 mediastream_signaling_.SendAudioVideoStream1();
1995 CreateAndSetRemoteOfferAndLocalAnswer();
1996
1997 local_desc = session_->local_description();
1998 candidates = local_desc->candidates(kMediaContentIndex0);
1999 ASSERT_TRUE(candidates != NULL);
2000 EXPECT_LT(0u, candidates->count());
2001 candidates = local_desc->candidates(1);
2002 ASSERT_TRUE(candidates != NULL);
2003 EXPECT_LT(0u, candidates->count());
2004}
2005
2006// Test that we can set a remote session description with remote candidates.
2007TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002008 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009
2010 cricket::Candidate candidate1;
2011 candidate1.set_component(1);
2012 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2013 candidate1);
2014 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016
2017 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2018 SetRemoteDescriptionWithoutError(offer);
2019
2020 const SessionDescriptionInterface* remote_desc =
2021 session_->remote_description();
2022 ASSERT_TRUE(remote_desc != NULL);
2023 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2024 const IceCandidateCollection* candidates =
2025 remote_desc->candidates(kMediaContentIndex0);
2026 ASSERT_EQ(1u, candidates->count());
2027 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2028
wu@webrtc.org91053e72013-08-10 07:18:04 +00002029 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 SetLocalDescriptionWithoutError(answer);
2031}
2032
2033// Test that offers and answers contains ice candidates when Ice candidates have
2034// been gathered.
2035TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002036 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002037 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 mediastream_signaling_.SendAudioVideoStream1();
2039 // Ice is started but candidates are not provided until SetLocalDescription
2040 // is called.
2041 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2042 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2043 CreateAndSetRemoteOfferAndLocalAnswer();
2044 // Wait until at least one local candidate has been collected.
2045 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2046 kIceCandidatesTimeout);
2047 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2048 kIceCandidatesTimeout);
2049
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002050 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2053 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2054 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2055 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2056
2057 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2058 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002059 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2061 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2062 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2063 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2064 SetLocalDescriptionWithoutError(answer);
2065}
2066
2067// Verifies TransportProxy and media channels are created with content names
2068// present in the SessionDescription.
2069TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002070 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002072 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073
2074 // CreateOffer creates session description with the content names "audio" and
2075 // "video". Goal is to modify these content names and verify transport channel
2076 // proxy in the BaseSession, as proxies are created with the content names
2077 // present in SDP.
2078 std::string sdp;
2079 EXPECT_TRUE(offer->ToString(&sdp));
2080 const std::string kAudioMid = "a=mid:audio";
2081 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2082 const std::string kVideoMid = "a=mid:video";
2083 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2084
2085 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002086 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 kAudioMidReplaceStr.c_str(),
2088 kAudioMidReplaceStr.length(),
2089 &sdp);
2090 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002091 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 kVideoMidReplaceStr.c_str(),
2093 kVideoMidReplaceStr.length(),
2094 &sdp);
2095
2096 SessionDescriptionInterface* modified_offer =
2097 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2098
2099 SetRemoteDescriptionWithoutError(modified_offer);
2100
2101 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002102 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SetLocalDescriptionWithoutError(answer);
2104
2105 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2106 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2107 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2108 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2109}
2110
2111// Test that an offer contains the correct media content descriptions based on
2112// the send streams when no constraints have been set.
2113TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002114 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002115 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2116
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 ASSERT_TRUE(offer != NULL);
2118 const cricket::ContentInfo* content =
2119 cricket::GetFirstAudioContent(offer->description());
2120 EXPECT_TRUE(content != NULL);
2121 content = cricket::GetFirstVideoContent(offer->description());
2122 EXPECT_TRUE(content == NULL);
2123}
2124
2125// Test that an offer contains the correct media content descriptions based on
2126// the send streams when no constraints have been set.
2127TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002128 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 // Test Audio only offer.
2130 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002131 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2132
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 const cricket::ContentInfo* content =
2134 cricket::GetFirstAudioContent(offer->description());
2135 EXPECT_TRUE(content != NULL);
2136 content = cricket::GetFirstVideoContent(offer->description());
2137 EXPECT_TRUE(content == NULL);
2138
2139 // Test Audio / Video offer.
2140 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002141 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 content = cricket::GetFirstAudioContent(offer->description());
2143 EXPECT_TRUE(content != NULL);
2144 content = cricket::GetFirstVideoContent(offer->description());
2145 EXPECT_TRUE(content != NULL);
2146}
2147
2148// Test that an offer contains no media content descriptions if
2149// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2150TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002151 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002152 PeerConnectionInterface::RTCOfferAnswerOptions options;
2153 options.offer_to_receive_audio = 0;
2154 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002156 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002157 CreateOffer(options));
2158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 ASSERT_TRUE(offer != NULL);
2160 const cricket::ContentInfo* content =
2161 cricket::GetFirstAudioContent(offer->description());
2162 EXPECT_TRUE(content == NULL);
2163 content = cricket::GetFirstVideoContent(offer->description());
2164 EXPECT_TRUE(content == NULL);
2165}
2166
2167// Test that an offer contains only audio media content descriptions if
2168// kOfferToReceiveAudio constraints are set to true.
2169TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002170 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002171 PeerConnectionInterface::RTCOfferAnswerOptions options;
2172 options.offer_to_receive_audio =
2173 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2174
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002175 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002176 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177
2178 const cricket::ContentInfo* content =
2179 cricket::GetFirstAudioContent(offer->description());
2180 EXPECT_TRUE(content != NULL);
2181 content = cricket::GetFirstVideoContent(offer->description());
2182 EXPECT_TRUE(content == NULL);
2183}
2184
2185// Test that an offer contains audio and video media content descriptions if
2186// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2187TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002188 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002190 PeerConnectionInterface::RTCOfferAnswerOptions options;
2191 options.offer_to_receive_audio =
2192 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2193 options.offer_to_receive_video =
2194 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2195
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002196 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002197 CreateOffer(options));
2198
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 const cricket::ContentInfo* content =
2200 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002201 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 content = cricket::GetFirstVideoContent(offer->description());
2204 EXPECT_TRUE(content != NULL);
2205
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002206 // Sets constraints to false and verifies that audio/video contents are
2207 // removed.
2208 options.offer_to_receive_audio = 0;
2209 options.offer_to_receive_video = 0;
2210 offer.reset(CreateOffer(options));
2211
2212 content = cricket::GetFirstAudioContent(offer->description());
2213 EXPECT_TRUE(content == NULL);
2214 content = cricket::GetFirstVideoContent(offer->description());
2215 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216}
2217
2218// Test that an answer can not be created if the last remote description is not
2219// an offer.
2220TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002221 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002222 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 SetLocalDescriptionWithoutError(offer);
2224 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2225 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002226 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227}
2228
2229// Test that an answer contains the correct media content descriptions when no
2230// constraints have been set.
2231TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002232 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002234 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002236 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002237 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 const cricket::ContentInfo* content =
2239 cricket::GetFirstAudioContent(answer->description());
2240 ASSERT_TRUE(content != NULL);
2241 EXPECT_FALSE(content->rejected);
2242
2243 content = cricket::GetFirstVideoContent(answer->description());
2244 ASSERT_TRUE(content != NULL);
2245 EXPECT_FALSE(content->rejected);
2246}
2247
2248// Test that an answer contains the correct media content descriptions when no
2249// constraints have been set and the offer only contain audio.
2250TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002251 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 // Create a remote offer with audio only.
2253 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002254
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002255 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 CreateRemoteOffer(options));
2257 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2258 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2259
2260 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002262 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 const cricket::ContentInfo* content =
2264 cricket::GetFirstAudioContent(answer->description());
2265 ASSERT_TRUE(content != NULL);
2266 EXPECT_FALSE(content->rejected);
2267
2268 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2269}
2270
2271// Test that an answer contains the correct media content descriptions when no
2272// constraints have been set.
2273TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002274 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002276 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 SetRemoteDescriptionWithoutError(offer.release());
2278 // Test with a stream with tracks.
2279 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002281 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 const cricket::ContentInfo* content =
2283 cricket::GetFirstAudioContent(answer->description());
2284 ASSERT_TRUE(content != NULL);
2285 EXPECT_FALSE(content->rejected);
2286
2287 content = cricket::GetFirstVideoContent(answer->description());
2288 ASSERT_TRUE(content != NULL);
2289 EXPECT_FALSE(content->rejected);
2290}
2291
2292// Test that an answer contains the correct media content descriptions when
2293// constraints have been set but no stream is sent.
2294TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002295 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002297 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 SetRemoteDescriptionWithoutError(offer.release());
2299
2300 webrtc::FakeConstraints constraints_no_receive;
2301 constraints_no_receive.SetMandatoryReceiveAudio(false);
2302 constraints_no_receive.SetMandatoryReceiveVideo(false);
2303
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002304 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002305 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 const cricket::ContentInfo* content =
2307 cricket::GetFirstAudioContent(answer->description());
2308 ASSERT_TRUE(content != NULL);
2309 EXPECT_TRUE(content->rejected);
2310
2311 content = cricket::GetFirstVideoContent(answer->description());
2312 ASSERT_TRUE(content != NULL);
2313 EXPECT_TRUE(content->rejected);
2314}
2315
2316// Test that an answer contains the correct media content descriptions when
2317// constraints have been set and streams are sent.
2318TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002319 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002321 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 SetRemoteDescriptionWithoutError(offer.release());
2323
2324 webrtc::FakeConstraints constraints_no_receive;
2325 constraints_no_receive.SetMandatoryReceiveAudio(false);
2326 constraints_no_receive.SetMandatoryReceiveVideo(false);
2327
2328 // Test with a stream with tracks.
2329 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002331 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332
2333 // TODO(perkj): Should the direction be set to SEND_ONLY?
2334 const cricket::ContentInfo* content =
2335 cricket::GetFirstAudioContent(answer->description());
2336 ASSERT_TRUE(content != NULL);
2337 EXPECT_FALSE(content->rejected);
2338
2339 // TODO(perkj): Should the direction be set to SEND_ONLY?
2340 content = cricket::GetFirstVideoContent(answer->description());
2341 ASSERT_TRUE(content != NULL);
2342 EXPECT_FALSE(content->rejected);
2343}
2344
2345TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2346 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002347 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002348 PeerConnectionInterface::RTCOfferAnswerOptions options;
2349 options.offer_to_receive_audio =
2350 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2351 options.voice_activity_detection = false;
2352
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002353 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002354 CreateOffer(options));
2355
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 const cricket::ContentInfo* content =
2357 cricket::GetFirstAudioContent(offer->description());
2358 EXPECT_TRUE(content != NULL);
2359 EXPECT_TRUE(VerifyNoCNCodecs(content));
2360}
2361
2362TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2363 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002364 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002366 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 SetRemoteDescriptionWithoutError(offer.release());
2368
2369 webrtc::FakeConstraints constraints;
2370 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002371 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002372 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 const cricket::ContentInfo* content =
2374 cricket::GetFirstAudioContent(answer->description());
2375 ASSERT_TRUE(content != NULL);
2376 EXPECT_TRUE(VerifyNoCNCodecs(content));
2377}
2378
2379// This test verifies the call setup when remote answer with audio only and
2380// later updates with video.
2381TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002382 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2384 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2385
2386 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002387 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
2389 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2391
2392 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2393 // and answer;
2394 SetLocalDescriptionWithoutError(offer);
2395 SetRemoteDescriptionWithoutError(answer);
2396
2397 video_channel_ = media_engine_->GetVideoChannel(0);
2398 voice_channel_ = media_engine_->GetVoiceChannel(0);
2399
2400 ASSERT_TRUE(video_channel_ == NULL);
2401
2402 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2403 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2404 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2405
2406 // Let the remote end update the session descriptions, with Audio and Video.
2407 mediastream_signaling_.SendAudioVideoStream2();
2408 CreateAndSetRemoteOfferAndLocalAnswer();
2409
2410 video_channel_ = media_engine_->GetVideoChannel(0);
2411 voice_channel_ = media_engine_->GetVoiceChannel(0);
2412
2413 ASSERT_TRUE(video_channel_ != NULL);
2414 ASSERT_TRUE(voice_channel_ != NULL);
2415
2416 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2417 ASSERT_EQ(1u, video_channel_->send_streams().size());
2418 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2419 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2420 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2421 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2422 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2423 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2424
2425 // Change session back to audio only.
2426 mediastream_signaling_.UseOptionsAudioOnly();
2427 CreateAndSetRemoteOfferAndLocalAnswer();
2428
2429 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2430 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2431 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2432 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2433 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2434}
2435
2436// This test verifies the call setup when remote answer with video only and
2437// later updates with audio.
2438TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002439 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2441 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2442 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002443 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444
2445 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002446 options.recv_audio = false;
2447 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2449 offer, options, cricket::SEC_ENABLED);
2450
2451 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2452 // and answer.
2453 SetLocalDescriptionWithoutError(offer);
2454 SetRemoteDescriptionWithoutError(answer);
2455
2456 video_channel_ = media_engine_->GetVideoChannel(0);
2457 voice_channel_ = media_engine_->GetVoiceChannel(0);
2458
2459 ASSERT_TRUE(voice_channel_ == NULL);
2460 ASSERT_TRUE(video_channel_ != NULL);
2461
2462 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2463 ASSERT_EQ(1u, video_channel_->send_streams().size());
2464 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2465
2466 // Update the session descriptions, with Audio and Video.
2467 mediastream_signaling_.SendAudioVideoStream2();
2468 CreateAndSetRemoteOfferAndLocalAnswer();
2469
2470 voice_channel_ = media_engine_->GetVoiceChannel(0);
2471 ASSERT_TRUE(voice_channel_ != NULL);
2472
2473 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2474 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2475 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2476 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2477
2478 // Change session back to video only.
2479 mediastream_signaling_.UseOptionsVideoOnly();
2480 CreateAndSetRemoteOfferAndLocalAnswer();
2481
2482 video_channel_ = media_engine_->GetVideoChannel(0);
2483 voice_channel_ = media_engine_->GetVoiceChannel(0);
2484
2485 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2486 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2487 ASSERT_EQ(1u, video_channel_->send_streams().size());
2488 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2489}
2490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002494 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 VerifyCryptoParams(offer->description());
2496 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002497 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 VerifyCryptoParams(answer->description());
2499}
2500
2501TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002502 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002503 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002505 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 VerifyNoCryptoParams(offer->description(), false);
2507}
2508
2509TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002510 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 VerifyAnswerFromNonCryptoOffer();
2512}
2513
2514TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002515 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 VerifyAnswerFromCryptoOffer();
2517}
2518
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002519// This test verifies that setLocalDescription fails if
2520// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2521TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002523 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2525
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002526 std::string sdp;
2527 RemoveIceUfragPwdLines(offer.get(), &sdp);
2528 SessionDescriptionInterface* modified_offer =
2529 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002530 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002531}
2532
2533// This test verifies that setRemoteDescription fails if
2534// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2535TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002536 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002537 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002538 std::string sdp;
2539 RemoveIceUfragPwdLines(offer.get(), &sdp);
2540 SessionDescriptionInterface* modified_offer =
2541 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002542 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002543}
2544
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002545// This test verifies that setLocalDescription fails if local offer has
2546// too short ice ufrag and pwd strings.
2547TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002548 Init();
pthatcherfa301802015-08-11 04:12:56 -07002549 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002550 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002551 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2552
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002553 std::string sdp;
2554 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2555 // recommended values of 4 and 22 bytes respectively.
2556 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2557 SessionDescriptionInterface* modified_offer =
2558 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2559 std::string error;
2560 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2561
2562 // Test with string greater than 256.
2563 sdp.clear();
2564 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2565 &sdp);
2566 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2567 NULL);
2568 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2569}
2570
2571// This test verifies that setRemoteDescription fails if remote offer has
2572// too short ice ufrag and pwd strings.
2573TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
pthatcherfa301802015-08-11 04:12:56 -07002575 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002576 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002577 std::string sdp;
2578 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2579 // recommended values of 4 and 22 bytes respectively.
2580 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2581 SessionDescriptionInterface* modified_offer =
2582 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2583 std::string error;
2584 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2585
2586 sdp.clear();
2587 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2588 &sdp);
2589 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2590 NULL);
2591 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2592}
2593
honghaiz503726c2015-07-31 12:37:38 -07002594// Test that if the remote description indicates the peer requested ICE restart
2595// (via a new ufrag or pwd), the old ICE candidates are not copied,
2596// and vice versa.
2597TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2598 Init();
2599 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2600
2601 // Create the first offer.
2602 std::string sdp;
2603 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2604 "abcdefghijklmnopqrstuvwx", &sdp);
2605 SessionDescriptionInterface* offer1 =
2606 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2607 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2608 0, "", "", "relay", 0, "");
2609 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2610 candidate1);
2611 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2612 SetRemoteDescriptionWithoutError(offer1);
2613 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2614
2615 // The second offer has the same ufrag and pwd but different address.
2616 sdp.clear();
2617 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2618 "abcdefghijklmnopqrstuvwx", &sdp);
2619 SessionDescriptionInterface* offer2 =
2620 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2621 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2622 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2623 candidate1);
2624 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2625 SetRemoteDescriptionWithoutError(offer2);
2626 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2627
2628 // The third offer has a different ufrag and different address.
2629 sdp.clear();
2630 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2631 "abcdefghijklmnopqrstuvwx", &sdp);
2632 SessionDescriptionInterface* offer3 =
2633 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2634 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2635 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2636 candidate1);
2637 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2638 SetRemoteDescriptionWithoutError(offer3);
2639 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2640
2641 // The fourth offer has no candidate but a different ufrag/pwd.
2642 sdp.clear();
2643 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2644 "abcdefghijklmnopqrstuvyz", &sdp);
2645 SessionDescriptionInterface* offer4 =
2646 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2647 SetRemoteDescriptionWithoutError(offer4);
2648 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2649}
2650
Donald Curtisd4f769d2015-05-28 09:48:21 -07002651// Test that candidates sent to the "video" transport do not get pushed down to
2652// the "audio" transport channel when bundling using TransportProxy.
2653TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2654 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2655
2656 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2657 mediastream_signaling_.SendAudioVideoStream1();
2658
2659 PeerConnectionInterface::RTCOfferAnswerOptions options;
2660 options.use_rtp_mux = true;
2661
2662 SessionDescriptionInterface* offer = CreateRemoteOffer();
2663 SetRemoteDescriptionWithoutError(offer);
2664
2665 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2666 SetLocalDescriptionWithoutError(answer);
2667
2668 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2669 session_->GetTransportProxy("video")->impl());
2670
2671 cricket::Transport* t = session_->GetTransport("audio");
2672
2673 // Checks if one of the transport channels contains a connection using a given
2674 // port.
2675 auto connection_with_remote_port = [t](int port) {
2676 cricket::TransportStats stats;
2677 t->GetStats(&stats);
2678 for (auto& chan_stat : stats.channel_stats) {
2679 for (auto& conn_info : chan_stat.connection_infos) {
2680 if (conn_info.remote_candidate.address().port() == port) {
2681 return true;
2682 }
2683 }
2684 }
2685 return false;
2686 };
2687
2688 EXPECT_FALSE(connection_with_remote_port(5000));
2689 EXPECT_FALSE(connection_with_remote_port(5001));
2690 EXPECT_FALSE(connection_with_remote_port(6000));
2691
2692 // The way the *_WAIT checks work is they only wait if the condition fails,
2693 // which does not help in the case where state is not changing. This is
2694 // problematic in this test since we want to verify that adding a video
2695 // candidate does _not_ change state. So we interleave candidates and assume
2696 // that messages are executed in the order they were posted.
2697
2698 // First audio candidate.
2699 cricket::Candidate candidate0;
2700 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2701 candidate0.set_component(1);
2702 candidate0.set_protocol("udp");
2703 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2704 candidate0);
2705 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2706
2707 // Video candidate.
2708 cricket::Candidate candidate1;
2709 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2710 candidate1.set_component(1);
2711 candidate1.set_protocol("udp");
2712 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2713 candidate1);
2714 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2715
2716 // Second audio candidate.
2717 cricket::Candidate candidate2;
2718 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2719 candidate2.set_component(1);
2720 candidate2.set_protocol("udp");
2721 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2722 candidate2);
2723 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2724
2725 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2726 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2727
2728 // No need here for a _WAIT check since we are checking that state hasn't
2729 // changed: if this is false we would be doing waits for nothing and if this
2730 // is true then there will be no messages processed anyways.
2731 EXPECT_FALSE(connection_with_remote_port(6000));
2732}
2733
Peter Thatcher4eddf182015-04-30 10:55:59 -07002734// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002735TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2736 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002738
2739 PeerConnectionInterface::RTCOfferAnswerOptions options;
2740 options.use_rtp_mux = true;
2741
2742 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002744
2745 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2746 session_->GetTransportProxy("video")->impl());
2747
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002749 SessionDescriptionInterface* answer =
2750 CreateRemoteAnswer(session_->local_description());
2751 SetRemoteDescriptionWithoutError(answer);
2752
2753 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2754 session_->GetTransportProxy("video")->impl());
2755}
2756
2757// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2758TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2759 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2760 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002761
Donald Curtis0e209b02015-03-24 09:29:54 -07002762 PeerConnectionInterface::RTCOfferAnswerOptions options;
2763 options.use_rtp_mux = true;
2764
2765 SessionDescriptionInterface* offer = CreateOffer(options);
2766 SetLocalDescriptionWithoutError(offer);
2767
2768 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2769 session_->GetTransportProxy("video")->impl());
2770
2771 mediastream_signaling_.SendAudioVideoStream2();
2772
2773 // Remove BUNDLE from the answer.
2774 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2775 CreateRemoteAnswer(session_->local_description()));
2776 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2777 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2778 JsepSessionDescription* modified_answer =
2779 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2780 modified_answer->Initialize(answer_copy, "1", "1");
2781 SetRemoteDescriptionWithoutError(modified_answer); //
2782
2783 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2784 session_->GetTransportProxy("video")->impl());
2785}
2786
2787// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2788TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2789 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2790 mediastream_signaling_.SendAudioVideoStream1();
2791
2792 PeerConnectionInterface::RTCOfferAnswerOptions options;
2793 options.use_rtp_mux = true;
2794
2795 SessionDescriptionInterface* offer = CreateOffer(options);
2796 SetLocalDescriptionWithoutError(offer);
2797
2798 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2799 session_->GetTransportProxy("video")->impl());
2800
2801 mediastream_signaling_.SendAudioVideoStream2();
2802 SessionDescriptionInterface* answer =
2803 CreateRemoteAnswer(session_->local_description());
2804 SetRemoteDescriptionWithoutError(answer);
2805
2806 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2807 session_->GetTransportProxy("video")->impl());
2808}
2809
2810// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2811TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2812 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2813 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002814
Donald Curtis0e209b02015-03-24 09:29:54 -07002815 PeerConnectionInterface::RTCOfferAnswerOptions options;
2816 options.use_rtp_mux = true;
2817
2818 SessionDescriptionInterface* offer = CreateOffer(options);
2819 SetLocalDescriptionWithoutError(offer);
2820
2821 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2822 session_->GetTransportProxy("video")->impl());
2823
2824 mediastream_signaling_.SendAudioVideoStream2();
2825
2826 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002827 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 CreateRemoteAnswer(session_->local_description()));
2829 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2830 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2831 JsepSessionDescription* modified_answer =
2832 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2833 modified_answer->Initialize(answer_copy, "1", "1");
2834 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835
Donald Curtis0e209b02015-03-24 09:29:54 -07002836 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2837 session_->GetTransportProxy("video")->impl());
2838}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839
Peter Thatcher4eddf182015-04-30 10:55:59 -07002840// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002841TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2842 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2843 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844
Donald Curtis0e209b02015-03-24 09:29:54 -07002845 PeerConnectionInterface::RTCOfferAnswerOptions options;
2846 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847
Donald Curtis0e209b02015-03-24 09:29:54 -07002848 SessionDescriptionInterface* offer = CreateOffer(options);
2849 SetLocalDescriptionWithoutError(offer);
2850
2851 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2852 session_->GetTransportProxy("video")->impl());
2853
2854 mediastream_signaling_.SendAudioVideoStream2();
2855 SessionDescriptionInterface* answer =
2856 CreateRemoteAnswer(session_->local_description());
2857 SetRemoteDescriptionWithoutError(answer);
2858
2859 // This should lead to an audio-only call but isn't implemented
2860 // correctly yet.
2861 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2862 session_->GetTransportProxy("video")->impl());
2863}
2864
2865// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2866TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2867 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2868 mediastream_signaling_.SendAudioVideoStream1();
2869 PeerConnectionInterface::RTCOfferAnswerOptions options;
2870 options.use_rtp_mux = true;
2871
2872 SessionDescriptionInterface* offer = CreateOffer(options);
2873 SetLocalDescriptionWithoutError(offer);
2874
2875 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2876 session_->GetTransportProxy("video")->impl());
2877
2878 mediastream_signaling_.SendAudioVideoStream2();
2879
2880 // Remove BUNDLE from the answer.
2881 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2882 CreateRemoteAnswer(session_->local_description()));
2883 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2884 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2885 JsepSessionDescription* modified_answer =
2886 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2887 modified_answer->Initialize(answer_copy, "1", "1");
2888 SetRemoteDescriptionWithoutError(modified_answer); //
2889
2890 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2891 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892}
2893
Peter Thatcher4eddf182015-04-30 10:55:59 -07002894// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2895TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2896 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2897 mediastream_signaling_.SendAudioVideoStream1();
2898
2899 PeerConnectionInterface::RTCOfferAnswerOptions options;
2900 options.use_rtp_mux = true;
2901
2902 SessionDescriptionInterface* offer = CreateOffer(options);
2903 SetRemoteDescriptionWithoutError(offer);
2904
2905 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2906 session_->GetTransportProxy("video")->impl());
2907}
2908
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002909TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2910 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2911 mediastream_signaling_.SendAudioVideoStream1();
2912
2913 PeerConnectionInterface::RTCOfferAnswerOptions options;
2914 SessionDescriptionInterface* offer = CreateOffer(options);
2915 SetLocalDescriptionWithoutError(offer);
2916
2917 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2918 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2919
2920 mediastream_signaling_.SendAudioVideoStream2();
2921 SessionDescriptionInterface* answer =
2922 CreateRemoteAnswer(session_->local_description());
2923 SetRemoteDescriptionWithoutError(answer);
2924
2925 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2926 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2927}
2928
2929TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2930 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2931 mediastream_signaling_.SendAudioVideoStream1();
2932
2933 PeerConnectionInterface::RTCOfferAnswerOptions options;
2934 SessionDescriptionInterface* offer = CreateOffer(options);
2935 SetLocalDescriptionWithoutError(offer);
2936
2937 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2938 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2939
2940 mediastream_signaling_.SendAudioVideoStream2();
2941 SessionDescriptionInterface* answer =
2942 CreateRemoteAnswer(session_->local_description());
2943 SetRemoteDescriptionWithoutError(answer);
2944
2945 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2946 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2947}
2948
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002949// This test verifies that SetLocalDescription and SetRemoteDescription fails
2950// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2951TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002952 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002953 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002954
2955 PeerConnectionInterface::RTCOfferAnswerOptions options;
2956 options.use_rtp_mux = true;
2957
2958 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002959 std::string offer_str;
2960 offer->ToString(&offer_str);
2961 // Disable rtcp-mux
2962 const std::string rtcp_mux = "rtcp-mux";
2963 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002964 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002965 xrtcp_mux.c_str(), xrtcp_mux.length(),
2966 &offer_str);
2967 JsepSessionDescription *local_offer =
2968 new JsepSessionDescription(JsepSessionDescription::kOffer);
2969 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002970 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002971 JsepSessionDescription *remote_offer =
2972 new JsepSessionDescription(JsepSessionDescription::kOffer);
2973 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002974 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002975 // Trying unmodified SDP.
2976 SetLocalDescriptionWithoutError(offer);
2977}
2978
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002980 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981 mediastream_signaling_.SendAudioVideoStream1();
2982 CreateAndSetRemoteOfferAndLocalAnswer();
2983 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2984 ASSERT_TRUE(channel != NULL);
2985 ASSERT_EQ(1u, channel->recv_streams().size());
2986 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2987 double left_vol, right_vol;
2988 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2989 EXPECT_EQ(1, left_vol);
2990 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002991 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002992 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2994 EXPECT_EQ(0, left_vol);
2995 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002996 EXPECT_EQ(0, renderer->channel_id());
2997 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2999 EXPECT_EQ(1, left_vol);
3000 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003001 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002}
3003
3004TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003005 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 mediastream_signaling_.SendAudioVideoStream1();
3007 CreateAndSetRemoteOfferAndLocalAnswer();
3008 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3009 ASSERT_TRUE(channel != NULL);
3010 ASSERT_EQ(1u, channel->send_streams().size());
3011 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3012 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3013
3014 cricket::AudioOptions options;
3015 options.echo_cancellation.Set(true);
3016
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003017 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003018 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3020 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003021 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003022 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003024 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003025 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3027 bool value;
3028 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3029 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003030 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003031 EXPECT_TRUE(renderer->sink() == NULL);
3032}
3033
3034TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003035 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003036 mediastream_signaling_.SendAudioVideoStream1();
3037 CreateAndSetRemoteOfferAndLocalAnswer();
3038 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3039 ASSERT_TRUE(channel != NULL);
3040 ASSERT_EQ(1u, channel->send_streams().size());
3041 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3042
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003043 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003044 cricket::AudioOptions options;
3045 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3046 EXPECT_TRUE(renderer->sink() != NULL);
3047
3048 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3049 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3050 // SetSink(NULL) callback afterwards.
3051 renderer.reset();
3052
3053 // This will trigger SetSink(NULL) if no OnClose() callback.
3054 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055}
3056
3057TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003058 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059 mediastream_signaling_.SendAudioVideoStream1();
3060 CreateAndSetRemoteOfferAndLocalAnswer();
3061 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3062 ASSERT_TRUE(channel != NULL);
3063 ASSERT_LT(0u, channel->renderers().size());
3064 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3065 ASSERT_EQ(1u, channel->recv_streams().size());
3066 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3067 cricket::FakeVideoRenderer renderer;
3068 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3069 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3070 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3071 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3072}
3073
3074TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003075 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076 mediastream_signaling_.SendAudioVideoStream1();
3077 CreateAndSetRemoteOfferAndLocalAnswer();
3078 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3079 ASSERT_TRUE(channel != NULL);
3080 ASSERT_EQ(1u, channel->send_streams().size());
3081 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3082 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3083 cricket::VideoOptions* options = NULL;
3084 session_->SetVideoSend(send_ssrc, false, options);
3085 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3086 session_->SetVideoSend(send_ssrc, true, options);
3087 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3088}
3089
3090TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3091 TestCanInsertDtmf(false);
3092}
3093
3094TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3095 TestCanInsertDtmf(true);
3096}
3097
3098TEST_F(WebRtcSessionTest, InsertDtmf) {
3099 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003100 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003101 mediastream_signaling_.SendAudioVideoStream1();
3102 CreateAndSetRemoteOfferAndLocalAnswer();
3103 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3104 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3105
3106 // Insert DTMF
3107 const int expected_flags = DF_SEND;
3108 const int expected_duration = 90;
3109 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3110 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3111 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3112
3113 // Verify
3114 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3115 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3116 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3117 expected_duration, expected_flags));
3118 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3119 expected_duration, expected_flags));
3120 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3121 expected_duration, expected_flags));
3122}
3123
3124// This test verifies the |initiator| flag when session initiates the call.
3125TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003126 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003127 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003128 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3130 SetLocalDescriptionWithoutError(offer);
3131 EXPECT_TRUE(session_->initiator());
3132 SetRemoteDescriptionWithoutError(answer);
3133 EXPECT_TRUE(session_->initiator());
3134}
3135
3136// This test verifies the |initiator| flag when session receives the call.
3137TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003138 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139 EXPECT_FALSE(session_->initiator());
3140 SessionDescriptionInterface* offer = CreateRemoteOffer();
3141 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003142 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143
3144 EXPECT_FALSE(session_->initiator());
3145 SetLocalDescriptionWithoutError(answer);
3146 EXPECT_FALSE(session_->initiator());
3147}
3148
pthatcherfa301802015-08-11 04:12:56 -07003149// This test verifies the ice protocol type at initiator of the call
3150// if |a=ice-options:google-ice| is present in answer.
3151TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
3152 Init();
3153 mediastream_signaling_.SendAudioVideoStream1();
3154 SessionDescriptionInterface* offer = CreateOffer();
3155 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3156 CreateRemoteAnswer(offer));
3157 SetLocalDescriptionWithoutError(offer);
3158 std::string sdp;
3159 EXPECT_TRUE(answer->ToString(&sdp));
3160 // Adding ice-options to the session level.
3161 InjectAfter("t=0 0\r\n",
3162 "a=ice-options:google-ice\r\n",
3163 &sdp);
3164 SessionDescriptionInterface* answer_with_gice =
3165 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3166 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3167 // only gice to fail.
3168 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
3169}
3170
3171// This test verifies the ice protocol type at initiator of the call
3172// if ICE RFC5245 is supported in answer.
3173TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
3174 Init();
3175 mediastream_signaling_.SendAudioVideoStream1();
3176 SessionDescriptionInterface* offer = CreateOffer();
3177 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3178 SetLocalDescriptionWithoutError(offer);
3179
3180 SetRemoteDescriptionWithoutError(answer);
3181 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3182 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3183}
3184
3185// This test verifies the ice protocol type at receiver side of the call if
3186// receiver decides to use ice RFC 5245.
3187TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
3188 Init();
3189 mediastream_signaling_.SendAudioVideoStream1();
3190 SessionDescriptionInterface* offer = CreateOffer();
3191 SetRemoteDescriptionWithoutError(offer);
3192 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3193 SetLocalDescriptionWithoutError(answer);
3194 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3195 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3196}
3197
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3199TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003200 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003202 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003204 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205 CreateRemoteAnswer(session_->local_description()));
3206
3207 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3208 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003209 JsepSessionDescription* modified_answer =
3210 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003211
3212 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3213 answer->session_id(),
3214 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003215 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216
wu@webrtc.org4e393072014-04-07 17:04:35 +00003217 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218 std::string sdp;
3219 EXPECT_TRUE(answer->ToString(&sdp));
3220 const std::string kAudioMid = "a=mid:audio";
3221 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003222 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003223 kAudioMidReplaceStr.c_str(),
3224 kAudioMidReplaceStr.length(),
3225 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003226 SessionDescriptionInterface* modified_answer1 =
3227 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003228 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
wu@webrtc.org4e393072014-04-07 17:04:35 +00003230 // Different media types.
3231 EXPECT_TRUE(answer->ToString(&sdp));
3232 const std::string kAudioMline = "m=audio";
3233 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003234 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003235 kAudioMlineReplaceStr.c_str(),
3236 kAudioMlineReplaceStr.length(),
3237 &sdp);
3238 SessionDescriptionInterface* modified_answer2 =
3239 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3240 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3241
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242 SetRemoteDescriptionWithoutError(answer.release());
3243}
3244
3245// Verifying remote offer and local answer have matching m-lines as per
3246// RFC 3264.
3247TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003248 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 mediastream_signaling_.SendAudioVideoStream1();
3250 SessionDescriptionInterface* offer = CreateRemoteOffer();
3251 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003252 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253
3254 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3255 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003256 JsepSessionDescription* modified_answer =
3257 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258
3259 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3260 answer->session_id(),
3261 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003262 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 SetLocalDescriptionWithoutError(answer);
3264}
3265
3266// This test verifies that WebRtcSession does not start candidate allocation
3267// before SetLocalDescription is called.
3268TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003269 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270 mediastream_signaling_.SendAudioVideoStream1();
3271 SessionDescriptionInterface* offer = CreateRemoteOffer();
3272 cricket::Candidate candidate;
3273 candidate.set_component(1);
3274 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3275 candidate);
3276 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3277 cricket::Candidate candidate1;
3278 candidate1.set_component(1);
3279 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3280 candidate1);
3281 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3282 SetRemoteDescriptionWithoutError(offer);
3283 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3284 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3285
3286 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003287 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3289 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3290
wu@webrtc.org91053e72013-08-10 07:18:04 +00003291 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292 SetLocalDescriptionWithoutError(answer);
3293 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3294 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3296}
3297
3298// This test verifies that crypto parameter is updated in local session
3299// description as per security policy set in MediaSessionDescriptionFactory.
3300TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003301 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003303 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304
3305 // Making sure SetLocalDescription correctly sets crypto value in
3306 // SessionDescription object after de-serialization of sdp string. The value
3307 // will be set as per MediaSessionDescriptionFactory.
3308 std::string offer_str;
3309 offer->ToString(&offer_str);
3310 SessionDescriptionInterface* jsep_offer_str =
3311 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3312 SetLocalDescriptionWithoutError(jsep_offer_str);
3313 EXPECT_TRUE(session_->voice_channel()->secure_required());
3314 EXPECT_TRUE(session_->video_channel()->secure_required());
3315}
3316
3317// This test verifies the crypto parameter when security is disabled.
3318TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003319 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003320 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003321 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003322 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323
3324 // Making sure SetLocalDescription correctly sets crypto value in
3325 // SessionDescription object after de-serialization of sdp string. The value
3326 // will be set as per MediaSessionDescriptionFactory.
3327 std::string offer_str;
3328 offer->ToString(&offer_str);
3329 SessionDescriptionInterface *jsep_offer_str =
3330 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3331 SetLocalDescriptionWithoutError(jsep_offer_str);
3332 EXPECT_FALSE(session_->voice_channel()->secure_required());
3333 EXPECT_FALSE(session_->video_channel()->secure_required());
3334}
3335
3336// This test verifies that an answer contains new ufrag and password if an offer
3337// with new ufrag and password is received.
3338TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003339 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003341 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003342 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 CreateRemoteOffer(options));
3344 SetRemoteDescriptionWithoutError(offer.release());
3345
3346 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003347 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003348 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003349 SetLocalDescriptionWithoutError(answer.release());
3350
3351 // Receive an offer with new ufrag and password.
3352 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003353 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003354 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355 SetRemoteDescriptionWithoutError(updated_offer1.release());
3356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003357 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003358 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359
3360 CompareIceUfragAndPassword(updated_answer1->description(),
3361 session_->local_description()->description(),
3362 false);
3363
3364 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003365}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366
wu@webrtc.org91053e72013-08-10 07:18:04 +00003367// This test verifies that an answer contains old ufrag and password if an offer
3368// with old ufrag and password is received.
3369TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003370 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003371 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003372 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003373 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003374 CreateRemoteOffer(options));
3375 SetRemoteDescriptionWithoutError(offer.release());
3376
3377 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003378 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003379 CreateAnswer(NULL));
3380 SetLocalDescriptionWithoutError(answer.release());
3381
3382 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003384 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003385 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 SetRemoteDescriptionWithoutError(updated_offer2.release());
3387
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003388 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003389 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390
3391 CompareIceUfragAndPassword(updated_answer2->description(),
3392 session_->local_description()->description(),
3393 true);
3394
3395 SetLocalDescriptionWithoutError(updated_answer2.release());
3396}
3397
3398TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003399 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003401 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 const std::string session_id_orig = offer->session_id();
3403 const std::string session_version_orig = offer->session_version();
3404 SetLocalDescriptionWithoutError(offer);
3405
3406 video_channel_ = media_engine_->GetVideoChannel(0);
3407 video_channel_->set_fail_set_send_codecs(true);
3408
3409 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003410 SessionDescriptionInterface* answer =
3411 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003412 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413}
3414
3415// Runs the loopback call test with BUNDLE and STUN disabled.
3416TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3417 // Lets try with only UDP ports.
pthatcherfa301802015-08-11 04:12:56 -07003418 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3419 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003420 cricket::PORTALLOCATOR_DISABLE_STUN |
3421 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 TestLoopbackCall();
3423}
3424
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003425TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
pthatcherfa301802015-08-11 04:12:56 -07003426 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3427 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003428 cricket::PORTALLOCATOR_DISABLE_STUN |
3429 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3430 cricket::PORTALLOCATOR_DISABLE_RELAY);
3431
3432 // best connection is IPv6 since it has higher network preference.
3433 LoopbackNetworkConfiguration config;
3434 config.test_ipv6_network_ = true;
3435 config.best_connection_after_initial_ice_converged_ =
3436 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3437
3438 TestLoopbackCall(config);
3439}
3440
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003441// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003442TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
pthatcherfa301802015-08-11 04:12:56 -07003443 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3444 cricket::PORTALLOCATOR_DISABLE_TCP |
3445 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003446 TestLoopbackCall();
3447}
3448
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003449TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003450 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003452 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003454 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3455 std::string error_code_str = "ERROR_CONTENT";
3456 std::string error_desc = "Fake session error description.";
3457 session_->SetError(error_code, error_desc);
3458
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3460 SessionDescriptionInterface* answer =
3461 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003462
3463 std::string action;
3464 std::ostringstream session_error_msg;
3465 session_error_msg << kSessionError << error_code_str << ". ";
3466 session_error_msg << kSessionErrorDesc << error_desc << ".";
3467 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3468 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469}
3470
3471TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3472 constraints_.reset(new FakeConstraints());
3473 constraints_->AddOptional(
3474 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003475 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476
3477 SetLocalDescriptionWithDataChannel();
3478 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3479}
3480
3481TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003482 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483
3484 constraints_.reset(new FakeConstraints());
3485 constraints_->AddOptional(
3486 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003487 options_.disable_sctp_data_channels = false;
3488
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003489 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490
3491 SetLocalDescriptionWithDataChannel();
3492 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3493}
3494
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003495TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003496 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003497
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003498 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003499
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003500 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003501 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003502 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3503}
3504
3505TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003506 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003507 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003508 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003509
3510 // Create remote offer with SCTP.
3511 cricket::MediaSessionOptions options;
3512 options.data_channel_type = cricket::DCT_SCTP;
3513 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003514 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003515 SetRemoteDescriptionWithoutError(offer);
3516
3517 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003518 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003519 EXPECT_TRUE(answer != NULL);
3520 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3521 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003522}
3523
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3525 constraints_.reset(new FakeConstraints());
3526 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003527 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
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_NONE, data_engine_->last_channel_type());
3532}
3533
3534TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003535 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003537 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538
3539 SetLocalDescriptionWithDataChannel();
3540 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3541}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003542
wu@webrtc.org97077a32013-10-25 21:18:33 +00003543TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003544 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003545 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003546 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003547
3548 SetLocalDescriptionWithDataChannel();
3549 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3550}
3551
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003552TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003553 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003554 const int new_send_port = 9998;
3555 const int new_recv_port = 7775;
3556
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003557 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003558 SetFactoryDtlsSrtp();
3559
3560 // By default, don't actually add the codecs to desc_factory_; they don't
3561 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3562 // let the session description get parsed. That'll get the proper codecs
3563 // into the stream.
3564 cricket::MediaSessionOptions options;
3565 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3566 "stream1", new_send_port, options);
3567
3568 // SetRemoteDescription will take the ownership of the offer.
3569 SetRemoteDescriptionWithoutError(offer);
3570
3571 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3572 new_recv_port, CreateAnswer(NULL));
3573 ASSERT_TRUE(answer != NULL);
3574
3575 // Now set the local description, which'll take ownership of the answer.
3576 SetLocalDescriptionWithoutError(answer);
3577
3578 // TEST PLAN: Set the port number to something new, set it in the SDP,
3579 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003580 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003581 dci.reliable = true;
3582 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003583 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003584 session_->CreateDataChannel("datachannel", &dci);
3585
3586 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3587 int portnum = -1;
3588 ASSERT_TRUE(ch != NULL);
3589 ASSERT_EQ(1UL, ch->send_codecs().size());
3590 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003591 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003592 ch->send_codecs()[0].name.c_str()));
3593 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3594 &portnum));
3595 EXPECT_EQ(new_send_port, portnum);
3596
3597 ASSERT_EQ(1UL, ch->recv_codecs().size());
3598 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003599 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003600 ch->recv_codecs()[0].name.c_str()));
3601 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3602 &portnum));
3603 EXPECT_EQ(new_recv_port, portnum);
3604}
3605
wu@webrtc.org91053e72013-08-10 07:18:04 +00003606// Verifies that CreateOffer succeeds when CreateOffer is called before async
3607// identity generation is finished.
3608TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003609 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003610 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003611
3612 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003613 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003614 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3615
wu@webrtc.org91053e72013-08-10 07:18:04 +00003616 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003617 VerifyNoCryptoParams(offer->description(), true);
3618 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003619}
3620
3621// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3622// identity generation is finished.
3623TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003624 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003625 InitWithDtls();
3626 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003627
3628 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003629 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003630 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003631 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003632 ASSERT_TRUE(offer.get() != NULL);
3633 SetRemoteDescriptionWithoutError(offer.release());
3634
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003635 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003636 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003637 VerifyNoCryptoParams(answer->description(), true);
3638 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003639}
3640
3641// Verifies that CreateOffer succeeds when CreateOffer is called after async
3642// identity generation is finished.
3643TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003644 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003645 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003646
3647 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003648
3649 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003650 EXPECT_TRUE(offer != NULL);
3651}
3652
3653// Verifies that CreateOffer fails when CreateOffer is called after async
3654// identity generation fails.
3655TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003656 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003657 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003658
3659 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003660
3661 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003662 EXPECT_TRUE(offer == NULL);
3663}
3664
3665// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3666// before async identity generation is finished.
3667TEST_F(WebRtcSessionTest,
3668 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
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 true, CreateSessionDescriptionRequest::kOffer);
3672}
3673
3674// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3675// before async identity generation fails.
3676TEST_F(WebRtcSessionTest,
3677 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
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 false, CreateSessionDescriptionRequest::kOffer);
3681}
3682
3683// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3684// before async identity generation is finished.
3685TEST_F(WebRtcSessionTest,
3686 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
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 true, CreateSessionDescriptionRequest::kAnswer);
3690}
3691
3692// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3693// before async identity generation fails.
3694TEST_F(WebRtcSessionTest,
3695 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003696 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003697 VerifyMultipleAsyncCreateDescription(
3698 false, CreateSessionDescriptionRequest::kAnswer);
3699}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003700
3701// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3702// offer has no SDES crypto but only DTLS fingerprint.
3703TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3704 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003705 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003706 // Create a remote offer with secured transport disabled.
3707 cricket::MediaSessionOptions options;
3708 JsepSessionDescription* offer(CreateRemoteOffer(
3709 options, cricket::SEC_DISABLED));
3710 // Adds a DTLS fingerprint to the remote offer.
3711 cricket::SessionDescription* sdp = offer->description();
3712 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3713 ASSERT_TRUE(audio != NULL);
3714 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3715 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003716 rtc::SSLFingerprint::CreateFromRfc4572(
3717 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003718 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003719 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003720}
3721
wu@webrtc.orgde305012013-10-31 15:40:38 +00003722// This test verifies DSCP is properly applied on the media channels.
3723TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3724 constraints_.reset(new FakeConstraints());
3725 constraints_->AddOptional(
3726 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003727 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003728 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003729 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003730
3731 SetLocalDescriptionWithoutError(offer);
3732
3733 video_channel_ = media_engine_->GetVideoChannel(0);
3734 voice_channel_ = media_engine_->GetVoiceChannel(0);
3735
3736 ASSERT_TRUE(video_channel_ != NULL);
3737 ASSERT_TRUE(voice_channel_ != NULL);
3738 cricket::AudioOptions audio_options;
3739 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3740 cricket::VideoOptions video_options;
3741 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3742 EXPECT_TRUE(audio_options.dscp.IsSet());
3743 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3744 EXPECT_TRUE(video_options.dscp.IsSet());
3745 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3746}
3747
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003748TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3749 constraints_.reset(new FakeConstraints());
3750 constraints_->AddOptional(
3751 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3752 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003753 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003754 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003755 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003756
3757 SetLocalDescriptionWithoutError(offer);
3758
3759 video_channel_ = media_engine_->GetVideoChannel(0);
3760
3761 ASSERT_TRUE(video_channel_ != NULL);
3762 cricket::VideoOptions video_options;
3763 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3764 EXPECT_TRUE(
3765 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3766}
3767
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003768TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3769 // Number of unsignalled receiving streams should be between 0 and
3770 // kMaxUnsignalledRecvStreams.
3771 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3772 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3773 kMaxUnsignalledRecvStreams);
3774 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3775}
3776
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003777TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3778 constraints_.reset(new FakeConstraints());
3779 constraints_->AddOptional(
3780 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3781 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003782 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003783 mediastream_signaling_.SendAudioVideoStream1();
3784 SessionDescriptionInterface* offer = CreateOffer();
3785
3786 SetLocalDescriptionWithoutError(offer);
3787
3788 voice_channel_ = media_engine_->GetVoiceChannel(0);
3789
3790 ASSERT_TRUE(voice_channel_ != NULL);
3791 cricket::AudioOptions audio_options;
3792 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3793 EXPECT_TRUE(
3794 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3795}
3796
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003797// Tests that we can renegotiate new media content with ICE candidates in the
3798// new remote SDP.
3799TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003800 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003801 InitWithDtls();
3802 SetFactoryDtlsSrtp();
3803
3804 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003805 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003806 SetLocalDescriptionWithoutError(offer);
3807
3808 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3809 SetRemoteDescriptionWithoutError(answer);
3810
3811 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003812 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003813 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3814
3815 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003816 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003817 candidate1.set_component(1);
3818 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3819 candidate1);
3820 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3821 SetRemoteDescriptionWithoutError(offer);
3822
3823 answer = CreateAnswer(NULL);
3824 SetLocalDescriptionWithoutError(answer);
3825}
3826
3827// Tests that we can renegotiate new media content with ICE candidates separated
3828// from the remote SDP.
3829TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003830 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003831 InitWithDtls();
3832 SetFactoryDtlsSrtp();
3833
3834 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003835 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003836 SetLocalDescriptionWithoutError(offer);
3837
3838 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3839 SetRemoteDescriptionWithoutError(answer);
3840
3841 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003842 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003843 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3844 SetRemoteDescriptionWithoutError(offer);
3845
3846 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003847 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003848 candidate1.set_component(1);
3849 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3850 candidate1);
3851 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3852
3853 answer = CreateAnswer(NULL);
3854 SetLocalDescriptionWithoutError(answer);
3855}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003856// Tests that RTX codec is removed from the answer when it isn't supported
3857// by local side.
3858TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3859 Init();
3860 mediastream_signaling_.SendAudioVideoStream1();
3861 std::string offer_sdp(kSdpWithRtx);
3862
3863 SessionDescriptionInterface* offer =
3864 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3865 EXPECT_TRUE(offer->ToString(&offer_sdp));
3866
3867 // Offer SDP contains the RTX codec.
3868 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3869 SetRemoteDescriptionWithoutError(offer);
3870
3871 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3872 std::string answer_sdp;
3873 answer->ToString(&answer_sdp);
3874 // Answer SDP removes the unsupported RTX codec.
3875 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3876 SetLocalDescriptionWithoutError(answer);
3877}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003878
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003879// This verifies that the voice channel after bundle has both options from video
3880// and voice channels.
3881TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3882 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3883 mediastream_signaling_.SendAudioVideoStream1();
3884
3885 PeerConnectionInterface::RTCOfferAnswerOptions options;
3886 options.use_rtp_mux = true;
3887
3888 SessionDescriptionInterface* offer = CreateOffer(options);
3889 SetLocalDescriptionWithoutError(offer);
3890
3891 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3892 rtc::Socket::Option::OPT_SNDBUF, 4000);
3893
3894 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3895 rtc::Socket::Option::OPT_RCVBUF, 8000);
3896
3897 int option_val;
3898 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3899 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3900 EXPECT_EQ(4000, option_val);
3901 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3902 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3903
3904 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3905 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3906 EXPECT_EQ(8000, option_val);
3907 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3908 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3909
3910 EXPECT_NE(session_->voice_channel()->transport_channel(),
3911 session_->video_channel()->transport_channel());
3912
3913 mediastream_signaling_.SendAudioVideoStream2();
3914 SessionDescriptionInterface* answer =
3915 CreateRemoteAnswer(session_->local_description());
3916 SetRemoteDescriptionWithoutError(answer);
3917
3918 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3919 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3920 EXPECT_EQ(4000, option_val);
3921
3922 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3923 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3924 EXPECT_EQ(8000, option_val);
3925}
3926
tommi0f620f42015-07-09 03:25:02 -07003927// Test creating a session, request multiple offers, destroy the session
3928// and make sure we got success/failure callbacks for all of the requests.
3929// Background: crbug.com/507307
3930TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3931 Init();
3932
3933 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3934 PeerConnectionInterface::RTCOfferAnswerOptions options;
3935 options.offer_to_receive_audio =
3936 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3937
3938 for (auto& o : observers) {
3939 o = new WebRtcSessionCreateSDPObserverForTest();
3940 session_->CreateOffer(o, options);
3941 }
3942
3943 session_.reset();
3944
3945 // Make sure we process pending messages on the current (signaling) thread
3946 // before checking we we got our callbacks. Quit() will do this and then
3947 // immediately exit. We won't need the queue after this point anyway.
3948 rtc::Thread::Current()->Quit();
3949
3950 for (auto& o : observers) {
3951 // We expect to have received a notification now even if the session was
3952 // terminated. The offer creation may or may not have succeeded, but we
3953 // must have received a notification which, so the only invalid state
3954 // is kInit.
3955 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3956 }
3957}
3958
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003959// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3960// currently fails because upon disconnection and reconnection OnIceComplete is
3961// called more than once without returning to IceGatheringGathering.