blob: 250e4153d640e00189941b9070faf76cf960b51f [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
kwiberg0eb15ed2015-12-17 03:04:15 -080028#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070029#include <vector>
30
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000031#include "talk/session/media/channelmanager.h"
32#include "talk/session/media/mediasession.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010033#include "webrtc/api/audiotrack.h"
34#include "webrtc/api/fakemediacontroller.h"
35#include "webrtc/api/fakemetricsobserver.h"
36#include "webrtc/api/jsepicecandidate.h"
37#include "webrtc/api/jsepsessiondescription.h"
38#include "webrtc/api/peerconnection.h"
39#include "webrtc/api/sctputils.h"
40#include "webrtc/api/streamcollection.h"
41#include "webrtc/api/streamcollection.h"
42#include "webrtc/api/test/fakeconstraints.h"
43#include "webrtc/api/test/fakedtlsidentitystore.h"
44#include "webrtc/api/videotrack.h"
45#include "webrtc/api/webrtcsession.h"
46#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047#include "webrtc/base/fakenetwork.h"
48#include "webrtc/base/firewallsocketserver.h"
49#include "webrtc/base/gunit.h"
50#include "webrtc/base/logging.h"
51#include "webrtc/base/network.h"
52#include "webrtc/base/physicalsocketserver.h"
53#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020054#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055#include "webrtc/base/sslstreamadapter.h"
56#include "webrtc/base/stringutils.h"
57#include "webrtc/base/thread.h"
58#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080059#include "webrtc/media/base/fakemediaengine.h"
60#include "webrtc/media/base/fakevideorenderer.h"
61#include "webrtc/media/base/mediachannel.h"
62#include "webrtc/media/webrtc/fakewebrtccall.h"
63#include "webrtc/p2p/base/stunserver.h"
64#include "webrtc/p2p/base/teststunserver.h"
65#include "webrtc/p2p/base/testturnserver.h"
66#include "webrtc/p2p/base/transportchannel.h"
67#include "webrtc/p2p/client/basicportallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
69#define MAYBE_SKIP_TEST(feature) \
70 if (!(feature())) { \
71 LOG(LS_INFO) << "Feature disabled... skipping"; \
72 return; \
73 }
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::FakeVoiceMediaChannel;
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;
deadbeefab9b2d12015-10-14 11:33:11 -070083using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020084using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070086using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070088using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::JsepIceCandidate;
90using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000091using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::PeerConnectionInterface;
93using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070094using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000096using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000097using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kCreateChannelFailed;
99using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000103using webrtc::kSdpWithoutDtlsFingerprint;
104using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000106using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000107using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000109typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
110
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111static const int kClientAddrPort = 0;
112static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000113static const char kClientIPv6AddrHost1[] =
114 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000115static const char kClientAddrHost2[] = "22.22.22.22";
116static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000117static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
118static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000119static const char kTurnUsername[] = "test";
120static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122static const char kSessionVersion[] = "1";
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Media index of candidates belonging to the first media content.
125static const int kMediaContentIndex0 = 0;
126static const char kMediaContentName0[] = "audio";
127
128// Media index of candidates belonging to the second media content.
129static const int kMediaContentIndex1 = 1;
130static const char kMediaContentName1[] = "video";
131
132static const int kIceCandidatesTimeout = 10000;
133
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000134static const char kFakeDtlsFingerprint[] =
135 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
136 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
137
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000138static const char kTooLongIceUfragPwd[] =
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
143
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000144static const char kSdpWithRtx[] =
145 "v=0\r\n"
146 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
149 "a=msid-semantic: WMS stream1\r\n"
150 "m=video 9 RTP/SAVPF 0 96\r\n"
151 "c=IN IP4 0.0.0.0\r\n"
152 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
153 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
154 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
155 "a=mid:video\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
159 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
160 "a=rtpmap:0 fake_video_codec/90000\r\n"
161 "a=rtpmap:96 rtx/90000\r\n"
162 "a=fmtp:96 apt=0\r\n";
163
deadbeefab9b2d12015-10-14 11:33:11 -0700164static const char kStream1[] = "stream1";
165static const char kVideoTrack1[] = "video1";
166static const char kAudioTrack1[] = "audio1";
167
168static const char kStream2[] = "stream2";
169static const char kVideoTrack2[] = "video2";
170static const char kAudioTrack2[] = "audio2";
171
Henrik Boström87713d02015-08-25 09:53:21 +0200172enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174class MockIceObserver : public webrtc::IceObserver {
175 public:
176 MockIceObserver()
177 : oncandidatesready_(false),
178 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
179 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
180 }
181
perkjdfb769d2016-02-09 03:09:43 -0800182 void OnIceConnectionChange(
183 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 ice_connection_state_ = new_state;
185 }
perkjdfb769d2016-02-09 03:09:43 -0800186 void OnIceGatheringChange(
187 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // We can never transition back to "new".
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
190 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800191 oncandidatesready_ =
192 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 }
194
195 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800196 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000197 switch (candidate->sdp_mline_index()) {
198 case kMediaContentIndex0:
199 mline_0_candidates_.push_back(candidate->candidate());
200 break;
201 case kMediaContentIndex1:
202 mline_1_candidates_.push_back(candidate->candidate());
203 break;
204 default:
205 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000207
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 // The ICE gathering state should always be Gathering when a candidate is
209 // received (or possibly Completed in the case of the final candidate).
210 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
211 }
212
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 bool oncandidatesready_;
214 std::vector<cricket::Candidate> mline_0_candidates_;
215 std::vector<cricket::Candidate> mline_1_candidates_;
216 PeerConnectionInterface::IceConnectionState ice_connection_state_;
217 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
218};
219
220class WebRtcSessionForTest : public webrtc::WebRtcSession {
221 public:
stefanc1aeaf02015-10-15 07:26:07 -0700222 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000223 rtc::Thread* signaling_thread,
224 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700226 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700227 : WebRtcSession(media_controller,
228 signaling_thread,
229 worker_thread,
230 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 RegisterIceObserver(ice_observer);
232 }
233 virtual ~WebRtcSessionForTest() {}
234
deadbeefcbecd352015-09-23 11:50:27 -0700235 // Note that these methods are only safe to use if the signaling thread
236 // is the same as the worker thread
237 cricket::TransportChannel* voice_rtp_transport_channel() {
238 return rtp_transport_channel(voice_channel());
239 }
240
241 cricket::TransportChannel* voice_rtcp_transport_channel() {
242 return rtcp_transport_channel(voice_channel());
243 }
244
245 cricket::TransportChannel* video_rtp_transport_channel() {
246 return rtp_transport_channel(video_channel());
247 }
248
249 cricket::TransportChannel* video_rtcp_transport_channel() {
250 return rtcp_transport_channel(video_channel());
251 }
252
253 cricket::TransportChannel* data_rtp_transport_channel() {
254 return rtp_transport_channel(data_channel());
255 }
256
257 cricket::TransportChannel* data_rtcp_transport_channel() {
258 return rtcp_transport_channel(data_channel());
259 }
260
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 using webrtc::WebRtcSession::SetAudioPlayout;
262 using webrtc::WebRtcSession::SetAudioSend;
263 using webrtc::WebRtcSession::SetCaptureDevice;
264 using webrtc::WebRtcSession::SetVideoPlayout;
265 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700266
267 private:
268 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
269 if (!ch) {
270 return nullptr;
271 }
272 return ch->transport_channel();
273 }
274
275 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
276 if (!ch) {
277 return nullptr;
278 }
279 return ch->rtcp_transport_channel();
280 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281};
282
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000284 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000286 enum State {
287 kInit,
288 kFailed,
289 kSucceeded,
290 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000291 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000292
293 // CreateSessionDescriptionObserver implementation.
294 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000295 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 state_ = kSucceeded;
297 }
298 virtual void OnFailure(const std::string& error) {
299 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000302 SessionDescriptionInterface* description() { return description_.get(); }
303
304 SessionDescriptionInterface* ReleaseDescription() {
305 return description_.release();
306 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307
wu@webrtc.org91053e72013-08-10 07:18:04 +0000308 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309
wu@webrtc.org91053e72013-08-10 07:18:04 +0000310 protected:
311 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312
313 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000314 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000315 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316};
317
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318class FakeAudioRenderer : public cricket::AudioRenderer {
319 public:
solenberg98c68862015-10-09 03:27:14 -0700320 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000321 virtual ~FakeAudioRenderer() {
322 if (sink_)
323 sink_->OnClose();
324 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000325
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000326 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000327
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000328 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000329 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000330 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000331};
332
Henrik Boström87713d02015-08-25 09:53:21 +0200333class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700334 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
335 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 protected:
337 // TODO Investigate why ChannelManager crashes, if it's created
338 // after stun_server.
339 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700340 : media_engine_(new cricket::FakeMediaEngine()),
341 data_engine_(new cricket::FakeDataEngine()),
342 channel_manager_(
343 new cricket::ChannelManager(media_engine_,
344 data_engine_,
345 new cricket::CaptureManager(),
346 rtc::Thread::Current())),
347 fake_call_(webrtc::Call::Config()),
348 media_controller_(
349 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
350 channel_manager_.get())),
351 tdesc_factory_(new cricket::TransportDescriptionFactory()),
352 desc_factory_(
353 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
354 tdesc_factory_.get())),
355 pss_(new rtc::PhysicalSocketServer),
356 vss_(new rtc::VirtualSocketServer(pss_.get())),
357 fss_(new rtc::FirewallSocketServer(vss_.get())),
358 ss_scope_(fss_.get()),
359 stun_socket_addr_(
360 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
361 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
362 stun_socket_addr_)),
363 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
364 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000365 cricket::ServerAddresses stun_servers;
366 stun_servers.insert(stun_socket_addr_);
367 allocator_.reset(new cricket::BasicPortAllocator(
368 &network_manager_,
369 stun_servers,
370 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000371 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700372 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 EXPECT_TRUE(channel_manager_->Init());
374 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000375 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 }
377
378 void AddInterface(const SocketAddress& addr) {
379 network_manager_.AddInterface(addr);
380 }
381
Henrik Boström87713d02015-08-25 09:53:21 +0200382 // If |dtls_identity_store| != null or |rtc_configuration| contains
383 // |certificates| then DTLS will be enabled unless explicitly disabled by
384 // |rtc_configuration| options. When DTLS is enabled a certificate will be
385 // used if provided, otherwise one will be generated using the
386 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000387 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200388 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200389 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 ASSERT_TRUE(session_.get() == NULL);
391 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700392 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700393 allocator_.get(), &observer_));
394 session_->SignalDataChannelOpenMessage.connect(
395 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800396 session_->GetOnDestroyedSignal()->connect(
397 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398
399 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
400 observer_.ice_connection_state_);
401 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
402 observer_.ice_gathering_state_);
403
deadbeefcbecd352015-09-23 11:50:27 -0700404 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800405 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700406 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700407 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
409
deadbeefab9b2d12015-10-14 11:33:11 -0700410 void OnDataChannelOpenMessage(const std::string& label,
411 const InternalDataChannelInit& config) {
412 last_data_channel_label_ = label;
413 last_data_channel_config_ = config;
414 }
415
deadbeef057ecf02016-01-20 14:30:43 -0800416 void OnSessionDestroyed() { session_destroyed_ = true; }
417
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200419 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200420 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000421 }
422
423 void InitWithIceTransport(
424 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200425 PeerConnectionInterface::RTCConfiguration configuration;
426 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200427 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000428 }
429
430 void InitWithBundlePolicy(
431 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200432 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200433 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200434 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700435 }
436
437 void InitWithRtcpMuxPolicy(
438 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
439 PeerConnectionInterface::RTCConfiguration configuration;
440 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200441 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000442 }
443
Henrik Boström87713d02015-08-25 09:53:21 +0200444 // Successfully init with DTLS; with a certificate generated and supplied or
445 // with a store that generates it for us.
446 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
447 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
448 PeerConnectionInterface::RTCConfiguration configuration;
449 if (cert_gen_method == ALREADY_GENERATED) {
450 configuration.certificates.push_back(
451 FakeDtlsIdentityStore::GenerateCertificate());
452 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
453 dtls_identity_store.reset(new FakeDtlsIdentityStore());
454 dtls_identity_store->set_should_fail(false);
455 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700456 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200457 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800458 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200459 }
460
461 // Init with DTLS with a store that will fail to generate a certificate.
462 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200463 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
464 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200465 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200466 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800467 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000468 }
469
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 void InitWithDtmfCodec() {
471 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000472 const cricket::AudioCodec kTelephoneEventCodec(
473 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 std::vector<cricket::AudioCodec> codecs;
475 codecs.push_back(kTelephoneEventCodec);
476 media_engine_->SetAudioCodecs(codecs);
477 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000478 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 }
480
deadbeefab9b2d12015-10-14 11:33:11 -0700481 void SendAudioVideoStream1() {
482 send_stream_1_ = true;
483 send_stream_2_ = false;
484 send_audio_ = true;
485 send_video_ = true;
486 }
487
488 void SendAudioVideoStream2() {
489 send_stream_1_ = false;
490 send_stream_2_ = true;
491 send_audio_ = true;
492 send_video_ = true;
493 }
494
495 void SendAudioVideoStream1And2() {
496 send_stream_1_ = true;
497 send_stream_2_ = true;
498 send_audio_ = true;
499 send_video_ = true;
500 }
501
502 void SendNothing() {
503 send_stream_1_ = false;
504 send_stream_2_ = false;
505 send_audio_ = false;
506 send_video_ = false;
507 }
508
509 void SendAudioOnlyStream2() {
510 send_stream_1_ = false;
511 send_stream_2_ = true;
512 send_audio_ = true;
513 send_video_ = false;
514 }
515
516 void SendVideoOnlyStream2() {
517 send_stream_1_ = false;
518 send_stream_2_ = true;
519 send_audio_ = false;
520 send_video_ = true;
521 }
522
523 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
524 if (send_stream_1_ && send_audio_) {
525 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
526 kStream1);
527 }
528 if (send_stream_1_ && send_video_) {
529 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
530 kStream1);
531 }
532 if (send_stream_2_ && send_audio_) {
533 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
534 kStream2);
535 }
536 if (send_stream_2_ && send_video_) {
537 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
538 kStream2);
539 }
540 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
541 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
542 data_channel_->label(),
543 data_channel_->label());
544 }
545 }
546
547 void GetOptionsForOffer(
548 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
549 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700550 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
551
deadbeefc80741f2015-10-22 13:14:45 -0700552 AddStreamsToOptions(session_options);
553 if (rtc_options.offer_to_receive_audio ==
554 RTCOfferAnswerOptions::kUndefined) {
555 session_options->recv_audio =
556 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
557 }
558 if (rtc_options.offer_to_receive_video ==
559 RTCOfferAnswerOptions::kUndefined) {
560 session_options->recv_video =
561 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
562 }
563 session_options->bundle_enabled =
564 session_options->bundle_enabled &&
565 (session_options->has_audio() || session_options->has_video() ||
566 session_options->has_data());
567
deadbeefab9b2d12015-10-14 11:33:11 -0700568 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
569 session_options->data_channel_type = cricket::DCT_SCTP;
570 }
571 }
572
573 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
574 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700575 session_options->recv_audio = false;
576 session_options->recv_video = false;
577 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
578
deadbeefc80741f2015-10-22 13:14:45 -0700579 AddStreamsToOptions(session_options);
580 session_options->bundle_enabled =
581 session_options->bundle_enabled &&
582 (session_options->has_audio() || session_options->has_video() ||
583 session_options->has_data());
584
deadbeefab9b2d12015-10-14 11:33:11 -0700585 if (session_->data_channel_type() == cricket::DCT_SCTP) {
586 session_options->data_channel_type = cricket::DCT_SCTP;
587 }
588 }
589
590 // Creates a local offer and applies it. Starts ICE.
591 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 // to decide which streams to create.
593 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000594 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 SetLocalDescriptionWithoutError(offer);
596 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
597 observer_.ice_gathering_state_,
598 kIceCandidatesTimeout);
599 }
600
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000601 SessionDescriptionInterface* CreateOffer() {
602 PeerConnectionInterface::RTCOfferAnswerOptions options;
603 options.offer_to_receive_audio =
604 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
605
606 return CreateOffer(options);
607 }
608
wu@webrtc.org91053e72013-08-10 07:18:04 +0000609 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000610 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000611 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700613 cricket::MediaSessionOptions session_options;
614 GetOptionsForOffer(options, &session_options);
615 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 EXPECT_TRUE_WAIT(
617 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000618 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000619 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000620 }
621
622 SessionDescriptionInterface* CreateAnswer(
623 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000624 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000625 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700626 cricket::MediaSessionOptions session_options;
627 GetOptionsForAnswer(constraints, &session_options);
628 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000629 EXPECT_TRUE_WAIT(
630 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000631 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000632 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000633 }
634
wu@webrtc.org364f2042013-11-20 21:49:41 +0000635 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 return (session_->voice_channel() != NULL &&
637 session_->video_channel() != NULL);
638 }
639
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
641 ASSERT_TRUE(session_.get() != NULL);
642 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
643 ASSERT_TRUE(content != NULL);
644 const cricket::AudioContentDescription* audio_content =
645 static_cast<const cricket::AudioContentDescription*>(
646 content->description);
647 ASSERT_TRUE(audio_content != NULL);
648 ASSERT_EQ(1U, audio_content->cryptos().size());
649 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
650 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
651 audio_content->cryptos()[0].cipher_suite);
652 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
653 audio_content->protocol());
654
655 content = cricket::GetFirstVideoContent(sdp);
656 ASSERT_TRUE(content != NULL);
657 const cricket::VideoContentDescription* video_content =
658 static_cast<const cricket::VideoContentDescription*>(
659 content->description);
660 ASSERT_TRUE(video_content != NULL);
661 ASSERT_EQ(1U, video_content->cryptos().size());
662 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
663 video_content->cryptos()[0].cipher_suite);
664 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
665 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
666 video_content->protocol());
667 }
668
669 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
670 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
671 ASSERT_TRUE(content != NULL);
672 const cricket::AudioContentDescription* audio_content =
673 static_cast<const cricket::AudioContentDescription*>(
674 content->description);
675 ASSERT_TRUE(audio_content != NULL);
676 ASSERT_EQ(0U, audio_content->cryptos().size());
677
678 content = cricket::GetFirstVideoContent(sdp);
679 ASSERT_TRUE(content != NULL);
680 const cricket::VideoContentDescription* video_content =
681 static_cast<const cricket::VideoContentDescription*>(
682 content->description);
683 ASSERT_TRUE(video_content != NULL);
684 ASSERT_EQ(0U, video_content->cryptos().size());
685
686 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700687 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700689 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 video_content->protocol());
691 } else {
692 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
693 audio_content->protocol());
694 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
695 video_content->protocol());
696 }
697 }
698
699 // Set the internal fake description factories to do DTLS-SRTP.
700 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000701 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000703 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200704 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800705 tdesc_factory_->set_certificate(
706 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
707 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
709 }
710
711 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
712 bool expected) {
713 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
714 ASSERT_TRUE(audio != NULL);
715 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 const TransportInfo* video = sdp->GetTransportInfoByName("video");
717 ASSERT_TRUE(video != NULL);
718 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 }
720
721 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000722 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000724 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000725 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000727 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000729 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
730 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000731 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 // Answer should be NULL as no crypto params in offer.
733 ASSERT_TRUE(answer == NULL);
734 }
735
736 void VerifyAnswerFromCryptoOffer() {
737 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000738 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 options.bundle_enabled = true;
740 scoped_ptr<JsepSessionDescription> offer(
741 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
742 ASSERT_TRUE(offer.get() != NULL);
743 VerifyCryptoParams(offer->description());
744 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000745 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 ASSERT_TRUE(answer.get() != NULL);
747 VerifyCryptoParams(answer->description());
748 }
749
750 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
751 const cricket::SessionDescription* desc2,
752 bool expect_equal) {
753 if (desc1->contents().size() != desc2->contents().size()) {
754 EXPECT_FALSE(expect_equal);
755 return;
756 }
757
758 const cricket::ContentInfos& contents = desc1->contents();
759 cricket::ContentInfos::const_iterator it = contents.begin();
760
761 for (; it != contents.end(); ++it) {
762 const cricket::TransportDescription* transport_desc1 =
763 desc1->GetTransportDescriptionByName(it->name);
764 const cricket::TransportDescription* transport_desc2 =
765 desc2->GetTransportDescriptionByName(it->name);
766 if (!transport_desc1 || !transport_desc2) {
767 EXPECT_FALSE(expect_equal);
768 return;
769 }
770 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
771 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
772 EXPECT_FALSE(expect_equal);
773 return;
774 }
775 }
776 EXPECT_TRUE(expect_equal);
777 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000778
779 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
780 std::string *sdp) {
781 const cricket::SessionDescription* desc = current_desc->description();
782 EXPECT_TRUE(current_desc->ToString(sdp));
783
784 const cricket::ContentInfos& contents = desc->contents();
785 cricket::ContentInfos::const_iterator it = contents.begin();
786 // Replace ufrag and pwd lines with empty strings.
787 for (; it != contents.end(); ++it) {
788 const cricket::TransportDescription* transport_desc =
789 desc->GetTransportDescriptionByName(it->name);
790 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
791 + "\r\n";
792 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
793 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000794 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000795 "", 0,
796 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000797 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000798 "", 0,
799 sdp);
800 }
801 }
802
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000803 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
804 const std::string& modified_ice_ufrag,
805 const std::string& modified_ice_pwd,
806 std::string* sdp) {
807 const cricket::SessionDescription* desc = current_desc->description();
808 EXPECT_TRUE(current_desc->ToString(sdp));
809
810 const cricket::ContentInfos& contents = desc->contents();
811 cricket::ContentInfos::const_iterator it = contents.begin();
812 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
813 // |modified_ice_pwd| strings.
814 for (; it != contents.end(); ++it) {
815 const cricket::TransportDescription* transport_desc =
816 desc->GetTransportDescriptionByName(it->name);
817 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
818 + "\r\n";
819 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
820 + "\r\n";
821 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
822 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000823 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000824 mod_ufrag.c_str(), mod_ufrag.length(),
825 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000826 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000827 mod_pwd.c_str(), mod_pwd.length(),
828 sdp);
829 }
830 }
831
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 // Creates a remote offer and and applies it as a remote description,
833 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700834 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 // to decide which local and remote streams to create.
836 void CreateAndSetRemoteOfferAndLocalAnswer() {
837 SessionDescriptionInterface* offer = CreateRemoteOffer();
838 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000839 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 SetLocalDescriptionWithoutError(answer);
841 }
842 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
843 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700844 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 }
846 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700847 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 SetLocalDescriptionWithoutError(desc);
849 EXPECT_EQ(expected_state, session_->state());
850 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000851 void SetLocalDescriptionExpectError(const std::string& action,
852 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 SessionDescriptionInterface* desc) {
854 std::string error;
855 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000856 std::string sdp_type = "local ";
857 sdp_type.append(action);
858 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 EXPECT_NE(std::string::npos, error.find(expected_error));
860 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000861 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
862 SessionDescriptionInterface* desc) {
863 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
864 expected_error, desc);
865 }
866 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
867 SessionDescriptionInterface* desc) {
868 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
869 expected_error, desc);
870 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
872 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
873 }
874 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700875 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 SetRemoteDescriptionWithoutError(desc);
877 EXPECT_EQ(expected_state, session_->state());
878 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000879 void SetRemoteDescriptionExpectError(const std::string& action,
880 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 SessionDescriptionInterface* desc) {
882 std::string error;
883 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000884 std::string sdp_type = "remote ";
885 sdp_type.append(action);
886 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 EXPECT_NE(std::string::npos, error.find(expected_error));
888 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000889 void SetRemoteDescriptionOfferExpectError(
890 const std::string& expected_error, SessionDescriptionInterface* desc) {
891 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
892 expected_error, desc);
893 }
894 void SetRemoteDescriptionPranswerExpectError(
895 const std::string& expected_error, SessionDescriptionInterface* desc) {
896 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
897 expected_error, desc);
898 }
899 void SetRemoteDescriptionAnswerExpectError(
900 const std::string& expected_error, SessionDescriptionInterface* desc) {
901 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
902 expected_error, desc);
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
905 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
906 SessionDescriptionInterface** nocrypto_answer) {
907 // Create a SDP without Crypto.
908 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000909 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 options.bundle_enabled = true;
911 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
912 ASSERT_TRUE(*offer != NULL);
913 VerifyCryptoParams((*offer)->description());
914
915 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
916 cricket::SEC_DISABLED);
917 EXPECT_TRUE(*nocrypto_answer != NULL);
918 }
919
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000920 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
921 SessionDescriptionInterface** nodtls_answer) {
922 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000923 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000924 options.bundle_enabled = true;
925
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000926 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000927 CreateRemoteOffer(options, cricket::SEC_ENABLED));
928
929 *nodtls_answer =
930 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
931 EXPECT_TRUE(*nodtls_answer != NULL);
932 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
933 VerifyCryptoParams((*nodtls_answer)->description());
934
935 SetFactoryDtlsSrtp();
936 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
937 ASSERT_TRUE(*offer != NULL);
938 VerifyFingerprintStatus((*offer)->description(), true);
939 VerifyCryptoParams((*offer)->description());
940 }
941
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 JsepSessionDescription* CreateRemoteOfferWithVersion(
943 cricket::MediaSessionOptions options,
944 cricket::SecurePolicy secure_policy,
945 const std::string& session_version,
946 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000947 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 const cricket::SessionDescription* cricket_desc = NULL;
949 if (current_desc) {
950 cricket_desc = current_desc->description();
951 session_id = current_desc->session_id();
952 }
953
954 desc_factory_->set_secure(secure_policy);
955 JsepSessionDescription* offer(
956 new JsepSessionDescription(JsepSessionDescription::kOffer));
957 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
958 session_id, session_version)) {
959 delete offer;
960 offer = NULL;
961 }
962 return offer;
963 }
964 JsepSessionDescription* CreateRemoteOffer(
965 cricket::MediaSessionOptions options) {
966 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
967 kSessionVersion, NULL);
968 }
969 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000970 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
971 return CreateRemoteOfferWithVersion(
972 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 }
974 JsepSessionDescription* CreateRemoteOffer(
975 cricket::MediaSessionOptions options,
976 const SessionDescriptionInterface* current_desc) {
977 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
978 kSessionVersion, current_desc);
979 }
980
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000981 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
982 const char* sctp_stream_name, int new_port,
983 cricket::MediaSessionOptions options) {
984 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000985 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
986 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000987 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
988 }
989
990 // Takes ownership of offer_basis (and deletes it).
991 JsepSessionDescription* ChangeSDPSctpPort(
992 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
993 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
994 // SessionDescription from the mutated string.
995 const char* default_port_str = "5000";
996 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000997 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000998 std::string offer_str;
999 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001000 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001001 new_port_str, strlen(new_port_str),
1002 &offer_str);
1003 JsepSessionDescription* offer = new JsepSessionDescription(
1004 offer_basis->type());
1005 delete offer_basis;
1006 offer->Initialize(offer_str, NULL);
1007 return offer;
1008 }
1009
deadbeefab9b2d12015-10-14 11:33:11 -07001010 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 // before this function to decide which streams to create.
1012 JsepSessionDescription* CreateRemoteOffer() {
1013 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001014 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 return CreateRemoteOffer(options, session_->remote_description());
1016 }
1017
1018 JsepSessionDescription* CreateRemoteAnswer(
1019 const SessionDescriptionInterface* offer,
1020 cricket::MediaSessionOptions options,
1021 cricket::SecurePolicy policy) {
1022 desc_factory_->set_secure(policy);
1023 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001024 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 JsepSessionDescription* answer(
1026 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1027 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1028 options, NULL),
1029 session_id, kSessionVersion)) {
1030 delete answer;
1031 answer = NULL;
1032 }
1033 return answer;
1034 }
1035
1036 JsepSessionDescription* CreateRemoteAnswer(
1037 const SessionDescriptionInterface* offer,
1038 cricket::MediaSessionOptions options) {
1039 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1040 }
1041
deadbeefab9b2d12015-10-14 11:33:11 -07001042 // Creates an answer session description.
1043 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 // to decide which streams to create.
1045 JsepSessionDescription* CreateRemoteAnswer(
1046 const SessionDescriptionInterface* offer) {
1047 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001048 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1050 }
1051
1052 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001053 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001054 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001055 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001056
1057 PeerConnectionInterface::RTCOfferAnswerOptions options;
1058 options.use_rtp_mux = bundle;
1059
1060 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1062 // and answer.
1063 SetLocalDescriptionWithoutError(offer);
1064
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001065 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001066 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 std::string sdp;
1068 EXPECT_TRUE(answer->ToString(&sdp));
1069
1070 size_t expected_candidate_num = 2;
1071 if (!rtcp_mux) {
1072 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1073 // for rtp and rtcp.
1074 expected_candidate_num = 4;
1075 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 const std::string kRtcpMux = "a=rtcp-mux";
1077 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001078 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 kXRtcpMux.c_str(), kXRtcpMux.length(),
1080 &sdp);
1081 }
1082
1083 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1084 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085
1086 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001087 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1089 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001090 if (bundle) {
1091 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1092 } else {
1093 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 }
1095 }
1096 // Tests that we can only send DTMF when the dtmf codec is supported.
1097 void TestCanInsertDtmf(bool can) {
1098 if (can) {
1099 InitWithDtmfCodec();
1100 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001101 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 }
deadbeefab9b2d12015-10-14 11:33:11 -07001103 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 CreateAndSetRemoteOfferAndLocalAnswer();
1105 EXPECT_FALSE(session_->CanInsertDtmf(""));
1106 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1107 }
1108
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001109 // Helper class to configure loopback network and verify Best
1110 // Connection using right IP protocol for TestLoopbackCall
1111 // method. LoopbackNetworkManager applies firewall rules to block
1112 // all ping traffic once ICE completed, and remove them to observe
1113 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1114 // verifies the best connection is using the right IP protocol after
1115 // initial ICE convergences.
1116
1117 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001118 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001119 LoopbackNetworkConfiguration()
1120 : test_ipv6_network_(false),
1121 test_extra_ipv4_network_(false),
1122 best_connection_after_initial_ice_converged_(1, 0) {}
1123
1124 // Used to track the expected best connection count in each IP protocol.
1125 struct ExpectedBestConnection {
1126 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1127 : ipv4_count_(ipv4_count),
1128 ipv6_count_(ipv6_count) {}
1129
1130 int ipv4_count_;
1131 int ipv6_count_;
1132 };
1133
1134 bool test_ipv6_network_;
1135 bool test_extra_ipv4_network_;
1136 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1137
1138 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001139 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001140 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1141 }
1142
1143 private:
jbauchac8869e2015-07-03 01:36:14 -07001144 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001145 const ExpectedBestConnection& expected) const {
1146 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001147 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1148 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001149 expected.ipv4_count_);
1150 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001151 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1152 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001154 // This is used in the loopback call so there is only single host to host
1155 // candidate pair.
1156 EXPECT_EQ(metrics_observer->GetEnumCounter(
1157 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1158 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001159 0);
1160 EXPECT_EQ(metrics_observer->GetEnumCounter(
1161 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1162 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001163 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001164 }
1165 };
1166
1167 class LoopbackNetworkManager {
1168 public:
1169 LoopbackNetworkManager(WebRtcSessionTest* session,
1170 const LoopbackNetworkConfiguration& config)
1171 : config_(config) {
1172 session->AddInterface(
1173 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1174 if (config_.test_extra_ipv4_network_) {
1175 session->AddInterface(
1176 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1177 }
1178 if (config_.test_ipv6_network_) {
1179 session->AddInterface(
1180 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1181 }
1182 }
1183
1184 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1185 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1186 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1187 if (config_.test_extra_ipv4_network_) {
1188 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1189 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1190 }
1191 if (config_.test_ipv6_network_) {
1192 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1193 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1194 }
1195 }
1196
1197 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1198
1199 private:
1200 LoopbackNetworkConfiguration config_;
1201 };
1202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 // The method sets up a call from the session to itself, in a loopback
1204 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001205 // disconnection, and then a permanent disconnection.
1206 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1208 // While running the call, this method also checks if the session goes through
1209 // the correct sequence of ICE states when a connection is established,
1210 // broken, and re-established.
1211 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001212 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1213 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001215
stefanc1aeaf02015-10-15 07:26:07 -07001216 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001217 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001218 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001219 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220
1221 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1222 observer_.ice_gathering_state_);
1223 SetLocalDescriptionWithoutError(offer);
1224 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1225 observer_.ice_connection_state_);
1226 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001227 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1229 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001230 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231
1232 std::string sdp;
1233 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001234 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1235 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 ASSERT_TRUE(desc != NULL);
1237 SetRemoteDescriptionWithoutError(desc);
1238
1239 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001240 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001241
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001242 // The ice connection state is "Connected" too briefly to catch in a test.
1243 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001244 observer_.ice_connection_state_, kIceCandidatesTimeout);
1245 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246
stefanc1aeaf02015-10-15 07:26:07 -07001247 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1248 LoopbackNetworkManager loopback_network_manager(this, config);
1249 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001250 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 // Adding firewall rule to block ping requests, which should cause
1252 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001253
1254 loopback_network_manager.ApplyFirewallRules(fss_.get());
1255
1256 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1258 observer_.ice_connection_state_,
1259 kIceCandidatesTimeout);
1260
jbauchac8869e2015-07-03 01:36:14 -07001261 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001264 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001266 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001267 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268 observer_.ice_connection_state_,
1269 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001270
1271 // Now we block ping requests and wait until the ICE connection transitions
1272 // to the Failed state. This will take at least 30 seconds because it must
1273 // wait for the Port to timeout.
1274 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275
1276 loopback_network_manager.ApplyFirewallRules(fss_.get());
1277 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001278 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001279 observer_.ice_connection_state_,
1280 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 }
1282
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001283 void TestLoopbackCall() {
1284 LoopbackNetworkConfiguration config;
1285 TestLoopbackCall(config);
1286 }
1287
stefanc1aeaf02015-10-15 07:26:07 -07001288 void TestPacketOptions() {
1289 media_controller_.reset(
1290 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1291 LoopbackNetworkConfiguration config;
1292 LoopbackNetworkManager loopback_network_manager(this, config);
1293
1294 SetupLoopbackCall();
1295
1296 uint8_t test_packet[15] = {0};
1297 rtc::PacketOptions options;
1298 options.packet_id = 10;
1299 media_engine_->GetVideoChannel(0)
1300 ->SendRtp(test_packet, sizeof(test_packet), options);
1301
1302 const int kPacketTimeout = 2000;
1303 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1304 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1305 }
1306
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1308 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001309 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1310 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1311
1312 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1314 codecs.push_back(kCNCodec1);
1315 codecs.push_back(kCNCodec2);
1316 media_engine_->SetAudioCodecs(codecs);
1317 desc_factory_->set_audio_codecs(codecs);
1318 }
1319
1320 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1321 const cricket::ContentDescription* description = content->description;
1322 ASSERT(description != NULL);
1323 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001324 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 ASSERT(audio_content_desc != NULL);
1326 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1327 if (audio_content_desc->codecs()[i].name == "CN")
1328 return false;
1329 }
1330 return true;
1331 }
1332
deadbeefab9b2d12015-10-14 11:33:11 -07001333 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001334 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001335 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1336 data_channel_ = DataChannel::Create(
1337 session_.get(), session_->data_channel_type(), "datachannel", dci);
1338 }
1339
1340 void SetLocalDescriptionWithDataChannel() {
1341 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001342 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 SetLocalDescriptionWithoutError(offer);
1344 }
1345
wu@webrtc.org91053e72013-08-10 07:18:04 +00001346 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001347 RTCCertificateGenerationMethod cert_gen_method,
1348 CreateSessionDescriptionRequest::Type type) {
1349 InitWithDtls(cert_gen_method);
1350 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1351 }
1352
1353 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1354 CreateSessionDescriptionRequest::Type type) {
1355 InitWithDtlsIdentityGenFail();
1356 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1357 }
1358
1359 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001360 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001361 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001362 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001363 if (type == CreateSessionDescriptionRequest::kAnswer) {
1364 cricket::MediaSessionOptions options;
1365 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001366 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001367 ASSERT_TRUE(offer.get() != NULL);
1368 SetRemoteDescriptionWithoutError(offer.release());
1369 }
1370
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001371 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001372 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001373 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001374 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 observers[kNumber];
1376 for (int i = 0; i < kNumber; ++i) {
1377 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1378 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001379 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001380 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001381 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001382 }
1383 }
1384
1385 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1386 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1387 WebRtcSessionCreateSDPObserverForTest::kFailed;
1388
1389 for (int i = 0; i < kNumber; ++i) {
1390 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1391 if (success) {
1392 EXPECT_TRUE(observers[i]->description() != NULL);
1393 } else {
1394 EXPECT_TRUE(observers[i]->description() == NULL);
1395 }
1396 }
1397 }
1398
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001399 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001400 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001401 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001402 turn_server.credentials = credentials;
1403 turn_server.ports.push_back(
1404 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1405 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001406 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001407 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001408 }
1409
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 cricket::FakeMediaEngine* media_engine_;
1411 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001413 cricket::FakeCall fake_call_;
1414 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001415 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001416 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1417 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1418 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1419 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1420 rtc::SocketServerScope ss_scope_;
1421 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001422 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001423 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001424 rtc::FakeNetworkManager network_manager_;
1425 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001426 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001427 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001428 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 MockIceObserver observer_;
1430 cricket::FakeVideoMediaChannel* video_channel_;
1431 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001432 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001433 // The following flags affect options created for CreateOffer/CreateAnswer.
1434 bool send_stream_1_ = false;
1435 bool send_stream_2_ = false;
1436 bool send_audio_ = false;
1437 bool send_video_ = false;
1438 rtc::scoped_refptr<DataChannel> data_channel_;
1439 // Last values received from data channel creation signal.
1440 std::string last_data_channel_label_;
1441 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001442 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443};
1444
Henrik Boström87713d02015-08-25 09:53:21 +02001445TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1446 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001447 // SDES is disabled when DTLS is on.
1448 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449}
1450
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001451TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001452 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001453 // SDES is required if DTLS is off.
1454 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001455}
1456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1458 TestSessionCandidatesWithBundleRtcpMux(false, false);
1459}
1460
1461// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1462// with rtcp-mux and/or bundle.
1463TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1464 TestSessionCandidatesWithBundleRtcpMux(false, true);
1465}
1466
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1468 TestSessionCandidatesWithBundleRtcpMux(true, true);
1469}
1470
1471TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1473 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001474 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001475 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 InitiateCall();
1477 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1478 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1479 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1480}
1481
minyuec8930ba2016-01-22 06:17:46 -08001482// Crashes on Win only. See webrtc:5411.
1483#if defined(WEBRTC_WIN)
1484#define MAYBE_TestStunError DISABLED_TestStunError
1485#else
1486#define MAYBE_TestStunError TestStunError
1487#endif
1488TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001489 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1490 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001491 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001492 rtc::FP_UDP,
1493 rtc::FD_ANY,
1494 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001495 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001496 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001498 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1500 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1501 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1502}
1503
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001504// Test session delivers no candidates gathered when constraint set to "none".
1505TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1506 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001507 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001508 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001509 InitiateCall();
1510 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1511 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1512 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1513}
1514
1515// Test session delivers only relay candidates gathered when constaint set to
1516// "relay".
1517TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1518 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1519 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001520 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001521 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001522 InitiateCall();
1523 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1524 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1525 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1526 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1527 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1528 observer_.mline_0_candidates_[i].type());
1529 }
1530 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1531 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1532 observer_.mline_1_candidates_[i].type());
1533 }
1534}
1535
1536// Test session delivers all candidates gathered when constaint set to "all".
1537TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1538 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001539 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001540 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001541 InitiateCall();
1542 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1543 // Host + STUN. By default allocator is disabled to gather relay candidates.
1544 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1545 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1546}
1547
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001548TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001549 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001550 SessionDescriptionInterface* offer = NULL;
1551 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1552 std::string unknown_action;
1553 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1554 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1555}
1556
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557// Test creating offers and receive answers and make sure the
1558// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001559TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001560 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001561 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001562 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 const std::string session_id_orig = offer->session_id();
1564 const std::string session_version_orig = offer->session_version();
1565 SetLocalDescriptionWithoutError(offer);
1566
deadbeefab9b2d12015-10-14 11:33:11 -07001567 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 SessionDescriptionInterface* answer =
1569 CreateRemoteAnswer(session_->local_description());
1570 SetRemoteDescriptionWithoutError(answer);
1571
1572 video_channel_ = media_engine_->GetVideoChannel(0);
1573 voice_channel_ = media_engine_->GetVoiceChannel(0);
1574
1575 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1576 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1577
1578 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1579 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1580
1581 ASSERT_EQ(1u, video_channel_->send_streams().size());
1582 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1583 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1584 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1585
1586 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001587 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001588 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589
1590 // Verify the session id is the same and the session version is
1591 // increased.
1592 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001593 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1594 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595
1596 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001597 EXPECT_EQ(0u, video_channel_->send_streams().size());
1598 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599
deadbeefab9b2d12015-10-14 11:33:11 -07001600 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 answer = CreateRemoteAnswer(session_->local_description());
1602 SetRemoteDescriptionWithoutError(answer);
1603
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 // Make sure the receive streams have not changed.
1605 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1606 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1607 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1608 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1609}
1610
1611// Test receiving offers and creating answers and make sure the
1612// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001613TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001614 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001615 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001616 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 SetRemoteDescriptionWithoutError(offer);
1619
deadbeefab9b2d12015-10-14 11:33:11 -07001620 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001621 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 SetLocalDescriptionWithoutError(answer);
1624
1625 const std::string session_id_orig = answer->session_id();
1626 const std::string session_version_orig = answer->session_version();
1627
1628 video_channel_ = media_engine_->GetVideoChannel(0);
1629 voice_channel_ = media_engine_->GetVoiceChannel(0);
1630
1631 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1632 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1633
1634 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1635 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1636
1637 ASSERT_EQ(1u, video_channel_->send_streams().size());
1638 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1640 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1641
deadbeefab9b2d12015-10-14 11:33:11 -07001642 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001643 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 SetRemoteDescriptionWithoutError(offer);
1645
1646 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001647 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001648 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649
1650 // Verify the session id is the same and the session version is
1651 // increased.
1652 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001653 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1654 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 SetLocalDescriptionWithoutError(answer);
1656
1657 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1658 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1659 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1660 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1661 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1662 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1663
1664 // Make sure we have no send streams.
1665 EXPECT_EQ(0u, video_channel_->send_streams().size());
1666 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1667}
1668
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001669TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001670 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001671 media_engine_->set_fail_create_channel(true);
1672
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001674 ASSERT_TRUE(offer != NULL);
1675 // SetRemoteDescription and SetLocalDescription will take the ownership of
1676 // the offer.
1677 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001678 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001679 ASSERT_TRUE(offer != NULL);
1680 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1681}
1682
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001683//
1684// Tests for creating/setting SDP under different SDES/DTLS polices:
1685//
1686// --DTLS off and SDES on
1687// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1688// set local/remote offer/answer with crypto --> success
1689// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1690// failure
1691// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1692// failure
1693// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1694// failure
1695//
1696// --DTLS on and SDES off
1697// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1698// set local/remote offer/answer with DTLS fingerprint --> success
1699// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1700// fingerprint --> failure
1701// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1702// --> failure
1703// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1704// --> failure
1705//
1706// --Encryption disabled: DTLS off and SDES off
1707// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1708// answer without SDES or DTLS --> success
1709// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1710// answer without SDES or DTLS --> success
1711//
1712
1713// Test that we return a failure when applying a remote/local offer that doesn't
1714// have cryptos enabled when DTLS is off.
1715TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001716 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001718 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 JsepSessionDescription* offer = CreateRemoteOffer(
1720 options, cricket::SEC_DISABLED);
1721 ASSERT_TRUE(offer != NULL);
1722 VerifyNoCryptoParams(offer->description(), false);
1723 // SetRemoteDescription and SetLocalDescription will take the ownership of
1724 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001725 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1727 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001728 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729}
1730
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731// Test that we return a failure when applying a local answer that doesn't have
1732// cryptos enabled when DTLS is off.
1733TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001734 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 SessionDescriptionInterface* offer = NULL;
1736 SessionDescriptionInterface* answer = NULL;
1737 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1738 // SetRemoteDescription and SetLocalDescription will take the ownership of
1739 // the offer.
1740 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742}
1743
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744// Test we will return fail when apply an remote answer that doesn't have
1745// crypto enabled when DTLS is off.
1746TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 SessionDescriptionInterface* offer = NULL;
1749 SessionDescriptionInterface* answer = NULL;
1750 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1751 // SetRemoteDescription and SetLocalDescription will take the ownership of
1752 // the offer.
1753 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001754 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1758// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001759TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001760 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001761 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001762 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 SetFactoryDtlsSrtp();
1764 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001765 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766 JsepSessionDescription* offer =
1767 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 ASSERT_TRUE(offer != NULL);
1769 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // SetRemoteDescription will take the ownership of the offer.
1773 SetRemoteDescriptionWithoutError(offer);
1774
1775 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001776 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 ASSERT_TRUE(answer != NULL);
1778 VerifyFingerprintStatus(answer->description(), true);
1779 // Check that we don't have an a=crypto line in the answer.
1780 VerifyNoCryptoParams(answer->description(), true);
1781
1782 // Now set the local description, which should work, even without a=crypto.
1783 SetLocalDescriptionWithoutError(answer);
1784}
1785
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1787// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001788TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001789 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001790 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001791 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792 SetFactoryDtlsSrtp();
1793
1794 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001795 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796 ASSERT_TRUE(offer != NULL);
1797 VerifyFingerprintStatus(offer->description(), true);
1798 // Check that we don't have an a=crypto line in the offer.
1799 VerifyNoCryptoParams(offer->description(), true);
1800
1801 // Now set the local description, which should work, even without a=crypto.
1802 SetLocalDescriptionWithoutError(offer);
1803
1804 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001805 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 JsepSessionDescription* answer =
1807 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1808 ASSERT_TRUE(answer != NULL);
1809 VerifyFingerprintStatus(answer->description(), true);
1810 VerifyNoCryptoParams(answer->description(), true);
1811
1812 // SetRemoteDescription will take the ownership of the answer.
1813 SetRemoteDescriptionWithoutError(answer);
1814}
1815
1816// Test that if we support DTLS and the other side didn't offer a fingerprint,
1817// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001818TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001819 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001820 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001822 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 JsepSessionDescription* offer = CreateRemoteOffer(
1825 options, cricket::SEC_REQUIRED);
1826 ASSERT_TRUE(offer != NULL);
1827 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 // SetRemoteDescription will take the ownership of the offer.
1831 SetRemoteDescriptionOfferExpectError(
1832 kSdpWithoutDtlsFingerprint, offer);
1833
1834 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1835 // SetLocalDescription will take the ownership of the offer.
1836 SetLocalDescriptionOfferExpectError(
1837 kSdpWithoutDtlsFingerprint, offer);
1838}
1839
1840// Test that we return a failure when applying a local answer that doesn't have
1841// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001842TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001843 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001844 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 SessionDescriptionInterface* offer = NULL;
1846 SessionDescriptionInterface* answer = NULL;
1847 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1848
1849 // SetRemoteDescription and SetLocalDescription will take the ownership of
1850 // the offer and answer.
1851 SetRemoteDescriptionWithoutError(offer);
1852 SetLocalDescriptionAnswerExpectError(
1853 kSdpWithoutDtlsFingerprint, answer);
1854}
1855
1856// Test that we return a failure when applying a remote answer that doesn't have
1857// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001858TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001859 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001860 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001861 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001863 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001864 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1865 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001867 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001868
1869 // SetRemoteDescription and SetLocalDescription will take the ownership of
1870 // the offer and answer.
1871 SetLocalDescriptionWithoutError(offer);
1872 SetRemoteDescriptionAnswerExpectError(
1873 kSdpWithoutDtlsFingerprint, answer);
1874}
1875
1876// Test that we create a local offer without SDES or DTLS and accept a remote
1877// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001878TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001879 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001881 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882
1883 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001884 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885 ASSERT_TRUE(offer != NULL);
1886 VerifyFingerprintStatus(offer->description(), false);
1887 // Check that we don't have an a=crypto line in the offer.
1888 VerifyNoCryptoParams(offer->description(), false);
1889
1890 // Now set the local description, which should work, even without a=crypto.
1891 SetLocalDescriptionWithoutError(offer);
1892
1893 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001894 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 JsepSessionDescription* answer =
1896 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1897 ASSERT_TRUE(answer != NULL);
1898 VerifyFingerprintStatus(answer->description(), false);
1899 VerifyNoCryptoParams(answer->description(), false);
1900
1901 // SetRemoteDescription will take the ownership of the answer.
1902 SetRemoteDescriptionWithoutError(answer);
1903}
1904
1905// Test that we create a local answer without SDES or DTLS and accept a remote
1906// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001907TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001909 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001910
1911 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001912 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 JsepSessionDescription* offer =
1914 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1915 ASSERT_TRUE(offer != NULL);
1916 VerifyFingerprintStatus(offer->description(), false);
1917 VerifyNoCryptoParams(offer->description(), false);
1918
1919 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 SetRemoteDescriptionWithoutError(offer);
1921
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001923 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 ASSERT_TRUE(answer != NULL);
1925 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001926 // Check that we don't have an a=crypto line in the answer.
1927 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001929 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 SetLocalDescriptionWithoutError(answer);
1931}
1932
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001933// Test that we can create and set an answer correctly when different
1934// SSL roles have been negotiated for different transports.
1935// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1936TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1937 SendAudioVideoStream1();
1938 InitWithDtls(GetParam());
1939 SetFactoryDtlsSrtp();
1940
1941 SessionDescriptionInterface* offer = CreateOffer();
1942 SetLocalDescriptionWithoutError(offer);
1943
1944 cricket::MediaSessionOptions options;
1945 options.recv_video = true;
1946
1947 // First, negotiate different SSL roles.
1948 SessionDescriptionInterface* answer =
1949 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1950 TransportInfo* audio_transport_info =
1951 answer->description()->GetTransportInfoByName("audio");
1952 audio_transport_info->description.connection_role =
1953 cricket::CONNECTIONROLE_ACTIVE;
1954 TransportInfo* video_transport_info =
1955 answer->description()->GetTransportInfoByName("video");
1956 video_transport_info->description.connection_role =
1957 cricket::CONNECTIONROLE_PASSIVE;
1958 SetRemoteDescriptionWithoutError(answer);
1959
1960 // Now create an offer in the reverse direction, and ensure the initial
1961 // offerer responds with an answer with correct SSL roles.
1962 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1963 kSessionVersion,
1964 session_->remote_description());
1965 SetRemoteDescriptionWithoutError(offer);
1966
1967 answer = CreateAnswer(nullptr);
1968 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1969 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1970 audio_transport_info->description.connection_role);
1971 video_transport_info = answer->description()->GetTransportInfoByName("video");
1972 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1973 video_transport_info->description.connection_role);
1974 SetLocalDescriptionWithoutError(answer);
1975
1976 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1977 // audio is transferred over to video in the answer that completes the BUNDLE
1978 // negotiation.
1979 options.bundle_enabled = true;
1980 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1981 kSessionVersion,
1982 session_->remote_description());
1983 SetRemoteDescriptionWithoutError(offer);
1984 answer = CreateAnswer(nullptr);
1985 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1986 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1987 audio_transport_info->description.connection_role);
1988 video_transport_info = answer->description()->GetTransportInfoByName("video");
1989 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1990 video_transport_info->description.connection_role);
1991 SetLocalDescriptionWithoutError(answer);
1992}
1993
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001996 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001998 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 SetLocalDescriptionWithoutError(offer);
2000
2001 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002002 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 SetLocalDescriptionWithoutError(offer2);
2004}
2005
2006TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002007 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002008 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002010 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 SetRemoteDescriptionWithoutError(offer);
2012
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetRemoteDescriptionWithoutError(offer2);
2015}
2016
2017TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002018 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002019 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002020 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002022 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002023 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2024 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025}
2026
2027TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002028 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002029 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002033 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002034 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035}
2036
2037TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002039 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002041 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
2043 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002044 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002046 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047
deadbeefab9b2d12015-10-14 11:33:11 -07002048 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002050 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2052
deadbeefd59daf82015-10-14 15:02:44 -07002053 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002056 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002057 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058}
2059
2060TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002062 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002064 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065
2066 JsepSessionDescription* pranswer =
2067 CreateRemoteAnswer(session_->local_description());
2068 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2069
2070 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002071 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 JsepSessionDescription* pranswer2 =
2075 CreateRemoteAnswer(session_->local_description());
2076 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2077
2078 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002079 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080
deadbeefab9b2d12015-10-14 11:33:11 -07002081 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 SessionDescriptionInterface* answer =
2083 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002084 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085}
2086
2087TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2091
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 SessionDescriptionInterface* answer =
2093 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002094 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2095 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096}
2097
2098TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002100 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SessionDescriptionInterface* answer =
2104 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002105 SetRemoteDescriptionAnswerExpectError(
2106 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002110 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112
2113 cricket::Candidate candidate;
2114 candidate.set_component(1);
2115 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2116
deadbeefd59daf82015-10-14 15:02:44 -07002117 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2119
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002120 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002122
2123 // Fail since we have not set a remote description.
2124 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
2126 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2127 session_->local_description());
2128 SetRemoteDescriptionWithoutError(answer);
2129
deadbeefd59daf82015-10-14 15:02:44 -07002130 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2131 candidate.set_component(2);
2132 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2133 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 // Verifying the candidates are copied properly from internal vector.
2136 const SessionDescriptionInterface* remote_desc =
2137 session_->remote_description();
2138 ASSERT_TRUE(remote_desc != NULL);
2139 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2140 const IceCandidateCollection* candidates =
2141 remote_desc->candidates(kMediaContentIndex0);
2142 ASSERT_EQ(2u, candidates->count());
2143 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2144 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2145 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2146 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2147
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002148 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2149 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 candidate.set_component(2);
2151 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2152 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002153 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
2155 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2156 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2157}
2158
2159// Test that a remote candidate is added to the remote session description and
2160// that it is retained if the remote session description is changed.
2161TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002162 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 cricket::Candidate candidate1;
2164 candidate1.set_component(1);
2165 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2166 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002167 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 CreateAndSetRemoteOfferAndLocalAnswer();
2169
2170 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2171 const SessionDescriptionInterface* remote_desc =
2172 session_->remote_description();
2173 ASSERT_TRUE(remote_desc != NULL);
2174 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2175 const IceCandidateCollection* candidates =
2176 remote_desc->candidates(kMediaContentIndex0);
2177 ASSERT_EQ(1u, candidates->count());
2178 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2179
2180 // Update the RemoteSessionDescription with a new session description and
2181 // a candidate and check that the new remote session description contains both
2182 // candidates.
2183 SessionDescriptionInterface* offer = CreateRemoteOffer();
2184 cricket::Candidate candidate2;
2185 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2186 candidate2);
2187 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2188 SetRemoteDescriptionWithoutError(offer);
2189
2190 remote_desc = session_->remote_description();
2191 ASSERT_TRUE(remote_desc != NULL);
2192 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2193 candidates = remote_desc->candidates(kMediaContentIndex0);
2194 ASSERT_EQ(2u, candidates->count());
2195 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2196 // Username and password have be updated with the TransportInfo of the
2197 // SessionDescription, won't be equal to the original one.
2198 candidate2.set_username(candidates->at(0)->candidate().username());
2199 candidate2.set_password(candidates->at(0)->candidate().password());
2200 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2201 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2202 // No need to verify the username and password.
2203 candidate1.set_username(candidates->at(1)->candidate().username());
2204 candidate1.set_password(candidates->at(1)->candidate().password());
2205 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2206
2207 // Test that the candidate is ignored if we can add the same candidate again.
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2209}
2210
2211// Test that local candidates are added to the local session description and
2212// that they are retained if the local session description is changed.
2213TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002214 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002215 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002216 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 CreateAndSetRemoteOfferAndLocalAnswer();
2218
2219 const SessionDescriptionInterface* local_desc = session_->local_description();
2220 const IceCandidateCollection* candidates =
2221 local_desc->candidates(kMediaContentIndex0);
2222 ASSERT_TRUE(candidates != NULL);
2223 EXPECT_EQ(0u, candidates->count());
2224
2225 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2226
2227 local_desc = session_->local_description();
2228 candidates = local_desc->candidates(kMediaContentIndex0);
2229 ASSERT_TRUE(candidates != NULL);
2230 EXPECT_LT(0u, candidates->count());
2231 candidates = local_desc->candidates(1);
2232 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002233 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234
2235 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002236 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 CreateAndSetRemoteOfferAndLocalAnswer();
2238
2239 local_desc = session_->local_description();
2240 candidates = local_desc->candidates(kMediaContentIndex0);
2241 ASSERT_TRUE(candidates != NULL);
2242 EXPECT_LT(0u, candidates->count());
2243 candidates = local_desc->candidates(1);
2244 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002245 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246}
2247
2248// Test that we can set a remote session description with remote candidates.
2249TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002250 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251
2252 cricket::Candidate candidate1;
2253 candidate1.set_component(1);
2254 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2255 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002256 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002257 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258
2259 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2260 SetRemoteDescriptionWithoutError(offer);
2261
2262 const SessionDescriptionInterface* remote_desc =
2263 session_->remote_description();
2264 ASSERT_TRUE(remote_desc != NULL);
2265 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2266 const IceCandidateCollection* candidates =
2267 remote_desc->candidates(kMediaContentIndex0);
2268 ASSERT_EQ(1u, candidates->count());
2269 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2270
wu@webrtc.org91053e72013-08-10 07:18:04 +00002271 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 SetLocalDescriptionWithoutError(answer);
2273}
2274
2275// Test that offers and answers contains ice candidates when Ice candidates have
2276// been gathered.
2277TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002278 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002279 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002280 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 // Ice is started but candidates are not provided until SetLocalDescription
2282 // is called.
2283 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2284 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2285 CreateAndSetRemoteOfferAndLocalAnswer();
2286 // Wait until at least one local candidate has been collected.
2287 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2288 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002290 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2293 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294
2295 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2296 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002297 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2299 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 SetLocalDescriptionWithoutError(answer);
2301}
2302
2303// Verifies TransportProxy and media channels are created with content names
2304// present in the SessionDescription.
2305TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002306 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002308 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309
2310 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002311 // "video". Goal is to modify these content names and verify transport
2312 // channels
2313 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 // present in SDP.
2315 std::string sdp;
2316 EXPECT_TRUE(offer->ToString(&sdp));
2317 const std::string kAudioMid = "a=mid:audio";
2318 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2319 const std::string kVideoMid = "a=mid:video";
2320 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2321
2322 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 kAudioMidReplaceStr.c_str(),
2325 kAudioMidReplaceStr.length(),
2326 &sdp);
2327 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002328 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 kVideoMidReplaceStr.c_str(),
2330 kVideoMidReplaceStr.length(),
2331 &sdp);
2332
2333 SessionDescriptionInterface* modified_offer =
2334 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2335
2336 SetRemoteDescriptionWithoutError(modified_offer);
2337
2338 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002339 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 SetLocalDescriptionWithoutError(answer);
2341
deadbeefcbecd352015-09-23 11:50:27 -07002342 cricket::TransportChannel* voice_transport_channel =
2343 session_->voice_rtp_transport_channel();
2344 EXPECT_TRUE(voice_transport_channel != NULL);
2345 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2346 cricket::TransportChannel* video_transport_channel =
2347 session_->video_rtp_transport_channel();
2348 EXPECT_TRUE(video_transport_channel != NULL);
2349 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2351 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2352}
2353
2354// Test that an offer contains the correct media content descriptions based on
2355// the send streams when no constraints have been set.
2356TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002357 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002358 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 ASSERT_TRUE(offer != NULL);
2361 const cricket::ContentInfo* content =
2362 cricket::GetFirstAudioContent(offer->description());
2363 EXPECT_TRUE(content != NULL);
2364 content = cricket::GetFirstVideoContent(offer->description());
2365 EXPECT_TRUE(content == NULL);
2366}
2367
2368// Test that an offer contains the correct media content descriptions based on
2369// the send streams when no constraints have been set.
2370TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002371 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002373 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002374 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 const cricket::ContentInfo* content =
2377 cricket::GetFirstAudioContent(offer->description());
2378 EXPECT_TRUE(content != NULL);
2379 content = cricket::GetFirstVideoContent(offer->description());
2380 EXPECT_TRUE(content == NULL);
2381
2382 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002383 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002384 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 content = cricket::GetFirstAudioContent(offer->description());
2386 EXPECT_TRUE(content != NULL);
2387 content = cricket::GetFirstVideoContent(offer->description());
2388 EXPECT_TRUE(content != NULL);
2389}
2390
2391// Test that an offer contains no media content descriptions if
2392// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2393TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002394 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002395 PeerConnectionInterface::RTCOfferAnswerOptions options;
2396 options.offer_to_receive_audio = 0;
2397 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002399 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002400 CreateOffer(options));
2401
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 ASSERT_TRUE(offer != NULL);
2403 const cricket::ContentInfo* content =
2404 cricket::GetFirstAudioContent(offer->description());
2405 EXPECT_TRUE(content == NULL);
2406 content = cricket::GetFirstVideoContent(offer->description());
2407 EXPECT_TRUE(content == NULL);
2408}
2409
2410// Test that an offer contains only audio media content descriptions if
2411// kOfferToReceiveAudio constraints are set to true.
2412TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002413 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002414 PeerConnectionInterface::RTCOfferAnswerOptions options;
2415 options.offer_to_receive_audio =
2416 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2417
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002418 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002419 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420
2421 const cricket::ContentInfo* content =
2422 cricket::GetFirstAudioContent(offer->description());
2423 EXPECT_TRUE(content != NULL);
2424 content = cricket::GetFirstVideoContent(offer->description());
2425 EXPECT_TRUE(content == NULL);
2426}
2427
2428// Test that an offer contains audio and video media content descriptions if
2429// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2430TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002431 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002433 PeerConnectionInterface::RTCOfferAnswerOptions options;
2434 options.offer_to_receive_audio =
2435 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2436 options.offer_to_receive_video =
2437 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2438
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002439 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002440 CreateOffer(options));
2441
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 const cricket::ContentInfo* content =
2443 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002444 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002445
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 content = cricket::GetFirstVideoContent(offer->description());
2447 EXPECT_TRUE(content != NULL);
2448
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002449 // Sets constraints to false and verifies that audio/video contents are
2450 // removed.
2451 options.offer_to_receive_audio = 0;
2452 options.offer_to_receive_video = 0;
2453 offer.reset(CreateOffer(options));
2454
2455 content = cricket::GetFirstAudioContent(offer->description());
2456 EXPECT_TRUE(content == NULL);
2457 content = cricket::GetFirstVideoContent(offer->description());
2458 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459}
2460
2461// Test that an answer can not be created if the last remote description is not
2462// an offer.
2463TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002464 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002465 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 SetLocalDescriptionWithoutError(offer);
2467 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2468 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002469 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470}
2471
2472// Test that an answer contains the correct media content descriptions when no
2473// constraints have been set.
2474TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002475 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002477 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002479 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002480 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 const cricket::ContentInfo* content =
2482 cricket::GetFirstAudioContent(answer->description());
2483 ASSERT_TRUE(content != NULL);
2484 EXPECT_FALSE(content->rejected);
2485
2486 content = cricket::GetFirstVideoContent(answer->description());
2487 ASSERT_TRUE(content != NULL);
2488 EXPECT_FALSE(content->rejected);
2489}
2490
2491// Test that an answer contains the correct media content descriptions when no
2492// constraints have been set and the offer only contain audio.
2493TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002494 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 // Create a remote offer with audio only.
2496 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002497
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002498 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 CreateRemoteOffer(options));
2500 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2501 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2502
2503 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002504 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002505 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 const cricket::ContentInfo* content =
2507 cricket::GetFirstAudioContent(answer->description());
2508 ASSERT_TRUE(content != NULL);
2509 EXPECT_FALSE(content->rejected);
2510
2511 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2512}
2513
2514// Test that an answer contains the correct media content descriptions when no
2515// constraints have been set.
2516TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002517 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002519 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 SetRemoteDescriptionWithoutError(offer.release());
2521 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002522 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002523 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002524 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(answer->description());
2527 ASSERT_TRUE(content != NULL);
2528 EXPECT_FALSE(content->rejected);
2529
2530 content = cricket::GetFirstVideoContent(answer->description());
2531 ASSERT_TRUE(content != NULL);
2532 EXPECT_FALSE(content->rejected);
2533}
2534
2535// Test that an answer contains the correct media content descriptions when
2536// constraints have been set but no stream is sent.
2537TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002540 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 SetRemoteDescriptionWithoutError(offer.release());
2542
2543 webrtc::FakeConstraints constraints_no_receive;
2544 constraints_no_receive.SetMandatoryReceiveAudio(false);
2545 constraints_no_receive.SetMandatoryReceiveVideo(false);
2546
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002547 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002548 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 const cricket::ContentInfo* content =
2550 cricket::GetFirstAudioContent(answer->description());
2551 ASSERT_TRUE(content != NULL);
2552 EXPECT_TRUE(content->rejected);
2553
2554 content = cricket::GetFirstVideoContent(answer->description());
2555 ASSERT_TRUE(content != NULL);
2556 EXPECT_TRUE(content->rejected);
2557}
2558
2559// Test that an answer contains the correct media content descriptions when
2560// constraints have been set and streams are sent.
2561TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002562 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002564 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 SetRemoteDescriptionWithoutError(offer.release());
2566
2567 webrtc::FakeConstraints constraints_no_receive;
2568 constraints_no_receive.SetMandatoryReceiveAudio(false);
2569 constraints_no_receive.SetMandatoryReceiveVideo(false);
2570
2571 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002572 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002573 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002574 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575
2576 // TODO(perkj): Should the direction be set to SEND_ONLY?
2577 const cricket::ContentInfo* content =
2578 cricket::GetFirstAudioContent(answer->description());
2579 ASSERT_TRUE(content != NULL);
2580 EXPECT_FALSE(content->rejected);
2581
2582 // TODO(perkj): Should the direction be set to SEND_ONLY?
2583 content = cricket::GetFirstVideoContent(answer->description());
2584 ASSERT_TRUE(content != NULL);
2585 EXPECT_FALSE(content->rejected);
2586}
2587
2588TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2589 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002590 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002591 PeerConnectionInterface::RTCOfferAnswerOptions options;
2592 options.offer_to_receive_audio =
2593 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2594 options.voice_activity_detection = false;
2595
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002596 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002597 CreateOffer(options));
2598
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599 const cricket::ContentInfo* content =
2600 cricket::GetFirstAudioContent(offer->description());
2601 EXPECT_TRUE(content != NULL);
2602 EXPECT_TRUE(VerifyNoCNCodecs(content));
2603}
2604
2605TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2606 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002607 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002609 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 SetRemoteDescriptionWithoutError(offer.release());
2611
2612 webrtc::FakeConstraints constraints;
2613 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002614 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002615 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 const cricket::ContentInfo* content =
2617 cricket::GetFirstAudioContent(answer->description());
2618 ASSERT_TRUE(content != NULL);
2619 EXPECT_TRUE(VerifyNoCNCodecs(content));
2620}
2621
2622// This test verifies the call setup when remote answer with audio only and
2623// later updates with video.
2624TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002625 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2627 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2628
deadbeefab9b2d12015-10-14 11:33:11 -07002629 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002630 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631
2632 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2634
2635 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2636 // and answer;
2637 SetLocalDescriptionWithoutError(offer);
2638 SetRemoteDescriptionWithoutError(answer);
2639
2640 video_channel_ = media_engine_->GetVideoChannel(0);
2641 voice_channel_ = media_engine_->GetVoiceChannel(0);
2642
2643 ASSERT_TRUE(video_channel_ == NULL);
2644
2645 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2646 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2647 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2648
2649 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002650 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 CreateAndSetRemoteOfferAndLocalAnswer();
2652
2653 video_channel_ = media_engine_->GetVideoChannel(0);
2654 voice_channel_ = media_engine_->GetVoiceChannel(0);
2655
2656 ASSERT_TRUE(video_channel_ != NULL);
2657 ASSERT_TRUE(voice_channel_ != NULL);
2658
2659 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2660 ASSERT_EQ(1u, video_channel_->send_streams().size());
2661 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2662 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2663 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2664 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2665 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2666 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2667
2668 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002669 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 CreateAndSetRemoteOfferAndLocalAnswer();
2671
2672 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2673 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2674 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2675 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2676 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2677}
2678
2679// This test verifies the call setup when remote answer with video only and
2680// later updates with audio.
2681TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002682 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2684 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002685 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002686 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687
2688 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002689 options.recv_audio = false;
2690 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2692 offer, options, cricket::SEC_ENABLED);
2693
2694 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2695 // and answer.
2696 SetLocalDescriptionWithoutError(offer);
2697 SetRemoteDescriptionWithoutError(answer);
2698
2699 video_channel_ = media_engine_->GetVideoChannel(0);
2700 voice_channel_ = media_engine_->GetVoiceChannel(0);
2701
2702 ASSERT_TRUE(voice_channel_ == NULL);
2703 ASSERT_TRUE(video_channel_ != NULL);
2704
2705 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2706 ASSERT_EQ(1u, video_channel_->send_streams().size());
2707 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2708
2709 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002710 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 CreateAndSetRemoteOfferAndLocalAnswer();
2712
2713 voice_channel_ = media_engine_->GetVoiceChannel(0);
2714 ASSERT_TRUE(voice_channel_ != NULL);
2715
2716 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2717 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2718 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2719 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2720
2721 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002722 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 CreateAndSetRemoteOfferAndLocalAnswer();
2724
2725 video_channel_ = media_engine_->GetVideoChannel(0);
2726 voice_channel_ = media_engine_->GetVoiceChannel(0);
2727
2728 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2729 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2730 ASSERT_EQ(1u, video_channel_->send_streams().size());
2731 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2732}
2733
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002735 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002736 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002737 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 VerifyCryptoParams(offer->description());
2739 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002740 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741 VerifyCryptoParams(answer->description());
2742}
2743
2744TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002745 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002746 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002747 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002748 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 VerifyNoCryptoParams(offer->description(), false);
2750}
2751
2752TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 VerifyAnswerFromNonCryptoOffer();
2755}
2756
2757TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002758 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759 VerifyAnswerFromCryptoOffer();
2760}
2761
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002762// This test verifies that setLocalDescription fails if
2763// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2764TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002765 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002766 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002767 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2768
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002769 std::string sdp;
2770 RemoveIceUfragPwdLines(offer.get(), &sdp);
2771 SessionDescriptionInterface* modified_offer =
2772 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002773 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002774}
2775
2776// This test verifies that setRemoteDescription fails if
2777// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2778TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002779 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002780 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002781 std::string sdp;
2782 RemoveIceUfragPwdLines(offer.get(), &sdp);
2783 SessionDescriptionInterface* modified_offer =
2784 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002785 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002786}
2787
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002788// This test verifies that setLocalDescription fails if local offer has
2789// too short ice ufrag and pwd strings.
2790TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002791 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002792 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002793 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2794
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002795 std::string sdp;
2796 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2797 // recommended values of 4 and 22 bytes respectively.
2798 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2799 SessionDescriptionInterface* modified_offer =
2800 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2801 std::string error;
2802 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2803
2804 // Test with string greater than 256.
2805 sdp.clear();
2806 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2807 &sdp);
2808 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2809 NULL);
2810 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2811}
2812
2813// This test verifies that setRemoteDescription fails if remote offer has
2814// too short ice ufrag and pwd strings.
2815TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002816 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002817 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002818 std::string sdp;
2819 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2820 // recommended values of 4 and 22 bytes respectively.
2821 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2822 SessionDescriptionInterface* modified_offer =
2823 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2824 std::string error;
2825 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2826
2827 sdp.clear();
2828 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2829 &sdp);
2830 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2831 NULL);
2832 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2833}
2834
Honghai Zhang04e91462015-12-11 14:26:22 -08002835// Test that if the remote offer indicates the peer requested ICE restart (via
2836// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2837TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002838 Init();
2839 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2840
2841 // Create the first offer.
2842 std::string sdp;
2843 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2844 "abcdefghijklmnopqrstuvwx", &sdp);
2845 SessionDescriptionInterface* offer1 =
2846 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2847 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2848 0, "", "", "relay", 0, "");
2849 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2850 candidate1);
2851 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2852 SetRemoteDescriptionWithoutError(offer1);
2853 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2854
2855 // The second offer has the same ufrag and pwd but different address.
2856 sdp.clear();
2857 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2858 "abcdefghijklmnopqrstuvwx", &sdp);
2859 SessionDescriptionInterface* offer2 =
2860 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2861 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2862 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2863 candidate1);
2864 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2865 SetRemoteDescriptionWithoutError(offer2);
2866 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2867
2868 // The third offer has a different ufrag and different address.
2869 sdp.clear();
2870 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2871 "abcdefghijklmnopqrstuvwx", &sdp);
2872 SessionDescriptionInterface* offer3 =
2873 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2874 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2875 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2876 candidate1);
2877 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2878 SetRemoteDescriptionWithoutError(offer3);
2879 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2880
2881 // The fourth offer has no candidate but a different ufrag/pwd.
2882 sdp.clear();
2883 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2884 "abcdefghijklmnopqrstuvyz", &sdp);
2885 SessionDescriptionInterface* offer4 =
2886 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2887 SetRemoteDescriptionWithoutError(offer4);
2888 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2889}
2890
Honghai Zhang04e91462015-12-11 14:26:22 -08002891// Test that if the remote answer indicates the peer requested ICE restart (via
2892// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2893TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2894 Init();
2895 SessionDescriptionInterface* offer = CreateOffer();
2896 SetLocalDescriptionWithoutError(offer);
2897 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2898
2899 // Create the first answer.
2900 std::string sdp;
2901 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2902 "abcdefghijklmnopqrstuvwx", &sdp);
2903 SessionDescriptionInterface* answer1 =
2904 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2905 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2906 0, "", "", "relay", 0, "");
2907 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2908 candidate1);
2909 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2910 SetRemoteDescriptionWithoutError(answer1);
2911 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2912
2913 // The second answer has the same ufrag and pwd but different address.
2914 sdp.clear();
2915 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2916 "abcdefghijklmnopqrstuvwx", &sdp);
2917 SessionDescriptionInterface* answer2 =
2918 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2919 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2920 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2921 candidate1);
2922 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2923 SetRemoteDescriptionWithoutError(answer2);
2924 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2925
2926 // The third answer has a different ufrag and different address.
2927 sdp.clear();
2928 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2929 "abcdefghijklmnopqrstuvwx", &sdp);
2930 SessionDescriptionInterface* answer3 =
2931 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2932 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2933 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2934 candidate1);
2935 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2936 SetRemoteDescriptionWithoutError(answer3);
2937 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2938
2939 // The fourth answer has no candidate but a different ufrag/pwd.
2940 sdp.clear();
2941 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2942 "abcdefghijklmnopqrstuvyz", &sdp);
2943 SessionDescriptionInterface* offer4 =
2944 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2945 SetRemoteDescriptionWithoutError(offer4);
2946 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2947}
2948
Donald Curtisd4f769d2015-05-28 09:48:21 -07002949// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002950// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002951TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2952 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2953
2954 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002955 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002956
2957 PeerConnectionInterface::RTCOfferAnswerOptions options;
2958 options.use_rtp_mux = true;
2959
2960 SessionDescriptionInterface* offer = CreateRemoteOffer();
2961 SetRemoteDescriptionWithoutError(offer);
2962
2963 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2964 SetLocalDescriptionWithoutError(answer);
2965
deadbeefcbecd352015-09-23 11:50:27 -07002966 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2967 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002968
deadbeefcbecd352015-09-23 11:50:27 -07002969 cricket::BaseChannel* voice_channel = session_->voice_channel();
2970 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002971
2972 // Checks if one of the transport channels contains a connection using a given
2973 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002974 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002975 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002976 session_->GetChannelTransportStats(voice_channel, &stats);
2977 for (auto& kv : stats.transport_stats) {
2978 for (auto& chan_stat : kv.second.channel_stats) {
2979 for (auto& conn_info : chan_stat.connection_infos) {
2980 if (conn_info.remote_candidate.address().port() == port) {
2981 return true;
2982 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002983 }
2984 }
2985 }
2986 return false;
2987 };
2988
2989 EXPECT_FALSE(connection_with_remote_port(5000));
2990 EXPECT_FALSE(connection_with_remote_port(5001));
2991 EXPECT_FALSE(connection_with_remote_port(6000));
2992
2993 // The way the *_WAIT checks work is they only wait if the condition fails,
2994 // which does not help in the case where state is not changing. This is
2995 // problematic in this test since we want to verify that adding a video
2996 // candidate does _not_ change state. So we interleave candidates and assume
2997 // that messages are executed in the order they were posted.
2998
2999 // First audio candidate.
3000 cricket::Candidate candidate0;
3001 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3002 candidate0.set_component(1);
3003 candidate0.set_protocol("udp");
3004 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3005 candidate0);
3006 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3007
3008 // Video candidate.
3009 cricket::Candidate candidate1;
3010 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3011 candidate1.set_component(1);
3012 candidate1.set_protocol("udp");
3013 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3014 candidate1);
3015 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3016
3017 // Second audio candidate.
3018 cricket::Candidate candidate2;
3019 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3020 candidate2.set_component(1);
3021 candidate2.set_protocol("udp");
3022 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3023 candidate2);
3024 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3025
3026 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3027 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3028
3029 // No need here for a _WAIT check since we are checking that state hasn't
3030 // changed: if this is false we would be doing waits for nothing and if this
3031 // is true then there will be no messages processed anyways.
3032 EXPECT_FALSE(connection_with_remote_port(6000));
3033}
3034
deadbeefcbecd352015-09-23 11:50:27 -07003035// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003036TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3037 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003038 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003039
3040 PeerConnectionInterface::RTCOfferAnswerOptions options;
3041 options.use_rtp_mux = true;
3042
3043 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003045
deadbeefcbecd352015-09-23 11:50:27 -07003046 EXPECT_NE(session_->voice_rtp_transport_channel(),
3047 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003048
deadbeefab9b2d12015-10-14 11:33:11 -07003049 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003050 SessionDescriptionInterface* answer =
3051 CreateRemoteAnswer(session_->local_description());
3052 SetRemoteDescriptionWithoutError(answer);
3053
deadbeefcbecd352015-09-23 11:50:27 -07003054 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3055 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003056}
3057
deadbeefcbecd352015-09-23 11:50:27 -07003058// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003059TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3060 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003061 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003062
Donald Curtis0e209b02015-03-24 09:29:54 -07003063 PeerConnectionInterface::RTCOfferAnswerOptions options;
3064 options.use_rtp_mux = true;
3065
3066 SessionDescriptionInterface* offer = CreateOffer(options);
3067 SetLocalDescriptionWithoutError(offer);
3068
deadbeefcbecd352015-09-23 11:50:27 -07003069 EXPECT_NE(session_->voice_rtp_transport_channel(),
3070 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003071
deadbeefab9b2d12015-10-14 11:33:11 -07003072 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003073
3074 // Remove BUNDLE from the answer.
3075 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3076 CreateRemoteAnswer(session_->local_description()));
3077 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3078 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3079 JsepSessionDescription* modified_answer =
3080 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3081 modified_answer->Initialize(answer_copy, "1", "1");
3082 SetRemoteDescriptionWithoutError(modified_answer); //
3083
deadbeefcbecd352015-09-23 11:50:27 -07003084 EXPECT_NE(session_->voice_rtp_transport_channel(),
3085 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003086}
3087
3088// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3089TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3090 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003091 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003092
3093 PeerConnectionInterface::RTCOfferAnswerOptions options;
3094 options.use_rtp_mux = true;
3095
3096 SessionDescriptionInterface* offer = CreateOffer(options);
3097 SetLocalDescriptionWithoutError(offer);
3098
deadbeefcbecd352015-09-23 11:50:27 -07003099 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3100 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003101
deadbeefab9b2d12015-10-14 11:33:11 -07003102 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003103 SessionDescriptionInterface* answer =
3104 CreateRemoteAnswer(session_->local_description());
3105 SetRemoteDescriptionWithoutError(answer);
3106
deadbeefcbecd352015-09-23 11:50:27 -07003107 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3108 session_->video_rtp_transport_channel());
3109}
3110
3111// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3112// audio content in the answer.
3113TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3114 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003115 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003116
3117 PeerConnectionInterface::RTCOfferAnswerOptions options;
3118 options.use_rtp_mux = true;
3119
3120 SessionDescriptionInterface* offer = CreateOffer(options);
3121 SetLocalDescriptionWithoutError(offer);
3122
3123 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3124 session_->video_rtp_transport_channel());
3125
deadbeefab9b2d12015-10-14 11:33:11 -07003126 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003127 cricket::MediaSessionOptions recv_options;
3128 recv_options.recv_audio = false;
3129 recv_options.recv_video = true;
3130 SessionDescriptionInterface* answer =
3131 CreateRemoteAnswer(session_->local_description(), recv_options);
3132 SetRemoteDescriptionWithoutError(answer);
3133
deadbeefd59daf82015-10-14 15:02:44 -07003134 EXPECT_TRUE(nullptr == session_->voice_channel());
3135 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003136
deadbeefd59daf82015-10-14 15:02:44 -07003137 session_->Close();
3138 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3139 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3140 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3141 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003142}
3143
3144// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3145TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3146 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003147 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003148
Donald Curtis0e209b02015-03-24 09:29:54 -07003149 PeerConnectionInterface::RTCOfferAnswerOptions options;
3150 options.use_rtp_mux = true;
3151
3152 SessionDescriptionInterface* offer = CreateOffer(options);
3153 SetLocalDescriptionWithoutError(offer);
3154
deadbeefcbecd352015-09-23 11:50:27 -07003155 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3156 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003157
deadbeefab9b2d12015-10-14 11:33:11 -07003158 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003159
3160 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003161 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162 CreateRemoteAnswer(session_->local_description()));
3163 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3164 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3165 JsepSessionDescription* modified_answer =
3166 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3167 modified_answer->Initialize(answer_copy, "1", "1");
3168 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169
deadbeefcbecd352015-09-23 11:50:27 -07003170 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3171 session_->video_rtp_transport_channel());
3172}
3173
3174// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3175TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3176 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003177 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003178
3179 SessionDescriptionInterface* offer = CreateRemoteOffer();
3180 SetRemoteDescriptionWithoutError(offer);
3181
3182 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3183 session_->video_rtp_transport_channel());
3184
deadbeefab9b2d12015-10-14 11:33:11 -07003185 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003186 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3187 SetLocalDescriptionWithoutError(answer);
3188
3189 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3190 session_->video_rtp_transport_channel());
3191}
3192
3193// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3194TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3195 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003196 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003197
3198 // Remove BUNDLE from the offer.
3199 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3200 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3201 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3202 JsepSessionDescription* modified_offer =
3203 new JsepSessionDescription(JsepSessionDescription::kOffer);
3204 modified_offer->Initialize(offer_copy, "1", "1");
3205
3206 // Expect an error when applying the remote description
3207 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3208 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003209}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210
Peter Thatcher4eddf182015-04-30 10:55:59 -07003211// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003212TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3213 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003214 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003215
Donald Curtis0e209b02015-03-24 09:29:54 -07003216 PeerConnectionInterface::RTCOfferAnswerOptions options;
3217 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003218
Donald Curtis0e209b02015-03-24 09:29:54 -07003219 SessionDescriptionInterface* offer = CreateOffer(options);
3220 SetLocalDescriptionWithoutError(offer);
3221
deadbeefcbecd352015-09-23 11:50:27 -07003222 EXPECT_NE(session_->voice_rtp_transport_channel(),
3223 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003224
deadbeefab9b2d12015-10-14 11:33:11 -07003225 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003226 SessionDescriptionInterface* answer =
3227 CreateRemoteAnswer(session_->local_description());
3228 SetRemoteDescriptionWithoutError(answer);
3229
3230 // This should lead to an audio-only call but isn't implemented
3231 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003232 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3233 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003234}
3235
deadbeefcbecd352015-09-23 11:50:27 -07003236// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003237TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3238 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003239 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003240 PeerConnectionInterface::RTCOfferAnswerOptions options;
3241 options.use_rtp_mux = true;
3242
3243 SessionDescriptionInterface* offer = CreateOffer(options);
3244 SetLocalDescriptionWithoutError(offer);
3245
deadbeefcbecd352015-09-23 11:50:27 -07003246 EXPECT_NE(session_->voice_rtp_transport_channel(),
3247 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003248
deadbeefab9b2d12015-10-14 11:33:11 -07003249 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003250
3251 // Remove BUNDLE from the answer.
3252 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3253 CreateRemoteAnswer(session_->local_description()));
3254 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3255 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3256 JsepSessionDescription* modified_answer =
3257 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3258 modified_answer->Initialize(answer_copy, "1", "1");
3259 SetRemoteDescriptionWithoutError(modified_answer); //
3260
deadbeefcbecd352015-09-23 11:50:27 -07003261 EXPECT_NE(session_->voice_rtp_transport_channel(),
3262 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263}
3264
Peter Thatcher4eddf182015-04-30 10:55:59 -07003265// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3266TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3267 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003268 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003269
3270 PeerConnectionInterface::RTCOfferAnswerOptions options;
3271 options.use_rtp_mux = true;
3272
3273 SessionDescriptionInterface* offer = CreateOffer(options);
3274 SetRemoteDescriptionWithoutError(offer);
3275
deadbeefcbecd352015-09-23 11:50:27 -07003276 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3277 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003278}
3279
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003280TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3281 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003282 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003283
3284 PeerConnectionInterface::RTCOfferAnswerOptions options;
3285 SessionDescriptionInterface* offer = CreateOffer(options);
3286 SetLocalDescriptionWithoutError(offer);
3287
deadbeefcbecd352015-09-23 11:50:27 -07003288 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3289 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003290
deadbeefab9b2d12015-10-14 11:33:11 -07003291 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003292 SessionDescriptionInterface* answer =
3293 CreateRemoteAnswer(session_->local_description());
3294 SetRemoteDescriptionWithoutError(answer);
3295
deadbeefcbecd352015-09-23 11:50:27 -07003296 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3297 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003298}
3299
3300TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3301 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003302 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003303
3304 PeerConnectionInterface::RTCOfferAnswerOptions options;
3305 SessionDescriptionInterface* offer = CreateOffer(options);
3306 SetLocalDescriptionWithoutError(offer);
3307
deadbeefcbecd352015-09-23 11:50:27 -07003308 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3309 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003310
deadbeefab9b2d12015-10-14 11:33:11 -07003311 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003312 SessionDescriptionInterface* answer =
3313 CreateRemoteAnswer(session_->local_description());
3314 SetRemoteDescriptionWithoutError(answer);
3315
deadbeefcbecd352015-09-23 11:50:27 -07003316 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3317 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003318}
3319
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003320// This test verifies that SetLocalDescription and SetRemoteDescription fails
3321// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3322TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003323 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003324 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003325
3326 PeerConnectionInterface::RTCOfferAnswerOptions options;
3327 options.use_rtp_mux = true;
3328
3329 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003330 std::string offer_str;
3331 offer->ToString(&offer_str);
3332 // Disable rtcp-mux
3333 const std::string rtcp_mux = "rtcp-mux";
3334 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003335 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003336 xrtcp_mux.c_str(), xrtcp_mux.length(),
3337 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003338 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003339 new JsepSessionDescription(JsepSessionDescription::kOffer);
3340 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003341 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003342 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003343 new JsepSessionDescription(JsepSessionDescription::kOffer);
3344 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003345 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003346 // Trying unmodified SDP.
3347 SetLocalDescriptionWithoutError(offer);
3348}
3349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003351 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003352 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353 CreateAndSetRemoteOfferAndLocalAnswer();
3354 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3355 ASSERT_TRUE(channel != NULL);
3356 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003357 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003358 double volume;
3359 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3360 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003361 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003362 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3363 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003364 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003365 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3366 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367}
3368
3369TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003370 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003371 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 CreateAndSetRemoteOfferAndLocalAnswer();
3373 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3374 ASSERT_TRUE(channel != NULL);
3375 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003376 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3378
3379 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003380 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003382 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003383 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003385 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003386 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003388 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003389 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003391 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003392 EXPECT_TRUE(renderer->sink() == NULL);
3393}
3394
3395TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003396 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003397 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003398 CreateAndSetRemoteOfferAndLocalAnswer();
3399 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3400 ASSERT_TRUE(channel != NULL);
3401 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003402 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003403
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003404 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003405 cricket::AudioOptions options;
3406 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3407 EXPECT_TRUE(renderer->sink() != NULL);
3408
3409 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3410 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3411 // SetSink(NULL) callback afterwards.
3412 renderer.reset();
3413
3414 // This will trigger SetSink(NULL) if no OnClose() callback.
3415 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416}
3417
3418TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003419 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003420 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 CreateAndSetRemoteOfferAndLocalAnswer();
3422 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3423 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003424 ASSERT_LT(0u, channel->sinks().size());
3425 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003427 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 cricket::FakeVideoRenderer renderer;
3429 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003430 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003432 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433}
3434
3435TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003436 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003437 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 CreateAndSetRemoteOfferAndLocalAnswer();
3439 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3440 ASSERT_TRUE(channel != NULL);
3441 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003442 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3444 cricket::VideoOptions* options = NULL;
3445 session_->SetVideoSend(send_ssrc, false, options);
3446 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3447 session_->SetVideoSend(send_ssrc, true, options);
3448 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3449}
3450
3451TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3452 TestCanInsertDtmf(false);
3453}
3454
3455TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3456 TestCanInsertDtmf(true);
3457}
3458
3459TEST_F(WebRtcSessionTest, InsertDtmf) {
3460 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003461 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003462 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 CreateAndSetRemoteOfferAndLocalAnswer();
3464 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3465 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3466
3467 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 const int expected_duration = 90;
3469 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3470 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3471 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3472
3473 // Verify
3474 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003475 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003477 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003479 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003481 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482}
3483
deadbeefd59daf82015-10-14 15:02:44 -07003484// This test verifies the |initial_offerer| flag when session initiates the
3485// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003487 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003488 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003489 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3491 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003492 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003494 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495}
3496
deadbeefd59daf82015-10-14 15:02:44 -07003497// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003499 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003500 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SessionDescriptionInterface* offer = CreateRemoteOffer();
3502 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003503 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003507 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508}
3509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3511TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003512 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003513 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003514 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003516 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 CreateRemoteAnswer(session_->local_description()));
3518
3519 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3520 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003521 JsepSessionDescription* modified_answer =
3522 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
3524 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3525 answer->session_id(),
3526 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003527 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
wu@webrtc.org4e393072014-04-07 17:04:35 +00003529 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 std::string sdp;
3531 EXPECT_TRUE(answer->ToString(&sdp));
3532 const std::string kAudioMid = "a=mid:audio";
3533 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003534 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 kAudioMidReplaceStr.c_str(),
3536 kAudioMidReplaceStr.length(),
3537 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003538 SessionDescriptionInterface* modified_answer1 =
3539 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003540 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541
wu@webrtc.org4e393072014-04-07 17:04:35 +00003542 // Different media types.
3543 EXPECT_TRUE(answer->ToString(&sdp));
3544 const std::string kAudioMline = "m=audio";
3545 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003546 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003547 kAudioMlineReplaceStr.c_str(),
3548 kAudioMlineReplaceStr.length(),
3549 &sdp);
3550 SessionDescriptionInterface* modified_answer2 =
3551 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3552 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3553
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 SetRemoteDescriptionWithoutError(answer.release());
3555}
3556
3557// Verifying remote offer and local answer have matching m-lines as per
3558// RFC 3264.
3559TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003560 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003561 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SessionDescriptionInterface* offer = CreateRemoteOffer();
3563 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003564 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565
3566 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3567 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003568 JsepSessionDescription* modified_answer =
3569 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570
3571 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3572 answer->session_id(),
3573 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003574 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 SetLocalDescriptionWithoutError(answer);
3576}
3577
3578// This test verifies that WebRtcSession does not start candidate allocation
3579// before SetLocalDescription is called.
3580TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003581 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003582 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 SessionDescriptionInterface* offer = CreateRemoteOffer();
3584 cricket::Candidate candidate;
3585 candidate.set_component(1);
3586 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3587 candidate);
3588 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3589 cricket::Candidate candidate1;
3590 candidate1.set_component(1);
3591 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3592 candidate1);
3593 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3594 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003595 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3596 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597
3598 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003599 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3601 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3602
wu@webrtc.org91053e72013-08-10 07:18:04 +00003603 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003604 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3606}
3607
3608// This test verifies that crypto parameter is updated in local session
3609// description as per security policy set in MediaSessionDescriptionFactory.
3610TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003611 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003612 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003613 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
3615 // Making sure SetLocalDescription correctly sets crypto value in
3616 // SessionDescription object after de-serialization of sdp string. The value
3617 // will be set as per MediaSessionDescriptionFactory.
3618 std::string offer_str;
3619 offer->ToString(&offer_str);
3620 SessionDescriptionInterface* jsep_offer_str =
3621 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3622 SetLocalDescriptionWithoutError(jsep_offer_str);
3623 EXPECT_TRUE(session_->voice_channel()->secure_required());
3624 EXPECT_TRUE(session_->video_channel()->secure_required());
3625}
3626
3627// This test verifies the crypto parameter when security is disabled.
3628TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003629 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003632 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633
3634 // Making sure SetLocalDescription correctly sets crypto value in
3635 // SessionDescription object after de-serialization of sdp string. The value
3636 // will be set as per MediaSessionDescriptionFactory.
3637 std::string offer_str;
3638 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003639 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3641 SetLocalDescriptionWithoutError(jsep_offer_str);
3642 EXPECT_FALSE(session_->voice_channel()->secure_required());
3643 EXPECT_FALSE(session_->video_channel()->secure_required());
3644}
3645
3646// This test verifies that an answer contains new ufrag and password if an offer
3647// with new ufrag and password is received.
3648TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003651 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003652 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 CreateRemoteOffer(options));
3654 SetRemoteDescriptionWithoutError(offer.release());
3655
deadbeefab9b2d12015-10-14 11:33:11 -07003656 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003657 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003658 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 SetLocalDescriptionWithoutError(answer.release());
3660
3661 // Receive an offer with new ufrag and password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003662 options.audio_transport_options.ice_restart = true;
3663 options.video_transport_options.ice_restart = true;
3664 options.data_transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003665 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003666 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 SetRemoteDescriptionWithoutError(updated_offer1.release());
3668
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671
3672 CompareIceUfragAndPassword(updated_answer1->description(),
3673 session_->local_description()->description(),
3674 false);
3675
3676 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003677}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003678
wu@webrtc.org91053e72013-08-10 07:18:04 +00003679// This test verifies that an answer contains old ufrag and password if an offer
3680// with old ufrag and password is received.
3681TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003682 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003683 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003684 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003685 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003686 CreateRemoteOffer(options));
3687 SetRemoteDescriptionWithoutError(offer.release());
3688
deadbeefab9b2d12015-10-14 11:33:11 -07003689 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003690 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003691 CreateAnswer(NULL));
3692 SetLocalDescriptionWithoutError(answer.release());
3693
3694 // Receive an offer without changed ufrag or password.
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003695 options.audio_transport_options.ice_restart = false;
3696 options.video_transport_options.ice_restart = false;
3697 options.data_transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003698 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003699 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003700 SetRemoteDescriptionWithoutError(updated_offer2.release());
3701
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003702 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003703 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704
3705 CompareIceUfragAndPassword(updated_answer2->description(),
3706 session_->local_description()->description(),
3707 true);
3708
3709 SetLocalDescriptionWithoutError(updated_answer2.release());
3710}
3711
3712TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003713 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003714 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003715 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716 const std::string session_id_orig = offer->session_id();
3717 const std::string session_version_orig = offer->session_version();
3718 SetLocalDescriptionWithoutError(offer);
3719
3720 video_channel_ = media_engine_->GetVideoChannel(0);
3721 video_channel_->set_fail_set_send_codecs(true);
3722
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003723 SessionDescriptionInterface* answer =
3724 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003725 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003726
3727 // Test that after a content error, setting any description will
3728 // result in an error.
3729 video_channel_->set_fail_set_send_codecs(false);
3730 answer = CreateRemoteAnswer(session_->local_description());
3731 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3732 offer = CreateRemoteOffer();
3733 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734}
3735
3736// Runs the loopback call test with BUNDLE and STUN disabled.
3737TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3738 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003739 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003740 cricket::PORTALLOCATOR_DISABLE_STUN |
3741 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742 TestLoopbackCall();
3743}
3744
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003745TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003746 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003747 cricket::PORTALLOCATOR_DISABLE_STUN |
3748 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3749 cricket::PORTALLOCATOR_DISABLE_RELAY);
3750
3751 // best connection is IPv6 since it has higher network preference.
3752 LoopbackNetworkConfiguration config;
3753 config.test_ipv6_network_ = true;
3754 config.best_connection_after_initial_ice_converged_ =
3755 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3756
3757 TestLoopbackCall(config);
3758}
3759
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003760// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003761TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003762 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3763 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003764 TestLoopbackCall();
3765}
3766
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003767TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3768 constraints_.reset(new FakeConstraints());
3769 constraints_->AddOptional(
3770 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003771 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003772
3773 SetLocalDescriptionWithDataChannel();
3774 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3775}
3776
Henrik Boström87713d02015-08-25 09:53:21 +02003777TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003778 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003779
3780 constraints_.reset(new FakeConstraints());
3781 constraints_->AddOptional(
3782 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003783 options_.disable_sctp_data_channels = false;
3784
Henrik Boström87713d02015-08-25 09:53:21 +02003785 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003786
3787 SetLocalDescriptionWithDataChannel();
3788 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3789}
3790
Henrik Boström87713d02015-08-25 09:53:21 +02003791TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003792 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003793
Henrik Boström87713d02015-08-25 09:53:21 +02003794 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003795
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003796 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003797 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003798 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3799}
3800
Henrik Boström87713d02015-08-25 09:53:21 +02003801TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003803 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003804 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003805
3806 // Create remote offer with SCTP.
3807 cricket::MediaSessionOptions options;
3808 options.data_channel_type = cricket::DCT_SCTP;
3809 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003810 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003811 SetRemoteDescriptionWithoutError(offer);
3812
3813 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003814 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003815 EXPECT_TRUE(answer != NULL);
3816 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3817 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003818}
3819
Henrik Boström87713d02015-08-25 09:53:21 +02003820TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003821 constraints_.reset(new FakeConstraints());
3822 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003823 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003824 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825
3826 SetLocalDescriptionWithDataChannel();
3827 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3828}
3829
Henrik Boström87713d02015-08-25 09:53:21 +02003830TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003831 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003832
Henrik Boström87713d02015-08-25 09:53:21 +02003833 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003834
3835 SetLocalDescriptionWithDataChannel();
3836 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3837}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003838
Henrik Boström87713d02015-08-25 09:53:21 +02003839TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003840 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003841 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003842 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003843
3844 SetLocalDescriptionWithDataChannel();
3845 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3846}
3847
Henrik Boström87713d02015-08-25 09:53:21 +02003848TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003849 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003850 const int new_send_port = 9998;
3851 const int new_recv_port = 7775;
3852
Henrik Boström87713d02015-08-25 09:53:21 +02003853 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003854 SetFactoryDtlsSrtp();
3855
3856 // By default, don't actually add the codecs to desc_factory_; they don't
3857 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3858 // let the session description get parsed. That'll get the proper codecs
3859 // into the stream.
3860 cricket::MediaSessionOptions options;
3861 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3862 "stream1", new_send_port, options);
3863
3864 // SetRemoteDescription will take the ownership of the offer.
3865 SetRemoteDescriptionWithoutError(offer);
3866
3867 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3868 new_recv_port, CreateAnswer(NULL));
3869 ASSERT_TRUE(answer != NULL);
3870
3871 // Now set the local description, which'll take ownership of the answer.
3872 SetLocalDescriptionWithoutError(answer);
3873
3874 // TEST PLAN: Set the port number to something new, set it in the SDP,
3875 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003876 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003877 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003878
3879 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3880 int portnum = -1;
3881 ASSERT_TRUE(ch != NULL);
3882 ASSERT_EQ(1UL, ch->send_codecs().size());
3883 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003884 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003885 ch->send_codecs()[0].name.c_str()));
3886 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3887 &portnum));
3888 EXPECT_EQ(new_send_port, portnum);
3889
3890 ASSERT_EQ(1UL, ch->recv_codecs().size());
3891 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003892 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003893 ch->recv_codecs()[0].name.c_str()));
3894 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3895 &portnum));
3896 EXPECT_EQ(new_recv_port, portnum);
3897}
3898
deadbeefab9b2d12015-10-14 11:33:11 -07003899// Verifies that when a session's DataChannel receives an OPEN message,
3900// WebRtcSession signals the DataChannel creation request with the expected
3901// config.
3902TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3903 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3904
3905 InitWithDtls(GetParam());
3906
3907 SetLocalDescriptionWithDataChannel();
3908 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3909
3910 webrtc::DataChannelInit config;
3911 config.id = 1;
3912 rtc::Buffer payload;
3913 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3914 cricket::ReceiveDataParams params;
3915 params.ssrc = config.id;
3916 params.type = cricket::DMT_CONTROL;
3917
3918 cricket::DataChannel* data_channel = session_->data_channel();
3919 data_channel->SignalDataReceived(data_channel, params, payload);
3920
3921 EXPECT_EQ("a", last_data_channel_label_);
3922 EXPECT_EQ(config.id, last_data_channel_config_.id);
3923 EXPECT_FALSE(last_data_channel_config_.negotiated);
3924 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3925 last_data_channel_config_.open_handshake_role);
3926}
3927
3928TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003929 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3930 FakeDtlsIdentityStore::GenerateCertificate();
3931
3932 PeerConnectionInterface::RTCConfiguration configuration;
3933 configuration.certificates.push_back(certificate);
3934 Init(nullptr, configuration);
3935 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3936
3937 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3938}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003939
Henrik Boström87713d02015-08-25 09:53:21 +02003940// Verifies that CreateOffer succeeds when CreateOffer is called before async
3941// identity generation is finished (even if a certificate is provided this is
3942// an async op).
3943TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3944 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3945 InitWithDtls(GetParam());
3946
Henrik Boströmd8281982015-08-27 10:12:24 +02003947 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003948 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003949 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3950
wu@webrtc.org91053e72013-08-10 07:18:04 +00003951 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003952 VerifyNoCryptoParams(offer->description(), true);
3953 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003954}
3955
3956// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003957// identity generation is finished (even if a certificate is provided this is
3958// an async op).
3959TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003960 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003961 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003962 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003963
3964 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003965 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003966 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003967 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003968 ASSERT_TRUE(offer.get() != NULL);
3969 SetRemoteDescriptionWithoutError(offer.release());
3970
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003971 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003972 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003973 VerifyNoCryptoParams(answer->description(), true);
3974 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003975}
3976
3977// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003978// identity generation is finished (even if a certificate is provided this is
3979// an async op).
3980TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003981 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003982 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003983
Henrik Boströmd8281982015-08-27 10:12:24 +02003984 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003985
3986 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003987 EXPECT_TRUE(offer != NULL);
3988}
3989
3990// Verifies that CreateOffer fails when CreateOffer is called after async
3991// identity generation fails.
3992TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003993 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003994 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003995
Henrik Boströmd8281982015-08-27 10:12:24 +02003996 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003997
3998 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003999 EXPECT_TRUE(offer == NULL);
4000}
4001
4002// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4003// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004004TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004005 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004006 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004007 VerifyMultipleAsyncCreateDescription(GetParam(),
4008 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004009}
4010
4011// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4012// before async identity generation fails.
4013TEST_F(WebRtcSessionTest,
4014 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004015 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004016 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4017 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004018}
4019
4020// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4021// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004022TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004023 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004024 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004025 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004026 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004027}
4028
4029// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4030// before async identity generation fails.
4031TEST_F(WebRtcSessionTest,
4032 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004033 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004034 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4035 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004036}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004037
4038// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4039// offer has no SDES crypto but only DTLS fingerprint.
4040TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4041 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004042 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004043 // Create a remote offer with secured transport disabled.
4044 cricket::MediaSessionOptions options;
4045 JsepSessionDescription* offer(CreateRemoteOffer(
4046 options, cricket::SEC_DISABLED));
4047 // Adds a DTLS fingerprint to the remote offer.
4048 cricket::SessionDescription* sdp = offer->description();
4049 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4050 ASSERT_TRUE(audio != NULL);
4051 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4052 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004053 rtc::SSLFingerprint::CreateFromRfc4572(
4054 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004055 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004056 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004057}
4058
wu@webrtc.orgde305012013-10-31 15:40:38 +00004059// This test verifies DSCP is properly applied on the media channels.
4060TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4061 constraints_.reset(new FakeConstraints());
4062 constraints_->AddOptional(
4063 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004064 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004065 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004066 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004067
4068 SetLocalDescriptionWithoutError(offer);
4069
4070 video_channel_ = media_engine_->GetVideoChannel(0);
4071 voice_channel_ = media_engine_->GetVoiceChannel(0);
4072
4073 ASSERT_TRUE(video_channel_ != NULL);
4074 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004075 const cricket::AudioOptions& audio_options = voice_channel_->options();
4076 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004077 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4078 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004079}
4080
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004081TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4082 constraints_.reset(new FakeConstraints());
4083 constraints_->AddOptional(
4084 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4085 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004086 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004087 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004088 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004089
4090 SetLocalDescriptionWithoutError(offer);
4091
4092 video_channel_ = media_engine_->GetVideoChannel(0);
4093
4094 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004095 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004096 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004097}
4098
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004099TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4100 constraints_.reset(new FakeConstraints());
4101 constraints_->AddOptional(
4102 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4103 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004104 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004105 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004106 SessionDescriptionInterface* offer = CreateOffer();
4107
4108 SetLocalDescriptionWithoutError(offer);
4109
4110 voice_channel_ = media_engine_->GetVoiceChannel(0);
4111
4112 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004113 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004114 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004115}
4116
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004117// Tests that we can renegotiate new media content with ICE candidates in the
4118// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004119TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004120 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004121 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004122 SetFactoryDtlsSrtp();
4123
deadbeefab9b2d12015-10-14 11:33:11 -07004124 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004125 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004126 SetLocalDescriptionWithoutError(offer);
4127
4128 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4129 SetRemoteDescriptionWithoutError(answer);
4130
4131 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004132 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004133 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4134
4135 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004136 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004137 candidate1.set_component(1);
4138 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4139 candidate1);
4140 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4141 SetRemoteDescriptionWithoutError(offer);
4142
4143 answer = CreateAnswer(NULL);
4144 SetLocalDescriptionWithoutError(answer);
4145}
4146
4147// Tests that we can renegotiate new media content with ICE candidates separated
4148// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004149TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004150 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004151 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004152 SetFactoryDtlsSrtp();
4153
deadbeefab9b2d12015-10-14 11:33:11 -07004154 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004155 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004156 SetLocalDescriptionWithoutError(offer);
4157
4158 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4159 SetRemoteDescriptionWithoutError(answer);
4160
4161 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004162 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004163 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4164 SetRemoteDescriptionWithoutError(offer);
4165
4166 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004167 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004168 candidate1.set_component(1);
4169 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4170 candidate1);
4171 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4172
4173 answer = CreateAnswer(NULL);
4174 SetLocalDescriptionWithoutError(answer);
4175}
honghaiz7f777492016-02-02 21:54:01 -08004176
4177// Flaky on Win and Mac only. See webrtc:4943
4178#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4179#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4180#else
4181#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4182#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004183// Tests that RTX codec is removed from the answer when it isn't supported
4184// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004185TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004186 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004187 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004188 std::string offer_sdp(kSdpWithRtx);
4189
4190 SessionDescriptionInterface* offer =
4191 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4192 EXPECT_TRUE(offer->ToString(&offer_sdp));
4193
4194 // Offer SDP contains the RTX codec.
4195 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4196 SetRemoteDescriptionWithoutError(offer);
4197
4198 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4199 std::string answer_sdp;
4200 answer->ToString(&answer_sdp);
4201 // Answer SDP removes the unsupported RTX codec.
4202 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4203 SetLocalDescriptionWithoutError(answer);
4204}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004205
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004206// This verifies that the voice channel after bundle has both options from video
4207// and voice channels.
4208TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4209 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004210 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004211
4212 PeerConnectionInterface::RTCOfferAnswerOptions options;
4213 options.use_rtp_mux = true;
4214
4215 SessionDescriptionInterface* offer = CreateOffer(options);
4216 SetLocalDescriptionWithoutError(offer);
4217
4218 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4219 rtc::Socket::Option::OPT_SNDBUF, 4000);
4220
4221 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4222 rtc::Socket::Option::OPT_RCVBUF, 8000);
4223
4224 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004225 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004226 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4227 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004228 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004229 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4230
deadbeefcbecd352015-09-23 11:50:27 -07004231 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004232 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4233 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004234 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004235 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4236
deadbeefcbecd352015-09-23 11:50:27 -07004237 EXPECT_NE(session_->voice_rtp_transport_channel(),
4238 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004239
deadbeefab9b2d12015-10-14 11:33:11 -07004240 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004241 SessionDescriptionInterface* answer =
4242 CreateRemoteAnswer(session_->local_description());
4243 SetRemoteDescriptionWithoutError(answer);
4244
deadbeefcbecd352015-09-23 11:50:27 -07004245 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004246 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4247 EXPECT_EQ(4000, option_val);
4248
deadbeefcbecd352015-09-23 11:50:27 -07004249 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004250 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4251 EXPECT_EQ(8000, option_val);
4252}
4253
tommi0f620f42015-07-09 03:25:02 -07004254// Test creating a session, request multiple offers, destroy the session
4255// and make sure we got success/failure callbacks for all of the requests.
4256// Background: crbug.com/507307
4257TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4258 Init();
4259
4260 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4261 PeerConnectionInterface::RTCOfferAnswerOptions options;
4262 options.offer_to_receive_audio =
4263 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004264 cricket::MediaSessionOptions session_options;
4265 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004266
4267 for (auto& o : observers) {
4268 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004269 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004270 }
4271
4272 session_.reset();
4273
tommi0f620f42015-07-09 03:25:02 -07004274 for (auto& o : observers) {
4275 // We expect to have received a notification now even if the session was
4276 // terminated. The offer creation may or may not have succeeded, but we
4277 // must have received a notification which, so the only invalid state
4278 // is kInit.
4279 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4280 }
4281}
4282
stefanc1aeaf02015-10-15 07:26:07 -07004283TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4284 TestPacketOptions();
4285}
4286
deadbeef057ecf02016-01-20 14:30:43 -08004287// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4288// is destroyed.
4289TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4290 Init();
4291 session_.reset();
4292 EXPECT_TRUE(session_destroyed_);
4293}
4294
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004295// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4296// currently fails because upon disconnection and reconnection OnIceComplete is
4297// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004298
deadbeefcbecd352015-09-23 11:50:27 -07004299INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4300 WebRtcSessionTest,
4301 testing::Values(ALREADY_GENERATED,
4302 DTLS_IDENTITY_STORE));