blob: b84e6fb8ad68a9cdb5d86e8228a5427de54f6f99 [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;
guoweisd12140a2015-09-10 13:32:11 -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
Henrik Boström87713d02015-08-25 09:53:21 +0200161enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
162
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163// Add some extra |newlines| to the |message| after |line|.
164static void InjectAfter(const std::string& line,
165 const std::string& newlines,
166 std::string* message) {
167 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000168 rtc::replace_substrs(line.c_str(), line.length(),
Henrik Boström87713d02015-08-25 09:53:21 +0200169 tmp.c_str(), tmp.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170}
171
172class MockIceObserver : public webrtc::IceObserver {
173 public:
174 MockIceObserver()
175 : oncandidatesready_(false),
176 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
177 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
178 }
179
180 virtual void OnIceConnectionChange(
181 PeerConnectionInterface::IceConnectionState new_state) {
182 ice_connection_state_ = new_state;
183 }
184 virtual void OnIceGatheringChange(
185 PeerConnectionInterface::IceGatheringState new_state) {
186 // We can never transition back to "new".
187 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
188 ice_gathering_state_ = new_state;
189
190 // oncandidatesready_ really means "ICE gathering is complete".
191 // This if statement ensures that this value remains correct when we
192 // transition from kIceGatheringComplete to kIceGatheringGathering.
193 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
194 oncandidatesready_ = false;
195 }
196 }
197
198 // Found a new candidate.
199 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000200 switch (candidate->sdp_mline_index()) {
201 case kMediaContentIndex0:
202 mline_0_candidates_.push_back(candidate->candidate());
203 break;
204 case kMediaContentIndex1:
205 mline_1_candidates_.push_back(candidate->candidate());
206 break;
207 default:
208 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000210
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 // The ICE gathering state should always be Gathering when a candidate is
212 // received (or possibly Completed in the case of the final candidate).
213 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
214 }
215
216 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
217 virtual void OnIceComplete() {
218 EXPECT_FALSE(oncandidatesready_);
219 oncandidatesready_ = true;
220
221 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
222 // be called approximately simultaneously. For ease of testing, this
223 // check additionally requires that they be called in the above order.
224 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
225 ice_gathering_state_);
226 }
227
228 bool oncandidatesready_;
229 std::vector<cricket::Candidate> mline_0_candidates_;
230 std::vector<cricket::Candidate> mline_1_candidates_;
231 PeerConnectionInterface::IceConnectionState ice_connection_state_;
232 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
233};
234
235class WebRtcSessionForTest : public webrtc::WebRtcSession {
236 public:
237 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 rtc::Thread* signaling_thread,
239 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 cricket::PortAllocator* port_allocator,
241 webrtc::IceObserver* ice_observer,
242 webrtc::MediaStreamSignaling* mediastream_signaling)
243 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
244 mediastream_signaling) {
245 RegisterIceObserver(ice_observer);
246 }
247 virtual ~WebRtcSessionForTest() {}
248
249 using cricket::BaseSession::GetTransportProxy;
250 using webrtc::WebRtcSession::SetAudioPlayout;
251 using webrtc::WebRtcSession::SetAudioSend;
252 using webrtc::WebRtcSession::SetCaptureDevice;
253 using webrtc::WebRtcSession::SetVideoPlayout;
254 using webrtc::WebRtcSession::SetVideoSend;
255};
256
wu@webrtc.org91053e72013-08-10 07:18:04 +0000257class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000260 enum State {
261 kInit,
262 kFailed,
263 kSucceeded,
264 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000265 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000266
267 // CreateSessionDescriptionObserver implementation.
268 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000269 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000270 state_ = kSucceeded;
271 }
272 virtual void OnFailure(const std::string& error) {
273 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 }
275
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000276 SessionDescriptionInterface* description() { return description_.get(); }
277
278 SessionDescriptionInterface* ReleaseDescription() {
279 return description_.release();
280 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284 protected:
285 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
287 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000288 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290};
291
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000292class FakeAudioRenderer : public cricket::AudioRenderer {
293 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000294 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
295 virtual ~FakeAudioRenderer() {
296 if (sink_)
297 sink_->OnClose();
298 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000300 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301 ASSERT(channel_id_ == -1);
302 channel_id_ = channel_id;
303 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000304 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305 ASSERT(channel_id == channel_id_);
306 channel_id_ = -1;
307 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000308 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000309
310 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312 private:
313 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000314 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315};
316
Henrik Boström87713d02015-08-25 09:53:21 +0200317class WebRtcSessionTest
318 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 protected:
320 // TODO Investigate why ChannelManager crashes, if it's created
321 // after stun_server.
322 WebRtcSessionTest()
323 : media_engine_(new cricket::FakeMediaEngine()),
324 data_engine_(new cricket::FakeDataEngine()),
325 device_manager_(new cricket::FakeDeviceManager()),
326 channel_manager_(new cricket::ChannelManager(
327 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000328 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 tdesc_factory_(new cricket::TransportDescriptionFactory()),
330 desc_factory_(new cricket::MediaSessionDescriptionFactory(
331 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000332 pss_(new rtc::PhysicalSocketServer),
333 vss_(new rtc::VirtualSocketServer(pss_.get())),
334 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000337 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000338 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
339 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000340 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700341 mediastream_signaling_(channel_manager_.get()),
342 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
guoweisd12140a2015-09-10 13:32:11 -0700343 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
344
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000345 cricket::ServerAddresses stun_servers;
346 stun_servers.insert(stun_socket_addr_);
347 allocator_.reset(new cricket::BasicPortAllocator(
348 &network_manager_,
349 stun_servers,
350 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000351 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweisd12140a2015-09-10 13:32:11 -0700352 cricket::PORTALLOCATOR_DISABLE_RELAY |
353 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 EXPECT_TRUE(channel_manager_->Init());
355 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000356 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
358
359 void AddInterface(const SocketAddress& addr) {
360 network_manager_.AddInterface(addr);
361 }
362
Henrik Boström87713d02015-08-25 09:53:21 +0200363 // If |dtls_identity_store| != null or |rtc_configuration| contains
364 // |certificates| then DTLS will be enabled unless explicitly disabled by
365 // |rtc_configuration| options. When DTLS is enabled a certificate will be
366 // used if provided, otherwise one will be generated using the
367 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000368 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200369 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200370 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 ASSERT_TRUE(session_.get() == NULL);
372 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000373 channel_manager_.get(), rtc::Thread::Current(),
374 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 &observer_,
376 &mediastream_signaling_));
377
378 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
379 observer_.ice_connection_state_);
380 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
381 observer_.ice_gathering_state_);
382
Henrik Boström5e56c592015-08-11 10:33:13 +0200383 EXPECT_TRUE(session_->Initialize(
384 options_, constraints_.get(), dtls_identity_store.Pass(),
385 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700386 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 }
388
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000389 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200390 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200391 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000392 }
393
394 void InitWithIceTransport(
395 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200396 PeerConnectionInterface::RTCConfiguration configuration;
397 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200398 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000399 }
400
401 void InitWithBundlePolicy(
402 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200403 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200404 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200405 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700406 }
407
408 void InitWithRtcpMuxPolicy(
409 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
410 PeerConnectionInterface::RTCConfiguration configuration;
411 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200412 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 }
414
Henrik Boström87713d02015-08-25 09:53:21 +0200415 // Successfully init with DTLS; with a certificate generated and supplied or
416 // with a store that generates it for us.
417 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
418 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
419 PeerConnectionInterface::RTCConfiguration configuration;
420 if (cert_gen_method == ALREADY_GENERATED) {
421 configuration.certificates.push_back(
422 FakeDtlsIdentityStore::GenerateCertificate());
423 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
424 dtls_identity_store.reset(new FakeDtlsIdentityStore());
425 dtls_identity_store->set_should_fail(false);
426 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700427 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200428 }
429 Init(dtls_identity_store.Pass(), configuration);
430 }
431
432 // Init with DTLS with a store that will fail to generate a certificate.
433 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200434 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
435 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200436 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200437 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200438 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000439 }
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 void InitWithDtmfCodec() {
442 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000443 const cricket::AudioCodec kTelephoneEventCodec(
444 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 std::vector<cricket::AudioCodec> codecs;
446 codecs.push_back(kTelephoneEventCodec);
447 media_engine_->SetAudioCodecs(codecs);
448 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000449 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
451
452 // Creates a local offer and applies it. Starts ice.
453 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
454 // to decide which streams to create.
455 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000456 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 SetLocalDescriptionWithoutError(offer);
458 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
459 observer_.ice_gathering_state_,
460 kIceCandidatesTimeout);
461 }
462
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000463 SessionDescriptionInterface* CreateOffer() {
464 PeerConnectionInterface::RTCOfferAnswerOptions options;
465 options.offer_to_receive_audio =
466 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
467
468 return CreateOffer(options);
469 }
470
wu@webrtc.org91053e72013-08-10 07:18:04 +0000471 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000472 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000474 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000475 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000476 EXPECT_TRUE_WAIT(
477 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000478 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000479 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000480 }
481
482 SessionDescriptionInterface* CreateAnswer(
483 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000484 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000485 = new WebRtcSessionCreateSDPObserverForTest();
486 session_->CreateAnswer(observer, constraints);
487 EXPECT_TRUE_WAIT(
488 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000489 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000490 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000491 }
492
wu@webrtc.org364f2042013-11-20 21:49:41 +0000493 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 return (session_->voice_channel() != NULL &&
495 session_->video_channel() != NULL);
496 }
497
wu@webrtc.org364f2042013-11-20 21:49:41 +0000498 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
500 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
501 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
502 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
503 }
504
505 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
506 ASSERT_TRUE(session_.get() != NULL);
507 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
508 ASSERT_TRUE(content != NULL);
509 const cricket::AudioContentDescription* audio_content =
510 static_cast<const cricket::AudioContentDescription*>(
511 content->description);
512 ASSERT_TRUE(audio_content != NULL);
513 ASSERT_EQ(1U, audio_content->cryptos().size());
514 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
515 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
516 audio_content->cryptos()[0].cipher_suite);
517 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
518 audio_content->protocol());
519
520 content = cricket::GetFirstVideoContent(sdp);
521 ASSERT_TRUE(content != NULL);
522 const cricket::VideoContentDescription* video_content =
523 static_cast<const cricket::VideoContentDescription*>(
524 content->description);
525 ASSERT_TRUE(video_content != NULL);
526 ASSERT_EQ(1U, video_content->cryptos().size());
527 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
528 video_content->cryptos()[0].cipher_suite);
529 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
530 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
531 video_content->protocol());
532 }
533
534 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
535 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
536 ASSERT_TRUE(content != NULL);
537 const cricket::AudioContentDescription* audio_content =
538 static_cast<const cricket::AudioContentDescription*>(
539 content->description);
540 ASSERT_TRUE(audio_content != NULL);
541 ASSERT_EQ(0U, audio_content->cryptos().size());
542
543 content = cricket::GetFirstVideoContent(sdp);
544 ASSERT_TRUE(content != NULL);
545 const cricket::VideoContentDescription* video_content =
546 static_cast<const cricket::VideoContentDescription*>(
547 content->description);
548 ASSERT_TRUE(video_content != NULL);
549 ASSERT_EQ(0U, video_content->cryptos().size());
550
551 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700552 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700554 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 video_content->protocol());
556 } else {
557 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
558 audio_content->protocol());
559 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
560 video_content->protocol());
561 }
562 }
563
564 // Set the internal fake description factories to do DTLS-SRTP.
565 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000566 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200569 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200570 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
571 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
572 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
574 }
575
576 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
577 bool expected) {
578 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
579 ASSERT_TRUE(audio != NULL);
580 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 const TransportInfo* video = sdp->GetTransportInfoByName("video");
582 ASSERT_TRUE(video != NULL);
583 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 }
585
586 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000587 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000589 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000590 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000592 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000594 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
595 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000596 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 // Answer should be NULL as no crypto params in offer.
598 ASSERT_TRUE(answer == NULL);
599 }
600
601 void VerifyAnswerFromCryptoOffer() {
602 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000603 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 options.bundle_enabled = true;
605 scoped_ptr<JsepSessionDescription> offer(
606 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
607 ASSERT_TRUE(offer.get() != NULL);
608 VerifyCryptoParams(offer->description());
609 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000610 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 ASSERT_TRUE(answer.get() != NULL);
612 VerifyCryptoParams(answer->description());
613 }
614
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000615 void SetAndVerifyNumUnsignalledRecvStreams(
616 int value_set, int value_expected) {
617 constraints_.reset(new FakeConstraints());
618 constraints_->AddOptional(
619 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
620 value_set);
621 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000622 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000623 mediastream_signaling_.SendAudioVideoStream1();
624 SessionDescriptionInterface* offer = CreateOffer();
625
626 SetLocalDescriptionWithoutError(offer);
627
628 video_channel_ = media_engine_->GetVideoChannel(0);
629
630 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700631 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000632 EXPECT_EQ(value_expected,
633 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
634 }
635
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
637 const cricket::SessionDescription* desc2,
638 bool expect_equal) {
639 if (desc1->contents().size() != desc2->contents().size()) {
640 EXPECT_FALSE(expect_equal);
641 return;
642 }
643
644 const cricket::ContentInfos& contents = desc1->contents();
645 cricket::ContentInfos::const_iterator it = contents.begin();
646
647 for (; it != contents.end(); ++it) {
648 const cricket::TransportDescription* transport_desc1 =
649 desc1->GetTransportDescriptionByName(it->name);
650 const cricket::TransportDescription* transport_desc2 =
651 desc2->GetTransportDescriptionByName(it->name);
652 if (!transport_desc1 || !transport_desc2) {
653 EXPECT_FALSE(expect_equal);
654 return;
655 }
656 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
657 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
658 EXPECT_FALSE(expect_equal);
659 return;
660 }
661 }
662 EXPECT_TRUE(expect_equal);
663 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000664
665 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
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 empty strings.
673 for (; it != contents.end(); ++it) {
674 const cricket::TransportDescription* transport_desc =
675 desc->GetTransportDescriptionByName(it->name);
676 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
677 + "\r\n";
678 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
679 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000680 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000681 "", 0,
682 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000683 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000684 "", 0,
685 sdp);
686 }
687 }
688
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000689 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
690 const std::string& modified_ice_ufrag,
691 const std::string& modified_ice_pwd,
692 std::string* sdp) {
693 const cricket::SessionDescription* desc = current_desc->description();
694 EXPECT_TRUE(current_desc->ToString(sdp));
695
696 const cricket::ContentInfos& contents = desc->contents();
697 cricket::ContentInfos::const_iterator it = contents.begin();
698 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
699 // |modified_ice_pwd| strings.
700 for (; it != contents.end(); ++it) {
701 const cricket::TransportDescription* transport_desc =
702 desc->GetTransportDescriptionByName(it->name);
703 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
704 + "\r\n";
705 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
706 + "\r\n";
707 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
708 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000709 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000710 mod_ufrag.c_str(), mod_ufrag.length(),
711 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000712 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000713 mod_pwd.c_str(), mod_pwd.length(),
714 sdp);
715 }
716 }
717
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 // Creates a remote offer and and applies it as a remote description,
719 // creates a local answer and applies is as a local description.
720 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
721 // to decide which local and remote streams to create.
722 void CreateAndSetRemoteOfferAndLocalAnswer() {
723 SessionDescriptionInterface* offer = CreateRemoteOffer();
724 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000725 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 SetLocalDescriptionWithoutError(answer);
727 }
728 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
729 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
730 }
731 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
732 BaseSession::State expected_state) {
733 SetLocalDescriptionWithoutError(desc);
734 EXPECT_EQ(expected_state, session_->state());
735 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000736 void SetLocalDescriptionExpectError(const std::string& action,
737 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 SessionDescriptionInterface* desc) {
739 std::string error;
740 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000741 std::string sdp_type = "local ";
742 sdp_type.append(action);
743 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 EXPECT_NE(std::string::npos, error.find(expected_error));
745 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000746 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
747 SessionDescriptionInterface* desc) {
748 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
749 expected_error, desc);
750 }
751 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
752 SessionDescriptionInterface* desc) {
753 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
754 expected_error, desc);
755 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
757 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
758 }
759 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
760 BaseSession::State expected_state) {
761 SetRemoteDescriptionWithoutError(desc);
762 EXPECT_EQ(expected_state, session_->state());
763 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 void SetRemoteDescriptionExpectError(const std::string& action,
765 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 SessionDescriptionInterface* desc) {
767 std::string error;
768 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000769 std::string sdp_type = "remote ";
770 sdp_type.append(action);
771 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 EXPECT_NE(std::string::npos, error.find(expected_error));
773 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000774 void SetRemoteDescriptionOfferExpectError(
775 const std::string& expected_error, SessionDescriptionInterface* desc) {
776 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
777 expected_error, desc);
778 }
779 void SetRemoteDescriptionPranswerExpectError(
780 const std::string& expected_error, SessionDescriptionInterface* desc) {
781 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
782 expected_error, desc);
783 }
784 void SetRemoteDescriptionAnswerExpectError(
785 const std::string& expected_error, SessionDescriptionInterface* desc) {
786 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
787 expected_error, desc);
788 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789
790 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
791 SessionDescriptionInterface** nocrypto_answer) {
792 // Create a SDP without Crypto.
793 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000794 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 options.bundle_enabled = true;
796 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
797 ASSERT_TRUE(*offer != NULL);
798 VerifyCryptoParams((*offer)->description());
799
800 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
801 cricket::SEC_DISABLED);
802 EXPECT_TRUE(*nocrypto_answer != NULL);
803 }
804
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000805 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
806 SessionDescriptionInterface** nodtls_answer) {
807 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000808 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000809 options.bundle_enabled = true;
810
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000811 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000812 CreateRemoteOffer(options, cricket::SEC_ENABLED));
813
814 *nodtls_answer =
815 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
816 EXPECT_TRUE(*nodtls_answer != NULL);
817 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
818 VerifyCryptoParams((*nodtls_answer)->description());
819
820 SetFactoryDtlsSrtp();
821 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
822 ASSERT_TRUE(*offer != NULL);
823 VerifyFingerprintStatus((*offer)->description(), true);
824 VerifyCryptoParams((*offer)->description());
825 }
826
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 JsepSessionDescription* CreateRemoteOfferWithVersion(
828 cricket::MediaSessionOptions options,
829 cricket::SecurePolicy secure_policy,
830 const std::string& session_version,
831 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000832 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 const cricket::SessionDescription* cricket_desc = NULL;
834 if (current_desc) {
835 cricket_desc = current_desc->description();
836 session_id = current_desc->session_id();
837 }
838
839 desc_factory_->set_secure(secure_policy);
840 JsepSessionDescription* offer(
841 new JsepSessionDescription(JsepSessionDescription::kOffer));
842 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
843 session_id, session_version)) {
844 delete offer;
845 offer = NULL;
846 }
847 return offer;
848 }
849 JsepSessionDescription* CreateRemoteOffer(
850 cricket::MediaSessionOptions options) {
851 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
852 kSessionVersion, NULL);
853 }
854 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000855 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
856 return CreateRemoteOfferWithVersion(
857 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 }
859 JsepSessionDescription* CreateRemoteOffer(
860 cricket::MediaSessionOptions options,
861 const SessionDescriptionInterface* current_desc) {
862 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
863 kSessionVersion, current_desc);
864 }
865
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000866 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
867 const char* sctp_stream_name, int new_port,
868 cricket::MediaSessionOptions options) {
869 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000870 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
871 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000872 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
873 }
874
875 // Takes ownership of offer_basis (and deletes it).
876 JsepSessionDescription* ChangeSDPSctpPort(
877 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
878 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
879 // SessionDescription from the mutated string.
880 const char* default_port_str = "5000";
881 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000882 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000883 std::string offer_str;
884 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000885 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000886 new_port_str, strlen(new_port_str),
887 &offer_str);
888 JsepSessionDescription* offer = new JsepSessionDescription(
889 offer_basis->type());
890 delete offer_basis;
891 offer->Initialize(offer_str, NULL);
892 return offer;
893 }
894
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
896 // before this function to decide which streams to create.
897 JsepSessionDescription* CreateRemoteOffer() {
898 cricket::MediaSessionOptions options;
899 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
900 return CreateRemoteOffer(options, session_->remote_description());
901 }
902
903 JsepSessionDescription* CreateRemoteAnswer(
904 const SessionDescriptionInterface* offer,
905 cricket::MediaSessionOptions options,
906 cricket::SecurePolicy policy) {
907 desc_factory_->set_secure(policy);
908 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000909 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 JsepSessionDescription* answer(
911 new JsepSessionDescription(JsepSessionDescription::kAnswer));
912 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
913 options, NULL),
914 session_id, kSessionVersion)) {
915 delete answer;
916 answer = NULL;
917 }
918 return answer;
919 }
920
921 JsepSessionDescription* CreateRemoteAnswer(
922 const SessionDescriptionInterface* offer,
923 cricket::MediaSessionOptions options) {
924 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
925 }
926
927 // Creates an answer session description with streams based on
928 // |mediastream_signaling_|. Call
929 // mediastream_signaling_.UseOptionsWithStreamX() before this function
930 // to decide which streams to create.
931 JsepSessionDescription* CreateRemoteAnswer(
932 const SessionDescriptionInterface* offer) {
933 cricket::MediaSessionOptions options;
934 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
935 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
936 }
937
938 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000939 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000940 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000942
943 PeerConnectionInterface::RTCOfferAnswerOptions options;
944 options.use_rtp_mux = bundle;
945
946 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
948 // and answer.
949 SetLocalDescriptionWithoutError(offer);
950
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000951 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000952 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 std::string sdp;
954 EXPECT_TRUE(answer->ToString(&sdp));
955
956 size_t expected_candidate_num = 2;
957 if (!rtcp_mux) {
958 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
959 // for rtp and rtcp.
960 expected_candidate_num = 4;
961 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 const std::string kRtcpMux = "a=rtcp-mux";
963 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 kXRtcpMux.c_str(), kXRtcpMux.length(),
966 &sdp);
967 }
968
969 SessionDescriptionInterface* new_answer = CreateSessionDescription(
970 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971
972 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000973 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
975 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
976 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
977 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
978 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
979 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
980 if (bundle) {
981 EXPECT_TRUE(c0.IsEquivalent(c1));
982 } else {
983 EXPECT_FALSE(c0.IsEquivalent(c1));
984 }
985 }
986 }
987 // Tests that we can only send DTMF when the dtmf codec is supported.
988 void TestCanInsertDtmf(bool can) {
989 if (can) {
990 InitWithDtmfCodec();
991 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000992 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 }
994 mediastream_signaling_.SendAudioVideoStream1();
995 CreateAndSetRemoteOfferAndLocalAnswer();
996 EXPECT_FALSE(session_->CanInsertDtmf(""));
997 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
998 }
999
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001000 // Helper class to configure loopback network and verify Best
1001 // Connection using right IP protocol for TestLoopbackCall
1002 // method. LoopbackNetworkManager applies firewall rules to block
1003 // all ping traffic once ICE completed, and remove them to observe
1004 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1005 // verifies the best connection is using the right IP protocol after
1006 // initial ICE convergences.
1007
1008 class LoopbackNetworkConfiguration {
1009 public:
1010 LoopbackNetworkConfiguration()
1011 : test_ipv6_network_(false),
1012 test_extra_ipv4_network_(false),
1013 best_connection_after_initial_ice_converged_(1, 0) {}
1014
1015 // Used to track the expected best connection count in each IP protocol.
1016 struct ExpectedBestConnection {
1017 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1018 : ipv4_count_(ipv4_count),
1019 ipv6_count_(ipv6_count) {}
1020
1021 int ipv4_count_;
1022 int ipv6_count_;
1023 };
1024
1025 bool test_ipv6_network_;
1026 bool test_extra_ipv4_network_;
1027 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1028
1029 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001030 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001031 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1032 }
1033
1034 private:
jbauchac8869e2015-07-03 01:36:14 -07001035 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001036 const ExpectedBestConnection& expected) const {
1037 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001038 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1039 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001040 expected.ipv4_count_);
1041 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001042 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1043 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001044 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001045 // This is used in the loopback call so there is only single host to host
1046 // candidate pair.
1047 EXPECT_EQ(metrics_observer->GetEnumCounter(
1048 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1049 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001050 0);
1051 EXPECT_EQ(metrics_observer->GetEnumCounter(
1052 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1053 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001054 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001055 }
1056 };
1057
1058 class LoopbackNetworkManager {
1059 public:
1060 LoopbackNetworkManager(WebRtcSessionTest* session,
1061 const LoopbackNetworkConfiguration& config)
1062 : config_(config) {
1063 session->AddInterface(
1064 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1065 if (config_.test_extra_ipv4_network_) {
1066 session->AddInterface(
1067 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1068 }
1069 if (config_.test_ipv6_network_) {
1070 session->AddInterface(
1071 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1072 }
1073 }
1074
1075 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1076 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1077 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1078 if (config_.test_extra_ipv4_network_) {
1079 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1080 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1081 }
1082 if (config_.test_ipv6_network_) {
1083 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1084 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1085 }
1086 }
1087
1088 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1089
1090 private:
1091 LoopbackNetworkConfiguration config_;
1092 };
1093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 // The method sets up a call from the session to itself, in a loopback
1095 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001096 // disconnection, and then a permanent disconnection.
1097 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1099 // While running the call, this method also checks if the session goes through
1100 // the correct sequence of ICE states when a connection is established,
1101 // broken, and re-established.
1102 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001103 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1104 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001106
1107 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1108 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001109 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001111 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112
1113 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1114 observer_.ice_gathering_state_);
1115 SetLocalDescriptionWithoutError(offer);
1116 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1117 observer_.ice_connection_state_);
1118 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1119 observer_.ice_gathering_state_,
1120 kIceCandidatesTimeout);
1121 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1122 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1123 observer_.ice_gathering_state_,
1124 kIceCandidatesTimeout);
1125
1126 std::string sdp;
1127 offer->ToString(&sdp);
1128 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001129 webrtc::CreateSessionDescription(
1130 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 ASSERT_TRUE(desc != NULL);
1132 SetRemoteDescriptionWithoutError(desc);
1133
1134 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1135 observer_.ice_connection_state_,
1136 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001137
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001138 // The ice connection state is "Connected" too briefly to catch in a test.
1139 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 observer_.ice_connection_state_,
1141 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001143 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 // Adding firewall rule to block ping requests, which should cause
1145 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001146
1147 loopback_network_manager.ApplyFirewallRules(fss_.get());
1148
1149 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1151 observer_.ice_connection_state_,
1152 kIceCandidatesTimeout);
1153
jbauchac8869e2015-07-03 01:36:14 -07001154 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 // Session is automatically calling OnSignalingReady after creation of
1159 // new portallocator session which will allocate new set of candidates.
1160
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001161 LOG(LS_INFO) << "Firewall Rules cleared";
1162
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001163 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 observer_.ice_connection_state_,
1165 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001166
1167 // Now we block ping requests and wait until the ICE connection transitions
1168 // to the Failed state. This will take at least 30 seconds because it must
1169 // wait for the Port to timeout.
1170 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001171
1172 loopback_network_manager.ApplyFirewallRules(fss_.get());
1173 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001174 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001175 observer_.ice_connection_state_,
1176 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 }
1178
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001179 void TestLoopbackCall() {
1180 LoopbackNetworkConfiguration config;
1181 TestLoopbackCall(config);
1182 }
1183
guoweisd12140a2015-09-10 13:32:11 -07001184 void VerifyTransportType(const std::string& content_name,
1185 cricket::TransportProtocol protocol) {
1186 const cricket::Transport* transport = session_->GetTransport(content_name);
1187 ASSERT_TRUE(transport != NULL);
1188 EXPECT_EQ(protocol, transport->protocol());
1189 }
1190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001191 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1192 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001193 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1194 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1195
1196 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1198 codecs.push_back(kCNCodec1);
1199 codecs.push_back(kCNCodec2);
1200 media_engine_->SetAudioCodecs(codecs);
1201 desc_factory_->set_audio_codecs(codecs);
1202 }
1203
1204 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1205 const cricket::ContentDescription* description = content->description;
1206 ASSERT(description != NULL);
1207 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001208 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 ASSERT(audio_content_desc != NULL);
1210 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1211 if (audio_content_desc->codecs()[i].name == "CN")
1212 return false;
1213 }
1214 return true;
1215 }
1216
1217 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001218 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 dci.reliable = false;
1220 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001221 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 SetLocalDescriptionWithoutError(offer);
1223 }
1224
wu@webrtc.org91053e72013-08-10 07:18:04 +00001225 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001226 RTCCertificateGenerationMethod cert_gen_method,
1227 CreateSessionDescriptionRequest::Type type) {
1228 InitWithDtls(cert_gen_method);
1229 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1230 }
1231
1232 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1233 CreateSessionDescriptionRequest::Type type) {
1234 InitWithDtlsIdentityGenFail();
1235 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1236 }
1237
1238 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001239 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001240 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001241 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001242 if (type == CreateSessionDescriptionRequest::kAnswer) {
1243 cricket::MediaSessionOptions options;
1244 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001245 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001246 ASSERT_TRUE(offer.get() != NULL);
1247 SetRemoteDescriptionWithoutError(offer.release());
1248 }
1249
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001250 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001251 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001253 observers[kNumber];
1254 for (int i = 0; i < kNumber; ++i) {
1255 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1256 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001257 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001258 } else {
1259 session_->CreateAnswer(observers[i], NULL);
1260 }
1261 }
1262
1263 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1264 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1265 WebRtcSessionCreateSDPObserverForTest::kFailed;
1266
1267 for (int i = 0; i < kNumber; ++i) {
1268 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1269 if (success) {
1270 EXPECT_TRUE(observers[i]->description() != NULL);
1271 } else {
1272 EXPECT_TRUE(observers[i]->description() == NULL);
1273 }
1274 }
1275 }
1276
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001277 void ConfigureAllocatorWithTurn() {
1278 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1279 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1280 relay_server.credentials = credentials;
1281 relay_server.ports.push_back(cricket::ProtocolAddress(
1282 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1283 allocator_->AddRelay(relay_server);
1284 allocator_->set_step_delay(cricket::kMinimumStepDelay);
guoweisd12140a2015-09-10 13:32:11 -07001285 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1286 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001287 }
1288
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 cricket::FakeMediaEngine* media_engine_;
1290 cricket::FakeDataEngine* data_engine_;
1291 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001292 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1293 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001294 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1295 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1296 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1297 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1298 rtc::SocketServerScope ss_scope_;
1299 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001300 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001301 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001302 rtc::FakeNetworkManager network_manager_;
1303 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001304 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001305 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001307 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 MockIceObserver observer_;
1309 cricket::FakeVideoMediaChannel* video_channel_;
1310 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001311 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312};
1313
Henrik Boström87713d02015-08-25 09:53:21 +02001314TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1315 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001316 // SDES is disabled when DTLS is on.
1317 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318}
1319
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001320TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001321 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001322 // SDES is required if DTLS is off.
1323 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001324}
1325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1327 TestSessionCandidatesWithBundleRtcpMux(false, false);
1328}
1329
1330// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1331// with rtcp-mux and/or bundle.
1332TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1333 TestSessionCandidatesWithBundleRtcpMux(false, true);
1334}
1335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1337 TestSessionCandidatesWithBundleRtcpMux(true, true);
1338}
1339
1340TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001341 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1342 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001343 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 mediastream_signaling_.SendAudioVideoStream1();
1345 InitiateCall();
1346 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1347 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1348 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1349}
1350
1351TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001352 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1353 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001354 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001355 rtc::FP_UDP,
1356 rtc::FD_ANY,
1357 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001358 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 mediastream_signaling_.SendAudioVideoStream1();
1360 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001361 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1363 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1364 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1365}
1366
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001367// Test session delivers no candidates gathered when constraint set to "none".
1368TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1369 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001370 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001371 mediastream_signaling_.SendAudioVideoStream1();
1372 InitiateCall();
1373 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1374 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1375 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1376}
1377
1378// Test session delivers only relay candidates gathered when constaint set to
1379// "relay".
1380TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1381 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1382 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001383 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001384 mediastream_signaling_.SendAudioVideoStream1();
1385 InitiateCall();
1386 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1387 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1388 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1389 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1390 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1391 observer_.mline_0_candidates_[i].type());
1392 }
1393 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1394 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1395 observer_.mline_1_candidates_[i].type());
1396 }
1397}
1398
1399// Test session delivers all candidates gathered when constaint set to "all".
1400TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1401 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001402 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001403 mediastream_signaling_.SendAudioVideoStream1();
1404 InitiateCall();
1405 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1406 // Host + STUN. By default allocator is disabled to gather relay candidates.
1407 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1408 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1409}
1410
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001411TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001412 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001413 SessionDescriptionInterface* offer = NULL;
1414 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1415 std::string unknown_action;
1416 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1417 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1418}
1419
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420// Test creating offers and receive answers and make sure the
1421// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001422TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001423 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001425 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 const std::string session_id_orig = offer->session_id();
1427 const std::string session_version_orig = offer->session_version();
1428 SetLocalDescriptionWithoutError(offer);
1429
1430 mediastream_signaling_.SendAudioVideoStream2();
1431 SessionDescriptionInterface* answer =
1432 CreateRemoteAnswer(session_->local_description());
1433 SetRemoteDescriptionWithoutError(answer);
1434
1435 video_channel_ = media_engine_->GetVideoChannel(0);
1436 voice_channel_ = media_engine_->GetVoiceChannel(0);
1437
1438 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1439 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1440
1441 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1442 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1443
1444 ASSERT_EQ(1u, video_channel_->send_streams().size());
1445 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1446 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1447 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1448
1449 // Create new offer without send streams.
1450 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001451 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452
1453 // Verify the session id is the same and the session version is
1454 // increased.
1455 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001456 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1457 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458
1459 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001460 EXPECT_EQ(0u, video_channel_->send_streams().size());
1461 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462
1463 mediastream_signaling_.SendAudioVideoStream2();
1464 answer = CreateRemoteAnswer(session_->local_description());
1465 SetRemoteDescriptionWithoutError(answer);
1466
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 // Make sure the receive streams have not changed.
1468 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1469 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1470 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1471 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1472}
1473
1474// Test receiving offers and creating answers and make sure the
1475// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001476TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001479 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001480 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 SetRemoteDescriptionWithoutError(offer);
1482
1483 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001484 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001485 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 SetLocalDescriptionWithoutError(answer);
1487
1488 const std::string session_id_orig = answer->session_id();
1489 const std::string session_version_orig = answer->session_version();
1490
1491 video_channel_ = media_engine_->GetVideoChannel(0);
1492 voice_channel_ = media_engine_->GetVoiceChannel(0);
1493
1494 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1495 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1496
1497 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1498 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1499
1500 ASSERT_EQ(1u, video_channel_->send_streams().size());
1501 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1502 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1503 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1504
1505 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001506 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 SetRemoteDescriptionWithoutError(offer);
1508
1509 // Answer by turning off all send streams.
1510 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001511 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512
1513 // Verify the session id is the same and the session version is
1514 // increased.
1515 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001516 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1517 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 SetLocalDescriptionWithoutError(answer);
1519
1520 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1521 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1522 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1523 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1524 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1525 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1526
1527 // Make sure we have no send streams.
1528 EXPECT_EQ(0u, video_channel_->send_streams().size());
1529 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1530}
1531
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001532TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001534 media_engine_->set_fail_create_channel(true);
1535
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001536 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001537 ASSERT_TRUE(offer != NULL);
1538 // SetRemoteDescription and SetLocalDescription will take the ownership of
1539 // the offer.
1540 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001541 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001542 ASSERT_TRUE(offer != NULL);
1543 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1544}
1545
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001546//
1547// Tests for creating/setting SDP under different SDES/DTLS polices:
1548//
1549// --DTLS off and SDES on
1550// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1551// set local/remote offer/answer with crypto --> success
1552// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1553// failure
1554// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1555// failure
1556// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1557// failure
1558//
1559// --DTLS on and SDES off
1560// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1561// set local/remote offer/answer with DTLS fingerprint --> success
1562// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1563// fingerprint --> failure
1564// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1565// --> failure
1566// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1567// --> failure
1568//
1569// --Encryption disabled: DTLS off and SDES off
1570// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1571// answer without SDES or DTLS --> success
1572// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1573// answer without SDES or DTLS --> success
1574//
1575
1576// Test that we return a failure when applying a remote/local offer that doesn't
1577// have cryptos enabled when DTLS is off.
1578TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001579 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001581 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 JsepSessionDescription* offer = CreateRemoteOffer(
1583 options, cricket::SEC_DISABLED);
1584 ASSERT_TRUE(offer != NULL);
1585 VerifyNoCryptoParams(offer->description(), false);
1586 // SetRemoteDescription and SetLocalDescription will take the ownership of
1587 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001588 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1590 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592}
1593
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594// Test that we return a failure when applying a local answer that doesn't have
1595// cryptos enabled when DTLS is off.
1596TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001597 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 SessionDescriptionInterface* offer = NULL;
1599 SessionDescriptionInterface* answer = NULL;
1600 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1601 // SetRemoteDescription and SetLocalDescription will take the ownership of
1602 // the offer.
1603 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001604 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605}
1606
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001607// Test we will return fail when apply an remote answer that doesn't have
1608// crypto enabled when DTLS is off.
1609TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001610 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 SessionDescriptionInterface* offer = NULL;
1612 SessionDescriptionInterface* answer = NULL;
1613 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1614 // SetRemoteDescription and SetLocalDescription will take the ownership of
1615 // the offer.
1616 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618}
1619
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001620// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1621// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001622TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001623 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001625 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SetFactoryDtlsSrtp();
1627 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001628 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001629 JsepSessionDescription* offer =
1630 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 ASSERT_TRUE(offer != NULL);
1632 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001633 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
1635 // SetRemoteDescription will take the ownership of the offer.
1636 SetRemoteDescriptionWithoutError(offer);
1637
1638 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001639 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 ASSERT_TRUE(answer != NULL);
1641 VerifyFingerprintStatus(answer->description(), true);
1642 // Check that we don't have an a=crypto line in the answer.
1643 VerifyNoCryptoParams(answer->description(), true);
1644
1645 // Now set the local description, which should work, even without a=crypto.
1646 SetLocalDescriptionWithoutError(answer);
1647}
1648
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001649// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1650// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001651TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001652 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001654 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001655 SetFactoryDtlsSrtp();
1656
1657 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001658 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001659 ASSERT_TRUE(offer != NULL);
1660 VerifyFingerprintStatus(offer->description(), true);
1661 // Check that we don't have an a=crypto line in the offer.
1662 VerifyNoCryptoParams(offer->description(), true);
1663
1664 // Now set the local description, which should work, even without a=crypto.
1665 SetLocalDescriptionWithoutError(offer);
1666
1667 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001668 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001669 JsepSessionDescription* answer =
1670 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1671 ASSERT_TRUE(answer != NULL);
1672 VerifyFingerprintStatus(answer->description(), true);
1673 VerifyNoCryptoParams(answer->description(), true);
1674
1675 // SetRemoteDescription will take the ownership of the answer.
1676 SetRemoteDescriptionWithoutError(answer);
1677}
1678
1679// Test that if we support DTLS and the other side didn't offer a fingerprint,
1680// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001681TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001682 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001683 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001685 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001686 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 JsepSessionDescription* offer = CreateRemoteOffer(
1688 options, cricket::SEC_REQUIRED);
1689 ASSERT_TRUE(offer != NULL);
1690 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001691 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693 // SetRemoteDescription will take the ownership of the offer.
1694 SetRemoteDescriptionOfferExpectError(
1695 kSdpWithoutDtlsFingerprint, offer);
1696
1697 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1698 // SetLocalDescription will take the ownership of the offer.
1699 SetLocalDescriptionOfferExpectError(
1700 kSdpWithoutDtlsFingerprint, offer);
1701}
1702
1703// Test that we return a failure when applying a local answer that doesn't have
1704// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001705TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001706 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001707 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 SessionDescriptionInterface* offer = NULL;
1709 SessionDescriptionInterface* answer = NULL;
1710 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1711
1712 // SetRemoteDescription and SetLocalDescription will take the ownership of
1713 // the offer and answer.
1714 SetRemoteDescriptionWithoutError(offer);
1715 SetLocalDescriptionAnswerExpectError(
1716 kSdpWithoutDtlsFingerprint, answer);
1717}
1718
1719// Test that we return a failure when applying a remote answer that doesn't have
1720// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001721TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001722 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001723 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1724 // result of using the "UDP/TLS/RTP/SAVPF" profile.
Henrik Boström87713d02015-08-25 09:53:21 +02001725 InitWithDtls(GetParam());
deadbeeff3938292015-07-15 12:20:53 -07001726 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001727 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001729 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730 JsepSessionDescription* answer =
1731 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1732
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer and answer.
1735 SetLocalDescriptionWithoutError(offer);
1736 SetRemoteDescriptionAnswerExpectError(
1737 kSdpWithoutDtlsFingerprint, answer);
1738}
1739
1740// Test that we create a local offer without SDES or DTLS and accept a remote
1741// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001742TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 mediastream_signaling_.SendAudioVideoStream1();
1744 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001745 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746
1747 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001748 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001749 ASSERT_TRUE(offer != NULL);
1750 VerifyFingerprintStatus(offer->description(), false);
1751 // Check that we don't have an a=crypto line in the offer.
1752 VerifyNoCryptoParams(offer->description(), false);
1753
1754 // Now set the local description, which should work, even without a=crypto.
1755 SetLocalDescriptionWithoutError(offer);
1756
1757 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001758 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759 JsepSessionDescription* answer =
1760 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1761 ASSERT_TRUE(answer != NULL);
1762 VerifyFingerprintStatus(answer->description(), false);
1763 VerifyNoCryptoParams(answer->description(), false);
1764
1765 // SetRemoteDescription will take the ownership of the answer.
1766 SetRemoteDescriptionWithoutError(answer);
1767}
1768
1769// Test that we create a local answer without SDES or DTLS and accept a remote
1770// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001771TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001773 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774
1775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001776 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777 JsepSessionDescription* offer =
1778 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1779 ASSERT_TRUE(offer != NULL);
1780 VerifyFingerprintStatus(offer->description(), false);
1781 VerifyNoCryptoParams(offer->description(), false);
1782
1783 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 SetRemoteDescriptionWithoutError(offer);
1785
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001787 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 ASSERT_TRUE(answer != NULL);
1789 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001790 // Check that we don't have an a=crypto line in the answer.
1791 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001793 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 SetLocalDescriptionWithoutError(answer);
1795}
1796
1797TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001798 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 mediastream_signaling_.SendNothing();
1800 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001801 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 SetLocalDescriptionWithoutError(offer);
1803
1804 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001805 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 SetLocalDescriptionWithoutError(offer2);
1807}
1808
1809TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001810 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 mediastream_signaling_.SendNothing();
1812 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001813 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 SetRemoteDescriptionWithoutError(offer);
1815
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001816 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 SetRemoteDescriptionWithoutError(offer2);
1818}
1819
1820TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001821 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001823 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001825 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001826 SetRemoteDescriptionOfferExpectError(
1827 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828}
1829
1830TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001831 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001833 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001835 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001836 SetLocalDescriptionOfferExpectError(
1837 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838}
1839
1840TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001841 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 mediastream_signaling_.SendNothing();
1843 SessionDescriptionInterface* offer = CreateRemoteOffer();
1844 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1845
1846 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001847 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1849 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1850
1851 mediastream_signaling_.SendAudioVideoStream1();
1852 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001853 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1855
1856 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1857
1858 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001859 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1861}
1862
1863TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001864 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001866 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1868
1869 JsepSessionDescription* pranswer =
1870 CreateRemoteAnswer(session_->local_description());
1871 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1872
1873 SetRemoteDescriptionExpectState(pranswer,
1874 BaseSession::STATE_RECEIVEDPRACCEPT);
1875
1876 mediastream_signaling_.SendAudioVideoStream1();
1877 JsepSessionDescription* pranswer2 =
1878 CreateRemoteAnswer(session_->local_description());
1879 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1880
1881 SetRemoteDescriptionExpectState(pranswer2,
1882 BaseSession::STATE_RECEIVEDPRACCEPT);
1883
1884 mediastream_signaling_.SendAudioVideoStream2();
1885 SessionDescriptionInterface* answer =
1886 CreateRemoteAnswer(session_->local_description());
1887 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1888}
1889
1890TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001891 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001893 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 SessionDescriptionInterface* answer =
1896 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001897 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1898 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899}
1900
1901TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001902 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001904 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 SessionDescriptionInterface* answer =
1907 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001908 SetRemoteDescriptionAnswerExpectError(
1909 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910}
1911
1912TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001913 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 mediastream_signaling_.SendAudioVideoStream1();
1915
1916 cricket::Candidate candidate;
1917 candidate.set_component(1);
1918 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1919
1920 // Fail since we have not set a offer description.
1921 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1922
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001923 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 SetLocalDescriptionWithoutError(offer);
1925 // Candidate should be allowed to add before remote description.
1926 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1927 candidate.set_component(2);
1928 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1929 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1930
1931 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1932 session_->local_description());
1933 SetRemoteDescriptionWithoutError(answer);
1934
1935 // Verifying the candidates are copied properly from internal vector.
1936 const SessionDescriptionInterface* remote_desc =
1937 session_->remote_description();
1938 ASSERT_TRUE(remote_desc != NULL);
1939 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1940 const IceCandidateCollection* candidates =
1941 remote_desc->candidates(kMediaContentIndex0);
1942 ASSERT_EQ(2u, candidates->count());
1943 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1944 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1945 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1946 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1947
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001948 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1949 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 candidate.set_component(2);
1951 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1952 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001953 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954
1955 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1956 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1957}
1958
1959// Test that a remote candidate is added to the remote session description and
1960// that it is retained if the remote session description is changed.
1961TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001962 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 cricket::Candidate candidate1;
1964 candidate1.set_component(1);
1965 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1966 candidate1);
1967 mediastream_signaling_.SendAudioVideoStream1();
1968 CreateAndSetRemoteOfferAndLocalAnswer();
1969
1970 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1971 const SessionDescriptionInterface* remote_desc =
1972 session_->remote_description();
1973 ASSERT_TRUE(remote_desc != NULL);
1974 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1975 const IceCandidateCollection* candidates =
1976 remote_desc->candidates(kMediaContentIndex0);
1977 ASSERT_EQ(1u, candidates->count());
1978 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1979
1980 // Update the RemoteSessionDescription with a new session description and
1981 // a candidate and check that the new remote session description contains both
1982 // candidates.
1983 SessionDescriptionInterface* offer = CreateRemoteOffer();
1984 cricket::Candidate candidate2;
1985 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1986 candidate2);
1987 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1988 SetRemoteDescriptionWithoutError(offer);
1989
1990 remote_desc = session_->remote_description();
1991 ASSERT_TRUE(remote_desc != NULL);
1992 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1993 candidates = remote_desc->candidates(kMediaContentIndex0);
1994 ASSERT_EQ(2u, candidates->count());
1995 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1996 // Username and password have be updated with the TransportInfo of the
1997 // SessionDescription, won't be equal to the original one.
1998 candidate2.set_username(candidates->at(0)->candidate().username());
1999 candidate2.set_password(candidates->at(0)->candidate().password());
2000 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2001 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2002 // No need to verify the username and password.
2003 candidate1.set_username(candidates->at(1)->candidate().username());
2004 candidate1.set_password(candidates->at(1)->candidate().password());
2005 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2006
2007 // Test that the candidate is ignored if we can add the same candidate again.
2008 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2009}
2010
2011// Test that local candidates are added to the local session description and
2012// that they are retained if the local session description is changed.
2013TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002014 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002015 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 mediastream_signaling_.SendAudioVideoStream1();
2017 CreateAndSetRemoteOfferAndLocalAnswer();
2018
2019 const SessionDescriptionInterface* local_desc = session_->local_description();
2020 const IceCandidateCollection* candidates =
2021 local_desc->candidates(kMediaContentIndex0);
2022 ASSERT_TRUE(candidates != NULL);
2023 EXPECT_EQ(0u, candidates->count());
2024
2025 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2026
2027 local_desc = session_->local_description();
2028 candidates = local_desc->candidates(kMediaContentIndex0);
2029 ASSERT_TRUE(candidates != NULL);
2030 EXPECT_LT(0u, candidates->count());
2031 candidates = local_desc->candidates(1);
2032 ASSERT_TRUE(candidates != NULL);
2033 EXPECT_LT(0u, candidates->count());
2034
2035 // Update the session descriptions.
2036 mediastream_signaling_.SendAudioVideoStream1();
2037 CreateAndSetRemoteOfferAndLocalAnswer();
2038
2039 local_desc = session_->local_description();
2040 candidates = local_desc->candidates(kMediaContentIndex0);
2041 ASSERT_TRUE(candidates != NULL);
2042 EXPECT_LT(0u, candidates->count());
2043 candidates = local_desc->candidates(1);
2044 ASSERT_TRUE(candidates != NULL);
2045 EXPECT_LT(0u, candidates->count());
2046}
2047
2048// Test that we can set a remote session description with remote candidates.
2049TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002050 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051
2052 cricket::Candidate candidate1;
2053 candidate1.set_component(1);
2054 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2055 candidate1);
2056 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002057 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
2059 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2060 SetRemoteDescriptionWithoutError(offer);
2061
2062 const SessionDescriptionInterface* remote_desc =
2063 session_->remote_description();
2064 ASSERT_TRUE(remote_desc != NULL);
2065 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2066 const IceCandidateCollection* candidates =
2067 remote_desc->candidates(kMediaContentIndex0);
2068 ASSERT_EQ(1u, candidates->count());
2069 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2070
wu@webrtc.org91053e72013-08-10 07:18:04 +00002071 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 SetLocalDescriptionWithoutError(answer);
2073}
2074
2075// Test that offers and answers contains ice candidates when Ice candidates have
2076// been gathered.
2077TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002078 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002079 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 mediastream_signaling_.SendAudioVideoStream1();
2081 // Ice is started but candidates are not provided until SetLocalDescription
2082 // is called.
2083 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2084 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2085 CreateAndSetRemoteOfferAndLocalAnswer();
2086 // Wait until at least one local candidate has been collected.
2087 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2088 kIceCandidatesTimeout);
2089 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2090 kIceCandidatesTimeout);
2091
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002092 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2095 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2096 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2097 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2098
2099 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2100 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002101 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2103 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2104 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2105 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2106 SetLocalDescriptionWithoutError(answer);
2107}
2108
2109// Verifies TransportProxy and media channels are created with content names
2110// present in the SessionDescription.
2111TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002112 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002114 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 // CreateOffer creates session description with the content names "audio" and
2117 // "video". Goal is to modify these content names and verify transport channel
2118 // proxy in the BaseSession, as proxies are created with the content names
2119 // present in SDP.
2120 std::string sdp;
2121 EXPECT_TRUE(offer->ToString(&sdp));
2122 const std::string kAudioMid = "a=mid:audio";
2123 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2124 const std::string kVideoMid = "a=mid:video";
2125 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2126
2127 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002128 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 kAudioMidReplaceStr.c_str(),
2130 kAudioMidReplaceStr.length(),
2131 &sdp);
2132 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002133 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 kVideoMidReplaceStr.c_str(),
2135 kVideoMidReplaceStr.length(),
2136 &sdp);
2137
2138 SessionDescriptionInterface* modified_offer =
2139 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2140
2141 SetRemoteDescriptionWithoutError(modified_offer);
2142
2143 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002144 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 SetLocalDescriptionWithoutError(answer);
2146
2147 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2148 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2149 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2150 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2151}
2152
2153// Test that an offer contains the correct media content descriptions based on
2154// the send streams when no constraints have been set.
2155TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002156 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002157 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
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 the correct media content descriptions based on
2168// the send streams when no constraints have been set.
2169TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002170 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 // Test Audio only offer.
2172 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002173 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 const cricket::ContentInfo* content =
2176 cricket::GetFirstAudioContent(offer->description());
2177 EXPECT_TRUE(content != NULL);
2178 content = cricket::GetFirstVideoContent(offer->description());
2179 EXPECT_TRUE(content == NULL);
2180
2181 // Test Audio / Video offer.
2182 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002183 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 content = cricket::GetFirstAudioContent(offer->description());
2185 EXPECT_TRUE(content != NULL);
2186 content = cricket::GetFirstVideoContent(offer->description());
2187 EXPECT_TRUE(content != NULL);
2188}
2189
2190// Test that an offer contains no media content descriptions if
2191// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2192TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002193 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002194 PeerConnectionInterface::RTCOfferAnswerOptions options;
2195 options.offer_to_receive_audio = 0;
2196 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002198 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002199 CreateOffer(options));
2200
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 ASSERT_TRUE(offer != NULL);
2202 const cricket::ContentInfo* content =
2203 cricket::GetFirstAudioContent(offer->description());
2204 EXPECT_TRUE(content == NULL);
2205 content = cricket::GetFirstVideoContent(offer->description());
2206 EXPECT_TRUE(content == NULL);
2207}
2208
2209// Test that an offer contains only audio media content descriptions if
2210// kOfferToReceiveAudio constraints are set to true.
2211TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002212 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002213 PeerConnectionInterface::RTCOfferAnswerOptions options;
2214 options.offer_to_receive_audio =
2215 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2216
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002217 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002218 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219
2220 const cricket::ContentInfo* content =
2221 cricket::GetFirstAudioContent(offer->description());
2222 EXPECT_TRUE(content != NULL);
2223 content = cricket::GetFirstVideoContent(offer->description());
2224 EXPECT_TRUE(content == NULL);
2225}
2226
2227// Test that an offer contains audio and video media content descriptions if
2228// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2229TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002230 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002232 PeerConnectionInterface::RTCOfferAnswerOptions options;
2233 options.offer_to_receive_audio =
2234 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2235 options.offer_to_receive_video =
2236 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2237
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002238 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002239 CreateOffer(options));
2240
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 const cricket::ContentInfo* content =
2242 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002243 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002244
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 content = cricket::GetFirstVideoContent(offer->description());
2246 EXPECT_TRUE(content != NULL);
2247
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002248 // Sets constraints to false and verifies that audio/video contents are
2249 // removed.
2250 options.offer_to_receive_audio = 0;
2251 options.offer_to_receive_video = 0;
2252 offer.reset(CreateOffer(options));
2253
2254 content = cricket::GetFirstAudioContent(offer->description());
2255 EXPECT_TRUE(content == NULL);
2256 content = cricket::GetFirstVideoContent(offer->description());
2257 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258}
2259
2260// Test that an answer can not be created if the last remote description is not
2261// an offer.
2262TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002263 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002264 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 SetLocalDescriptionWithoutError(offer);
2266 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2267 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002268 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269}
2270
2271// Test that an answer contains the correct media content descriptions when no
2272// constraints have been set.
2273TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
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());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002278 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002279 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 const cricket::ContentInfo* content =
2281 cricket::GetFirstAudioContent(answer->description());
2282 ASSERT_TRUE(content != NULL);
2283 EXPECT_FALSE(content->rejected);
2284
2285 content = cricket::GetFirstVideoContent(answer->description());
2286 ASSERT_TRUE(content != NULL);
2287 EXPECT_FALSE(content->rejected);
2288}
2289
2290// Test that an answer contains the correct media content descriptions when no
2291// constraints have been set and the offer only contain audio.
2292TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002293 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 // Create a remote offer with audio only.
2295 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002296
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002297 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 CreateRemoteOffer(options));
2299 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2300 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2301
2302 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002303 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002304 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 const cricket::ContentInfo* content =
2306 cricket::GetFirstAudioContent(answer->description());
2307 ASSERT_TRUE(content != NULL);
2308 EXPECT_FALSE(content->rejected);
2309
2310 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2311}
2312
2313// Test that an answer contains the correct media content descriptions when no
2314// constraints have been set.
2315TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002316 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002318 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 SetRemoteDescriptionWithoutError(offer.release());
2320 // Test with a stream with tracks.
2321 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002322 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002323 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 const cricket::ContentInfo* content =
2325 cricket::GetFirstAudioContent(answer->description());
2326 ASSERT_TRUE(content != NULL);
2327 EXPECT_FALSE(content->rejected);
2328
2329 content = cricket::GetFirstVideoContent(answer->description());
2330 ASSERT_TRUE(content != NULL);
2331 EXPECT_FALSE(content->rejected);
2332}
2333
2334// Test that an answer contains the correct media content descriptions when
2335// constraints have been set but no stream is sent.
2336TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002337 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002339 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 SetRemoteDescriptionWithoutError(offer.release());
2341
2342 webrtc::FakeConstraints constraints_no_receive;
2343 constraints_no_receive.SetMandatoryReceiveAudio(false);
2344 constraints_no_receive.SetMandatoryReceiveVideo(false);
2345
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002346 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002347 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 const cricket::ContentInfo* content =
2349 cricket::GetFirstAudioContent(answer->description());
2350 ASSERT_TRUE(content != NULL);
2351 EXPECT_TRUE(content->rejected);
2352
2353 content = cricket::GetFirstVideoContent(answer->description());
2354 ASSERT_TRUE(content != NULL);
2355 EXPECT_TRUE(content->rejected);
2356}
2357
2358// Test that an answer contains the correct media content descriptions when
2359// constraints have been set and streams are sent.
2360TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002361 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002363 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 SetRemoteDescriptionWithoutError(offer.release());
2365
2366 webrtc::FakeConstraints constraints_no_receive;
2367 constraints_no_receive.SetMandatoryReceiveAudio(false);
2368 constraints_no_receive.SetMandatoryReceiveVideo(false);
2369
2370 // Test with a stream with tracks.
2371 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002372 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002373 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
2375 // TODO(perkj): Should the direction be set to SEND_ONLY?
2376 const cricket::ContentInfo* content =
2377 cricket::GetFirstAudioContent(answer->description());
2378 ASSERT_TRUE(content != NULL);
2379 EXPECT_FALSE(content->rejected);
2380
2381 // TODO(perkj): Should the direction be set to SEND_ONLY?
2382 content = cricket::GetFirstVideoContent(answer->description());
2383 ASSERT_TRUE(content != NULL);
2384 EXPECT_FALSE(content->rejected);
2385}
2386
2387TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2388 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002389 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002390 PeerConnectionInterface::RTCOfferAnswerOptions options;
2391 options.offer_to_receive_audio =
2392 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2393 options.voice_activity_detection = false;
2394
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002395 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002396 CreateOffer(options));
2397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 const cricket::ContentInfo* content =
2399 cricket::GetFirstAudioContent(offer->description());
2400 EXPECT_TRUE(content != NULL);
2401 EXPECT_TRUE(VerifyNoCNCodecs(content));
2402}
2403
2404TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2405 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002406 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002408 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 SetRemoteDescriptionWithoutError(offer.release());
2410
2411 webrtc::FakeConstraints constraints;
2412 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002413 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002414 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415 const cricket::ContentInfo* content =
2416 cricket::GetFirstAudioContent(answer->description());
2417 ASSERT_TRUE(content != NULL);
2418 EXPECT_TRUE(VerifyNoCNCodecs(content));
2419}
2420
2421// This test verifies the call setup when remote answer with audio only and
2422// later updates with video.
2423TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002424 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2426 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2427
2428 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002429 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
2431 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2433
2434 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2435 // and answer;
2436 SetLocalDescriptionWithoutError(offer);
2437 SetRemoteDescriptionWithoutError(answer);
2438
2439 video_channel_ = media_engine_->GetVideoChannel(0);
2440 voice_channel_ = media_engine_->GetVoiceChannel(0);
2441
2442 ASSERT_TRUE(video_channel_ == NULL);
2443
2444 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2445 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2446 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2447
2448 // Let the remote end update the session descriptions, with Audio and Video.
2449 mediastream_signaling_.SendAudioVideoStream2();
2450 CreateAndSetRemoteOfferAndLocalAnswer();
2451
2452 video_channel_ = media_engine_->GetVideoChannel(0);
2453 voice_channel_ = media_engine_->GetVoiceChannel(0);
2454
2455 ASSERT_TRUE(video_channel_ != NULL);
2456 ASSERT_TRUE(voice_channel_ != NULL);
2457
2458 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2459 ASSERT_EQ(1u, video_channel_->send_streams().size());
2460 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2461 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2462 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2463 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2464 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2465 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2466
2467 // Change session back to audio only.
2468 mediastream_signaling_.UseOptionsAudioOnly();
2469 CreateAndSetRemoteOfferAndLocalAnswer();
2470
2471 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2472 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2473 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2474 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2475 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2476}
2477
2478// This test verifies the call setup when remote answer with video only and
2479// later updates with audio.
2480TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002481 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2483 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2484 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002485 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486
2487 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002488 options.recv_audio = false;
2489 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2491 offer, options, cricket::SEC_ENABLED);
2492
2493 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2494 // and answer.
2495 SetLocalDescriptionWithoutError(offer);
2496 SetRemoteDescriptionWithoutError(answer);
2497
2498 video_channel_ = media_engine_->GetVideoChannel(0);
2499 voice_channel_ = media_engine_->GetVoiceChannel(0);
2500
2501 ASSERT_TRUE(voice_channel_ == NULL);
2502 ASSERT_TRUE(video_channel_ != NULL);
2503
2504 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2505 ASSERT_EQ(1u, video_channel_->send_streams().size());
2506 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2507
2508 // Update the session descriptions, with Audio and Video.
2509 mediastream_signaling_.SendAudioVideoStream2();
2510 CreateAndSetRemoteOfferAndLocalAnswer();
2511
2512 voice_channel_ = media_engine_->GetVoiceChannel(0);
2513 ASSERT_TRUE(voice_channel_ != NULL);
2514
2515 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2516 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2517 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2518 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2519
2520 // Change session back to video only.
2521 mediastream_signaling_.UseOptionsVideoOnly();
2522 CreateAndSetRemoteOfferAndLocalAnswer();
2523
2524 video_channel_ = media_engine_->GetVideoChannel(0);
2525 voice_channel_ = media_engine_->GetVoiceChannel(0);
2526
2527 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2528 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2529 ASSERT_EQ(1u, video_channel_->send_streams().size());
2530 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2531}
2532
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002534 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002536 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 VerifyCryptoParams(offer->description());
2538 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002539 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 VerifyCryptoParams(answer->description());
2541}
2542
2543TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002544 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002547 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 VerifyNoCryptoParams(offer->description(), false);
2549}
2550
2551TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002552 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 VerifyAnswerFromNonCryptoOffer();
2554}
2555
2556TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002557 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 VerifyAnswerFromCryptoOffer();
2559}
2560
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002561// This test verifies that setLocalDescription fails if
2562// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2563TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002564 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002565 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002566 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2567
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002568 std::string sdp;
2569 RemoveIceUfragPwdLines(offer.get(), &sdp);
2570 SessionDescriptionInterface* modified_offer =
2571 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002572 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002573}
2574
2575// This test verifies that setRemoteDescription fails if
2576// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2577TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002579 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002580 std::string sdp;
2581 RemoveIceUfragPwdLines(offer.get(), &sdp);
2582 SessionDescriptionInterface* modified_offer =
2583 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002584 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002585}
2586
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002587// This test verifies that setLocalDescription fails if local offer has
2588// too short ice ufrag and pwd strings.
2589TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002590 Init();
guoweisd12140a2015-09-10 13:32:11 -07002591 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002592 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002593 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2594
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002595 std::string sdp;
2596 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2597 // recommended values of 4 and 22 bytes respectively.
2598 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2599 SessionDescriptionInterface* modified_offer =
2600 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2601 std::string error;
2602 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2603
2604 // Test with string greater than 256.
2605 sdp.clear();
2606 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2607 &sdp);
2608 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2609 NULL);
2610 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2611}
2612
2613// This test verifies that setRemoteDescription fails if remote offer has
2614// too short ice ufrag and pwd strings.
2615TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002616 Init();
guoweisd12140a2015-09-10 13:32:11 -07002617 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002618 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002619 std::string sdp;
2620 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2621 // recommended values of 4 and 22 bytes respectively.
2622 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2623 SessionDescriptionInterface* modified_offer =
2624 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2625 std::string error;
2626 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2627
2628 sdp.clear();
2629 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2630 &sdp);
2631 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2632 NULL);
2633 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2634}
2635
honghaiz503726c2015-07-31 12:37:38 -07002636// Test that if the remote description indicates the peer requested ICE restart
2637// (via a new ufrag or pwd), the old ICE candidates are not copied,
2638// and vice versa.
2639TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2640 Init();
2641 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2642
2643 // Create the first offer.
2644 std::string sdp;
2645 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2646 "abcdefghijklmnopqrstuvwx", &sdp);
2647 SessionDescriptionInterface* offer1 =
2648 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2649 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2650 0, "", "", "relay", 0, "");
2651 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2652 candidate1);
2653 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2654 SetRemoteDescriptionWithoutError(offer1);
2655 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2656
2657 // The second offer has the same ufrag and pwd but different address.
2658 sdp.clear();
2659 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2660 "abcdefghijklmnopqrstuvwx", &sdp);
2661 SessionDescriptionInterface* offer2 =
2662 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2663 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2664 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2665 candidate1);
2666 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2667 SetRemoteDescriptionWithoutError(offer2);
2668 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2669
2670 // The third offer has a different ufrag and different address.
2671 sdp.clear();
2672 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2673 "abcdefghijklmnopqrstuvwx", &sdp);
2674 SessionDescriptionInterface* offer3 =
2675 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2676 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2677 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2678 candidate1);
2679 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2680 SetRemoteDescriptionWithoutError(offer3);
2681 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2682
2683 // The fourth offer has no candidate but a different ufrag/pwd.
2684 sdp.clear();
2685 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2686 "abcdefghijklmnopqrstuvyz", &sdp);
2687 SessionDescriptionInterface* offer4 =
2688 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2689 SetRemoteDescriptionWithoutError(offer4);
2690 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2691}
2692
Donald Curtisd4f769d2015-05-28 09:48:21 -07002693// Test that candidates sent to the "video" transport do not get pushed down to
2694// the "audio" transport channel when bundling using TransportProxy.
2695TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2696 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2697
2698 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2699 mediastream_signaling_.SendAudioVideoStream1();
2700
2701 PeerConnectionInterface::RTCOfferAnswerOptions options;
2702 options.use_rtp_mux = true;
2703
2704 SessionDescriptionInterface* offer = CreateRemoteOffer();
2705 SetRemoteDescriptionWithoutError(offer);
2706
2707 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2708 SetLocalDescriptionWithoutError(answer);
2709
2710 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2711 session_->GetTransportProxy("video")->impl());
2712
2713 cricket::Transport* t = session_->GetTransport("audio");
2714
2715 // Checks if one of the transport channels contains a connection using a given
2716 // port.
2717 auto connection_with_remote_port = [t](int port) {
2718 cricket::TransportStats stats;
2719 t->GetStats(&stats);
2720 for (auto& chan_stat : stats.channel_stats) {
2721 for (auto& conn_info : chan_stat.connection_infos) {
2722 if (conn_info.remote_candidate.address().port() == port) {
2723 return true;
2724 }
2725 }
2726 }
2727 return false;
2728 };
2729
2730 EXPECT_FALSE(connection_with_remote_port(5000));
2731 EXPECT_FALSE(connection_with_remote_port(5001));
2732 EXPECT_FALSE(connection_with_remote_port(6000));
2733
2734 // The way the *_WAIT checks work is they only wait if the condition fails,
2735 // which does not help in the case where state is not changing. This is
2736 // problematic in this test since we want to verify that adding a video
2737 // candidate does _not_ change state. So we interleave candidates and assume
2738 // that messages are executed in the order they were posted.
2739
2740 // First audio candidate.
2741 cricket::Candidate candidate0;
2742 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2743 candidate0.set_component(1);
2744 candidate0.set_protocol("udp");
2745 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2746 candidate0);
2747 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2748
2749 // Video candidate.
2750 cricket::Candidate candidate1;
2751 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2752 candidate1.set_component(1);
2753 candidate1.set_protocol("udp");
2754 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2755 candidate1);
2756 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2757
2758 // Second audio candidate.
2759 cricket::Candidate candidate2;
2760 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2761 candidate2.set_component(1);
2762 candidate2.set_protocol("udp");
2763 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2764 candidate2);
2765 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2766
2767 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2768 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2769
2770 // No need here for a _WAIT check since we are checking that state hasn't
2771 // changed: if this is false we would be doing waits for nothing and if this
2772 // is true then there will be no messages processed anyways.
2773 EXPECT_FALSE(connection_with_remote_port(6000));
2774}
2775
Peter Thatcher4eddf182015-04-30 10:55:59 -07002776// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002777TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2778 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002780
2781 PeerConnectionInterface::RTCOfferAnswerOptions options;
2782 options.use_rtp_mux = true;
2783
2784 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002786
2787 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2788 session_->GetTransportProxy("video")->impl());
2789
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002791 SessionDescriptionInterface* answer =
2792 CreateRemoteAnswer(session_->local_description());
2793 SetRemoteDescriptionWithoutError(answer);
2794
2795 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2796 session_->GetTransportProxy("video")->impl());
2797}
2798
2799// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2800TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2801 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2802 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002803
Donald Curtis0e209b02015-03-24 09:29:54 -07002804 PeerConnectionInterface::RTCOfferAnswerOptions options;
2805 options.use_rtp_mux = true;
2806
2807 SessionDescriptionInterface* offer = CreateOffer(options);
2808 SetLocalDescriptionWithoutError(offer);
2809
2810 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2811 session_->GetTransportProxy("video")->impl());
2812
2813 mediastream_signaling_.SendAudioVideoStream2();
2814
2815 // Remove BUNDLE from the answer.
2816 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2817 CreateRemoteAnswer(session_->local_description()));
2818 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2819 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2820 JsepSessionDescription* modified_answer =
2821 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2822 modified_answer->Initialize(answer_copy, "1", "1");
2823 SetRemoteDescriptionWithoutError(modified_answer); //
2824
2825 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2826 session_->GetTransportProxy("video")->impl());
2827}
2828
2829// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2830TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2831 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2832 mediastream_signaling_.SendAudioVideoStream1();
2833
2834 PeerConnectionInterface::RTCOfferAnswerOptions options;
2835 options.use_rtp_mux = true;
2836
2837 SessionDescriptionInterface* offer = CreateOffer(options);
2838 SetLocalDescriptionWithoutError(offer);
2839
2840 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2841 session_->GetTransportProxy("video")->impl());
2842
2843 mediastream_signaling_.SendAudioVideoStream2();
2844 SessionDescriptionInterface* answer =
2845 CreateRemoteAnswer(session_->local_description());
2846 SetRemoteDescriptionWithoutError(answer);
2847
2848 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2849 session_->GetTransportProxy("video")->impl());
2850}
2851
2852// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2853TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2854 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2855 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002856
Donald Curtis0e209b02015-03-24 09:29:54 -07002857 PeerConnectionInterface::RTCOfferAnswerOptions options;
2858 options.use_rtp_mux = true;
2859
2860 SessionDescriptionInterface* offer = CreateOffer(options);
2861 SetLocalDescriptionWithoutError(offer);
2862
2863 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2864 session_->GetTransportProxy("video")->impl());
2865
2866 mediastream_signaling_.SendAudioVideoStream2();
2867
2868 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002869 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002870 CreateRemoteAnswer(session_->local_description()));
2871 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2872 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2873 JsepSessionDescription* modified_answer =
2874 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2875 modified_answer->Initialize(answer_copy, "1", "1");
2876 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877
Donald Curtis0e209b02015-03-24 09:29:54 -07002878 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2879 session_->GetTransportProxy("video")->impl());
2880}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881
Peter Thatcher4eddf182015-04-30 10:55:59 -07002882// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002883TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2884 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2885 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886
Donald Curtis0e209b02015-03-24 09:29:54 -07002887 PeerConnectionInterface::RTCOfferAnswerOptions options;
2888 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889
Donald Curtis0e209b02015-03-24 09:29:54 -07002890 SessionDescriptionInterface* offer = CreateOffer(options);
2891 SetLocalDescriptionWithoutError(offer);
2892
2893 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2894 session_->GetTransportProxy("video")->impl());
2895
2896 mediastream_signaling_.SendAudioVideoStream2();
2897 SessionDescriptionInterface* answer =
2898 CreateRemoteAnswer(session_->local_description());
2899 SetRemoteDescriptionWithoutError(answer);
2900
2901 // This should lead to an audio-only call but isn't implemented
2902 // correctly yet.
2903 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2904 session_->GetTransportProxy("video")->impl());
2905}
2906
2907// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2908TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2909 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2910 mediastream_signaling_.SendAudioVideoStream1();
2911 PeerConnectionInterface::RTCOfferAnswerOptions options;
2912 options.use_rtp_mux = true;
2913
2914 SessionDescriptionInterface* offer = CreateOffer(options);
2915 SetLocalDescriptionWithoutError(offer);
2916
2917 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2918 session_->GetTransportProxy("video")->impl());
2919
2920 mediastream_signaling_.SendAudioVideoStream2();
2921
2922 // Remove BUNDLE from the answer.
2923 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2924 CreateRemoteAnswer(session_->local_description()));
2925 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2926 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2927 JsepSessionDescription* modified_answer =
2928 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2929 modified_answer->Initialize(answer_copy, "1", "1");
2930 SetRemoteDescriptionWithoutError(modified_answer); //
2931
2932 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2933 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934}
2935
Peter Thatcher4eddf182015-04-30 10:55:59 -07002936// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2937TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2938 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2939 mediastream_signaling_.SendAudioVideoStream1();
2940
2941 PeerConnectionInterface::RTCOfferAnswerOptions options;
2942 options.use_rtp_mux = true;
2943
2944 SessionDescriptionInterface* offer = CreateOffer(options);
2945 SetRemoteDescriptionWithoutError(offer);
2946
2947 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2948 session_->GetTransportProxy("video")->impl());
2949}
2950
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002951TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2952 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2953 mediastream_signaling_.SendAudioVideoStream1();
2954
2955 PeerConnectionInterface::RTCOfferAnswerOptions options;
2956 SessionDescriptionInterface* offer = CreateOffer(options);
2957 SetLocalDescriptionWithoutError(offer);
2958
2959 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2960 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2961
2962 mediastream_signaling_.SendAudioVideoStream2();
2963 SessionDescriptionInterface* answer =
2964 CreateRemoteAnswer(session_->local_description());
2965 SetRemoteDescriptionWithoutError(answer);
2966
2967 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2968 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2969}
2970
2971TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2972 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2973 mediastream_signaling_.SendAudioVideoStream1();
2974
2975 PeerConnectionInterface::RTCOfferAnswerOptions options;
2976 SessionDescriptionInterface* offer = CreateOffer(options);
2977 SetLocalDescriptionWithoutError(offer);
2978
2979 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2980 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2981
2982 mediastream_signaling_.SendAudioVideoStream2();
2983 SessionDescriptionInterface* answer =
2984 CreateRemoteAnswer(session_->local_description());
2985 SetRemoteDescriptionWithoutError(answer);
2986
2987 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2988 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2989}
2990
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002991// This test verifies that SetLocalDescription and SetRemoteDescription fails
2992// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2993TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002994 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002995 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002996
2997 PeerConnectionInterface::RTCOfferAnswerOptions options;
2998 options.use_rtp_mux = true;
2999
3000 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003001 std::string offer_str;
3002 offer->ToString(&offer_str);
3003 // Disable rtcp-mux
3004 const std::string rtcp_mux = "rtcp-mux";
3005 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003006 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003007 xrtcp_mux.c_str(), xrtcp_mux.length(),
3008 &offer_str);
3009 JsepSessionDescription *local_offer =
3010 new JsepSessionDescription(JsepSessionDescription::kOffer);
3011 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003012 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003013 JsepSessionDescription *remote_offer =
3014 new JsepSessionDescription(JsepSessionDescription::kOffer);
3015 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003016 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003017 // Trying unmodified SDP.
3018 SetLocalDescriptionWithoutError(offer);
3019}
3020
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003022 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023 mediastream_signaling_.SendAudioVideoStream1();
3024 CreateAndSetRemoteOfferAndLocalAnswer();
3025 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3026 ASSERT_TRUE(channel != NULL);
3027 ASSERT_EQ(1u, channel->recv_streams().size());
3028 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3029 double left_vol, right_vol;
3030 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3031 EXPECT_EQ(1, left_vol);
3032 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003033 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003034 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3036 EXPECT_EQ(0, left_vol);
3037 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003038 EXPECT_EQ(0, renderer->channel_id());
3039 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3041 EXPECT_EQ(1, left_vol);
3042 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003043 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044}
3045
3046TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003047 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048 mediastream_signaling_.SendAudioVideoStream1();
3049 CreateAndSetRemoteOfferAndLocalAnswer();
3050 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3051 ASSERT_TRUE(channel != NULL);
3052 ASSERT_EQ(1u, channel->send_streams().size());
3053 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3054 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3055
3056 cricket::AudioOptions options;
3057 options.echo_cancellation.Set(true);
3058
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003059 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003060 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3062 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003063 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003064 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003065
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003066 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003067 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003068 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3069 bool value;
3070 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3071 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003072 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003073 EXPECT_TRUE(renderer->sink() == NULL);
3074}
3075
3076TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003077 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003078 mediastream_signaling_.SendAudioVideoStream1();
3079 CreateAndSetRemoteOfferAndLocalAnswer();
3080 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3081 ASSERT_TRUE(channel != NULL);
3082 ASSERT_EQ(1u, channel->send_streams().size());
3083 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3084
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003085 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003086 cricket::AudioOptions options;
3087 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3088 EXPECT_TRUE(renderer->sink() != NULL);
3089
3090 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3091 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3092 // SetSink(NULL) callback afterwards.
3093 renderer.reset();
3094
3095 // This will trigger SetSink(NULL) if no OnClose() callback.
3096 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097}
3098
3099TEST_F(WebRtcSessionTest, SetVideoPlayout) {
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 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3104 ASSERT_TRUE(channel != NULL);
3105 ASSERT_LT(0u, channel->renderers().size());
3106 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3107 ASSERT_EQ(1u, channel->recv_streams().size());
3108 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3109 cricket::FakeVideoRenderer renderer;
3110 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3111 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3112 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3113 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3114}
3115
3116TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003117 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118 mediastream_signaling_.SendAudioVideoStream1();
3119 CreateAndSetRemoteOfferAndLocalAnswer();
3120 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3121 ASSERT_TRUE(channel != NULL);
3122 ASSERT_EQ(1u, channel->send_streams().size());
3123 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3124 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3125 cricket::VideoOptions* options = NULL;
3126 session_->SetVideoSend(send_ssrc, false, options);
3127 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3128 session_->SetVideoSend(send_ssrc, true, options);
3129 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3130}
3131
3132TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3133 TestCanInsertDtmf(false);
3134}
3135
3136TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3137 TestCanInsertDtmf(true);
3138}
3139
3140TEST_F(WebRtcSessionTest, InsertDtmf) {
3141 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003142 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 mediastream_signaling_.SendAudioVideoStream1();
3144 CreateAndSetRemoteOfferAndLocalAnswer();
3145 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3146 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3147
3148 // Insert DTMF
3149 const int expected_flags = DF_SEND;
3150 const int expected_duration = 90;
3151 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3152 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3153 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3154
3155 // Verify
3156 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3157 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3158 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3159 expected_duration, expected_flags));
3160 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3161 expected_duration, expected_flags));
3162 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3163 expected_duration, expected_flags));
3164}
3165
3166// This test verifies the |initiator| flag when session initiates the call.
3167TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003168 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003170 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003171 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3172 SetLocalDescriptionWithoutError(offer);
3173 EXPECT_TRUE(session_->initiator());
3174 SetRemoteDescriptionWithoutError(answer);
3175 EXPECT_TRUE(session_->initiator());
3176}
3177
3178// This test verifies the |initiator| flag when session receives the call.
3179TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003180 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181 EXPECT_FALSE(session_->initiator());
3182 SessionDescriptionInterface* offer = CreateRemoteOffer();
3183 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003184 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185
3186 EXPECT_FALSE(session_->initiator());
3187 SetLocalDescriptionWithoutError(answer);
3188 EXPECT_FALSE(session_->initiator());
3189}
3190
guoweisd12140a2015-09-10 13:32:11 -07003191// This test verifies the ice protocol type at initiator of the call
3192// if |a=ice-options:google-ice| is present in answer.
3193TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
3194 Init();
3195 mediastream_signaling_.SendAudioVideoStream1();
3196 SessionDescriptionInterface* offer = CreateOffer();
3197 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3198 CreateRemoteAnswer(offer));
3199 SetLocalDescriptionWithoutError(offer);
3200 std::string sdp;
3201 EXPECT_TRUE(answer->ToString(&sdp));
3202 // Adding ice-options to the session level.
3203 InjectAfter("t=0 0\r\n",
3204 "a=ice-options:google-ice\r\n",
3205 &sdp);
3206 SessionDescriptionInterface* answer_with_gice =
3207 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3208 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3209 // only gice to fail.
3210 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
3211}
3212
3213// This test verifies the ice protocol type at initiator of the call
3214// if ICE RFC5245 is supported in answer.
3215TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
3216 Init();
3217 mediastream_signaling_.SendAudioVideoStream1();
3218 SessionDescriptionInterface* offer = CreateOffer();
3219 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3220 SetLocalDescriptionWithoutError(offer);
3221
3222 SetRemoteDescriptionWithoutError(answer);
3223 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3224 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3225}
3226
3227// This test verifies the ice protocol type at receiver side of the call if
3228// receiver decides to use ice RFC 5245.
3229TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
3230 Init();
3231 mediastream_signaling_.SendAudioVideoStream1();
3232 SessionDescriptionInterface* offer = CreateOffer();
3233 SetRemoteDescriptionWithoutError(offer);
3234 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3235 SetLocalDescriptionWithoutError(answer);
3236 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3237 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3238}
3239
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3241TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003242 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003244 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003246 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247 CreateRemoteAnswer(session_->local_description()));
3248
3249 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3250 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003251 JsepSessionDescription* modified_answer =
3252 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253
3254 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3255 answer->session_id(),
3256 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003257 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258
wu@webrtc.org4e393072014-04-07 17:04:35 +00003259 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260 std::string sdp;
3261 EXPECT_TRUE(answer->ToString(&sdp));
3262 const std::string kAudioMid = "a=mid:audio";
3263 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003264 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 kAudioMidReplaceStr.c_str(),
3266 kAudioMidReplaceStr.length(),
3267 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003268 SessionDescriptionInterface* modified_answer1 =
3269 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003270 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271
wu@webrtc.org4e393072014-04-07 17:04:35 +00003272 // Different media types.
3273 EXPECT_TRUE(answer->ToString(&sdp));
3274 const std::string kAudioMline = "m=audio";
3275 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003276 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003277 kAudioMlineReplaceStr.c_str(),
3278 kAudioMlineReplaceStr.length(),
3279 &sdp);
3280 SessionDescriptionInterface* modified_answer2 =
3281 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3282 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3283
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284 SetRemoteDescriptionWithoutError(answer.release());
3285}
3286
3287// Verifying remote offer and local answer have matching m-lines as per
3288// RFC 3264.
3289TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003290 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 mediastream_signaling_.SendAudioVideoStream1();
3292 SessionDescriptionInterface* offer = CreateRemoteOffer();
3293 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003294 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295
3296 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3297 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003298 JsepSessionDescription* modified_answer =
3299 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300
3301 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3302 answer->session_id(),
3303 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003304 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305 SetLocalDescriptionWithoutError(answer);
3306}
3307
3308// This test verifies that WebRtcSession does not start candidate allocation
3309// before SetLocalDescription is called.
3310TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003311 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 mediastream_signaling_.SendAudioVideoStream1();
3313 SessionDescriptionInterface* offer = CreateRemoteOffer();
3314 cricket::Candidate candidate;
3315 candidate.set_component(1);
3316 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3317 candidate);
3318 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3319 cricket::Candidate candidate1;
3320 candidate1.set_component(1);
3321 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3322 candidate1);
3323 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3324 SetRemoteDescriptionWithoutError(offer);
3325 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3326 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3327
3328 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003329 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3331 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3332
wu@webrtc.org91053e72013-08-10 07:18:04 +00003333 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 SetLocalDescriptionWithoutError(answer);
3335 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3336 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3337 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3338}
3339
3340// This test verifies that crypto parameter is updated in local session
3341// description as per security policy set in MediaSessionDescriptionFactory.
3342TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003343 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003345 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346
3347 // Making sure SetLocalDescription correctly sets crypto value in
3348 // SessionDescription object after de-serialization of sdp string. The value
3349 // will be set as per MediaSessionDescriptionFactory.
3350 std::string offer_str;
3351 offer->ToString(&offer_str);
3352 SessionDescriptionInterface* jsep_offer_str =
3353 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3354 SetLocalDescriptionWithoutError(jsep_offer_str);
3355 EXPECT_TRUE(session_->voice_channel()->secure_required());
3356 EXPECT_TRUE(session_->video_channel()->secure_required());
3357}
3358
3359// This test verifies the crypto parameter when security is disabled.
3360TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003361 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003362 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003363 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003364 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365
3366 // Making sure SetLocalDescription correctly sets crypto value in
3367 // SessionDescription object after de-serialization of sdp string. The value
3368 // will be set as per MediaSessionDescriptionFactory.
3369 std::string offer_str;
3370 offer->ToString(&offer_str);
3371 SessionDescriptionInterface *jsep_offer_str =
3372 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3373 SetLocalDescriptionWithoutError(jsep_offer_str);
3374 EXPECT_FALSE(session_->voice_channel()->secure_required());
3375 EXPECT_FALSE(session_->video_channel()->secure_required());
3376}
3377
3378// This test verifies that an answer contains new ufrag and password if an offer
3379// with new ufrag and password is received.
3380TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003381 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003383 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003384 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003385 CreateRemoteOffer(options));
3386 SetRemoteDescriptionWithoutError(offer.release());
3387
3388 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003389 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003390 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 SetLocalDescriptionWithoutError(answer.release());
3392
3393 // Receive an offer with new ufrag and password.
3394 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003395 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003396 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 SetRemoteDescriptionWithoutError(updated_offer1.release());
3398
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003399 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003400 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003401
3402 CompareIceUfragAndPassword(updated_answer1->description(),
3403 session_->local_description()->description(),
3404 false);
3405
3406 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003407}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408
wu@webrtc.org91053e72013-08-10 07:18:04 +00003409// This test verifies that an answer contains old ufrag and password if an offer
3410// with old ufrag and password is received.
3411TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003412 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003413 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003414 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003415 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003416 CreateRemoteOffer(options));
3417 SetRemoteDescriptionWithoutError(offer.release());
3418
3419 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003420 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003421 CreateAnswer(NULL));
3422 SetLocalDescriptionWithoutError(answer.release());
3423
3424 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003426 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003427 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 SetRemoteDescriptionWithoutError(updated_offer2.release());
3429
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003430 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003431 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432
3433 CompareIceUfragAndPassword(updated_answer2->description(),
3434 session_->local_description()->description(),
3435 true);
3436
3437 SetLocalDescriptionWithoutError(updated_answer2.release());
3438}
3439
3440TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003441 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003443 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444 const std::string session_id_orig = offer->session_id();
3445 const std::string session_version_orig = offer->session_version();
3446 SetLocalDescriptionWithoutError(offer);
3447
3448 video_channel_ = media_engine_->GetVideoChannel(0);
3449 video_channel_->set_fail_set_send_codecs(true);
3450
3451 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003452 SessionDescriptionInterface* answer =
3453 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003454 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455}
3456
3457// Runs the loopback call test with BUNDLE and STUN disabled.
3458TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3459 // Lets try with only UDP ports.
guoweisd12140a2015-09-10 13:32:11 -07003460 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3461 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003462 cricket::PORTALLOCATOR_DISABLE_STUN |
3463 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 TestLoopbackCall();
3465}
3466
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003467TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
guoweisd12140a2015-09-10 13:32:11 -07003468 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3469 cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003470 cricket::PORTALLOCATOR_DISABLE_STUN |
3471 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3472 cricket::PORTALLOCATOR_DISABLE_RELAY);
3473
3474 // best connection is IPv6 since it has higher network preference.
3475 LoopbackNetworkConfiguration config;
3476 config.test_ipv6_network_ = true;
3477 config.best_connection_after_initial_ice_converged_ =
3478 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3479
3480 TestLoopbackCall(config);
3481}
3482
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003483// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003484TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
guoweisd12140a2015-09-10 13:32:11 -07003485 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3486 cricket::PORTALLOCATOR_DISABLE_TCP |
3487 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003488 TestLoopbackCall();
3489}
3490
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003491TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003494 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003496 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3497 std::string error_code_str = "ERROR_CONTENT";
3498 std::string error_desc = "Fake session error description.";
3499 session_->SetError(error_code, error_desc);
3500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3502 SessionDescriptionInterface* answer =
3503 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003504
3505 std::string action;
3506 std::ostringstream session_error_msg;
3507 session_error_msg << kSessionError << error_code_str << ". ";
3508 session_error_msg << kSessionErrorDesc << error_desc << ".";
3509 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3510 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511}
3512
3513TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3514 constraints_.reset(new FakeConstraints());
3515 constraints_->AddOptional(
3516 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003517 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518
3519 SetLocalDescriptionWithDataChannel();
3520 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3521}
3522
Henrik Boström87713d02015-08-25 09:53:21 +02003523TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003524 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525
3526 constraints_.reset(new FakeConstraints());
3527 constraints_->AddOptional(
3528 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003529 options_.disable_sctp_data_channels = false;
3530
Henrik Boström87713d02015-08-25 09:53:21 +02003531 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532
3533 SetLocalDescriptionWithDataChannel();
3534 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3535}
3536
Henrik Boström87713d02015-08-25 09:53:21 +02003537TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003538 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003539
Henrik Boström87713d02015-08-25 09:53:21 +02003540 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003541
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003542 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003543 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003544 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3545}
3546
Henrik Boström87713d02015-08-25 09:53:21 +02003547TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003548 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003549 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003550 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003551
3552 // Create remote offer with SCTP.
3553 cricket::MediaSessionOptions options;
3554 options.data_channel_type = cricket::DCT_SCTP;
3555 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003556 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003557 SetRemoteDescriptionWithoutError(offer);
3558
3559 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003560 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003561 EXPECT_TRUE(answer != NULL);
3562 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3563 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003564}
3565
Henrik Boström87713d02015-08-25 09:53:21 +02003566TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567 constraints_.reset(new FakeConstraints());
3568 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003569 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003570 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571
3572 SetLocalDescriptionWithDataChannel();
3573 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3574}
3575
Henrik Boström87713d02015-08-25 09:53:21 +02003576TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003577 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578
Henrik Boström87713d02015-08-25 09:53:21 +02003579 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
3581 SetLocalDescriptionWithDataChannel();
3582 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3583}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003584
Henrik Boström87713d02015-08-25 09:53:21 +02003585TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003586 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003587 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003588 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003589
3590 SetLocalDescriptionWithDataChannel();
3591 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3592}
3593
Henrik Boström87713d02015-08-25 09:53:21 +02003594TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003595 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003596 const int new_send_port = 9998;
3597 const int new_recv_port = 7775;
3598
Henrik Boström87713d02015-08-25 09:53:21 +02003599 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003600 SetFactoryDtlsSrtp();
3601
3602 // By default, don't actually add the codecs to desc_factory_; they don't
3603 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3604 // let the session description get parsed. That'll get the proper codecs
3605 // into the stream.
3606 cricket::MediaSessionOptions options;
3607 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3608 "stream1", new_send_port, options);
3609
3610 // SetRemoteDescription will take the ownership of the offer.
3611 SetRemoteDescriptionWithoutError(offer);
3612
3613 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3614 new_recv_port, CreateAnswer(NULL));
3615 ASSERT_TRUE(answer != NULL);
3616
3617 // Now set the local description, which'll take ownership of the answer.
3618 SetLocalDescriptionWithoutError(answer);
3619
3620 // TEST PLAN: Set the port number to something new, set it in the SDP,
3621 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003622 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003623 dci.reliable = true;
3624 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003625 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003626 session_->CreateDataChannel("datachannel", &dci);
3627
3628 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3629 int portnum = -1;
3630 ASSERT_TRUE(ch != NULL);
3631 ASSERT_EQ(1UL, ch->send_codecs().size());
3632 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003633 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003634 ch->send_codecs()[0].name.c_str()));
3635 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3636 &portnum));
3637 EXPECT_EQ(new_send_port, portnum);
3638
3639 ASSERT_EQ(1UL, ch->recv_codecs().size());
3640 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003641 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003642 ch->recv_codecs()[0].name.c_str()));
3643 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3644 &portnum));
3645 EXPECT_EQ(new_recv_port, portnum);
3646}
3647
Henrik Boströmd8281982015-08-27 10:12:24 +02003648TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3649 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3650 FakeDtlsIdentityStore::GenerateCertificate();
3651
3652 PeerConnectionInterface::RTCConfiguration configuration;
3653 configuration.certificates.push_back(certificate);
3654 Init(nullptr, configuration);
3655 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3656
3657 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3658}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003659
Henrik Boström87713d02015-08-25 09:53:21 +02003660// Verifies that CreateOffer succeeds when CreateOffer is called before async
3661// identity generation is finished (even if a certificate is provided this is
3662// an async op).
3663TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3664 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3665 InitWithDtls(GetParam());
3666
Henrik Boströmd8281982015-08-27 10:12:24 +02003667 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003668 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003669 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3670
wu@webrtc.org91053e72013-08-10 07:18:04 +00003671 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003672 VerifyNoCryptoParams(offer->description(), true);
3673 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003674}
3675
3676// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003677// identity generation is finished (even if a certificate is provided this is
3678// an async op).
3679TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003680 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003681 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003682 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003683
3684 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003685 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003686 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003687 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003688 ASSERT_TRUE(offer.get() != NULL);
3689 SetRemoteDescriptionWithoutError(offer.release());
3690
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003691 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003692 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003693 VerifyNoCryptoParams(answer->description(), true);
3694 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003695}
3696
3697// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003698// identity generation is finished (even if a certificate is provided this is
3699// an async op).
3700TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003701 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003702 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003703
Henrik Boströmd8281982015-08-27 10:12:24 +02003704 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003705
3706 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003707 EXPECT_TRUE(offer != NULL);
3708}
3709
3710// Verifies that CreateOffer fails when CreateOffer is called after async
3711// identity generation fails.
3712TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003713 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003714 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003715
Henrik Boströmd8281982015-08-27 10:12:24 +02003716 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003717
3718 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003719 EXPECT_TRUE(offer == NULL);
3720}
3721
3722// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3723// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003724TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003725 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003726 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003727 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003728 GetParam(), CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003729}
3730
3731// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3732// before async identity generation fails.
3733TEST_F(WebRtcSessionTest,
3734 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003735 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003736 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3737 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003738}
3739
3740// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3741// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003742TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003743 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003744 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003745 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003746 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003747}
3748
3749// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3750// before async identity generation fails.
3751TEST_F(WebRtcSessionTest,
3752 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003753 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003754 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3755 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003756}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003757
3758// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3759// offer has no SDES crypto but only DTLS fingerprint.
3760TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3761 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003762 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003763 // Create a remote offer with secured transport disabled.
3764 cricket::MediaSessionOptions options;
3765 JsepSessionDescription* offer(CreateRemoteOffer(
3766 options, cricket::SEC_DISABLED));
3767 // Adds a DTLS fingerprint to the remote offer.
3768 cricket::SessionDescription* sdp = offer->description();
3769 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3770 ASSERT_TRUE(audio != NULL);
3771 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3772 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003773 rtc::SSLFingerprint::CreateFromRfc4572(
3774 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003775 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003776 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003777}
3778
wu@webrtc.orgde305012013-10-31 15:40:38 +00003779// This test verifies DSCP is properly applied on the media channels.
3780TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3781 constraints_.reset(new FakeConstraints());
3782 constraints_->AddOptional(
3783 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003784 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003785 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003786 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003787
3788 SetLocalDescriptionWithoutError(offer);
3789
3790 video_channel_ = media_engine_->GetVideoChannel(0);
3791 voice_channel_ = media_engine_->GetVoiceChannel(0);
3792
3793 ASSERT_TRUE(video_channel_ != NULL);
3794 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003795 const cricket::AudioOptions& audio_options = voice_channel_->options();
3796 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003797 EXPECT_TRUE(audio_options.dscp.IsSet());
3798 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3799 EXPECT_TRUE(video_options.dscp.IsSet());
3800 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3801}
3802
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003803TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3804 constraints_.reset(new FakeConstraints());
3805 constraints_->AddOptional(
3806 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3807 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003808 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003809 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003810 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003811
3812 SetLocalDescriptionWithoutError(offer);
3813
3814 video_channel_ = media_engine_->GetVideoChannel(0);
3815
3816 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003817 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003818 EXPECT_TRUE(
3819 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3820}
3821
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003822TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3823 // Number of unsignalled receiving streams should be between 0 and
3824 // kMaxUnsignalledRecvStreams.
3825 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3826 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3827 kMaxUnsignalledRecvStreams);
3828 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3829}
3830
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003831TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3832 constraints_.reset(new FakeConstraints());
3833 constraints_->AddOptional(
3834 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3835 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003836 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003837 mediastream_signaling_.SendAudioVideoStream1();
3838 SessionDescriptionInterface* offer = CreateOffer();
3839
3840 SetLocalDescriptionWithoutError(offer);
3841
3842 voice_channel_ = media_engine_->GetVoiceChannel(0);
3843
3844 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003845 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003846 EXPECT_TRUE(
3847 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3848}
3849
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003850// Tests that we can renegotiate new media content with ICE candidates in the
3851// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003852TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003853 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003854 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003855 SetFactoryDtlsSrtp();
3856
3857 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003858 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003859 SetLocalDescriptionWithoutError(offer);
3860
3861 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3862 SetRemoteDescriptionWithoutError(answer);
3863
3864 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003865 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003866 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3867
3868 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003869 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003870 candidate1.set_component(1);
3871 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3872 candidate1);
3873 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3874 SetRemoteDescriptionWithoutError(offer);
3875
3876 answer = CreateAnswer(NULL);
3877 SetLocalDescriptionWithoutError(answer);
3878}
3879
3880// Tests that we can renegotiate new media content with ICE candidates separated
3881// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003882TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003883 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003884 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003885 SetFactoryDtlsSrtp();
3886
3887 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003888 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003889 SetLocalDescriptionWithoutError(offer);
3890
3891 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3892 SetRemoteDescriptionWithoutError(answer);
3893
3894 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003895 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003896 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3897 SetRemoteDescriptionWithoutError(offer);
3898
3899 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003900 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003901 candidate1.set_component(1);
3902 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3903 candidate1);
3904 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3905
3906 answer = CreateAnswer(NULL);
3907 SetLocalDescriptionWithoutError(answer);
3908}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003909// Tests that RTX codec is removed from the answer when it isn't supported
3910// by local side.
3911TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3912 Init();
3913 mediastream_signaling_.SendAudioVideoStream1();
3914 std::string offer_sdp(kSdpWithRtx);
3915
3916 SessionDescriptionInterface* offer =
3917 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3918 EXPECT_TRUE(offer->ToString(&offer_sdp));
3919
3920 // Offer SDP contains the RTX codec.
3921 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3922 SetRemoteDescriptionWithoutError(offer);
3923
3924 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3925 std::string answer_sdp;
3926 answer->ToString(&answer_sdp);
3927 // Answer SDP removes the unsupported RTX codec.
3928 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3929 SetLocalDescriptionWithoutError(answer);
3930}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003931
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003932// This verifies that the voice channel after bundle has both options from video
3933// and voice channels.
3934TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3935 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3936 mediastream_signaling_.SendAudioVideoStream1();
3937
3938 PeerConnectionInterface::RTCOfferAnswerOptions options;
3939 options.use_rtp_mux = true;
3940
3941 SessionDescriptionInterface* offer = CreateOffer(options);
3942 SetLocalDescriptionWithoutError(offer);
3943
3944 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3945 rtc::Socket::Option::OPT_SNDBUF, 4000);
3946
3947 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3948 rtc::Socket::Option::OPT_RCVBUF, 8000);
3949
3950 int option_val;
3951 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3952 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3953 EXPECT_EQ(4000, option_val);
3954 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3955 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3956
3957 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3958 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3959 EXPECT_EQ(8000, option_val);
3960 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3961 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3962
3963 EXPECT_NE(session_->voice_channel()->transport_channel(),
3964 session_->video_channel()->transport_channel());
3965
3966 mediastream_signaling_.SendAudioVideoStream2();
3967 SessionDescriptionInterface* answer =
3968 CreateRemoteAnswer(session_->local_description());
3969 SetRemoteDescriptionWithoutError(answer);
3970
3971 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3972 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3973 EXPECT_EQ(4000, option_val);
3974
3975 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3976 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3977 EXPECT_EQ(8000, option_val);
3978}
3979
tommi0f620f42015-07-09 03:25:02 -07003980// Test creating a session, request multiple offers, destroy the session
3981// and make sure we got success/failure callbacks for all of the requests.
3982// Background: crbug.com/507307
3983TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3984 Init();
3985
3986 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3987 PeerConnectionInterface::RTCOfferAnswerOptions options;
3988 options.offer_to_receive_audio =
3989 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3990
3991 for (auto& o : observers) {
3992 o = new WebRtcSessionCreateSDPObserverForTest();
3993 session_->CreateOffer(o, options);
3994 }
3995
3996 session_.reset();
3997
tommi0f620f42015-07-09 03:25:02 -07003998 for (auto& o : observers) {
3999 // We expect to have received a notification now even if the session was
4000 // terminated. The offer creation may or may not have succeeded, but we
4001 // must have received a notification which, so the only invalid state
4002 // is kInit.
4003 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4004 }
4005}
4006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004007// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4008// currently fails because upon disconnection and reconnection OnIceComplete is
4009// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004010
4011INSTANTIATE_TEST_CASE_P(
4012 WebRtcSessionTests, WebRtcSessionTest,
4013 testing::Values(ALREADY_GENERATED, DTLS_IDENTITY_STORE));