blob: 4cb6cc441e381692e93777138ed4c11fa5dd431e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/test/fakedtlsidentitystore.h"
23#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/media/base/fakemediaengine.h"
39#include "webrtc/media/base/fakevideorenderer.h"
40#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080042#include "webrtc/p2p/base/stunserver.h"
43#include "webrtc/p2p/base/teststunserver.h"
44#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/base/transportchannel.h"
46#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010047#include "webrtc/pc/channelmanager.h"
48#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
51 if (!(feature())) { \
52 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058using rtc::SocketAddress;
59using rtc::scoped_ptr;
60using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000062using webrtc::CreateSessionDescriptionObserver;
63using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070064using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020065using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070066using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070068using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using webrtc::JsepIceCandidate;
70using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000071using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::PeerConnectionInterface;
73using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070074using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000076using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000077using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000078using webrtc::kCreateChannelFailed;
79using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000082using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000083using webrtc::kSdpWithoutDtlsFingerprint;
84using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000086using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000087using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000089typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
90
wu@webrtc.org364f2042013-11-20 21:49:41 +000091static const int kClientAddrPort = 0;
92static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000093static const char kClientIPv6AddrHost1[] =
94 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000095static const char kClientAddrHost2[] = "22.22.22.22";
96static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000097static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
98static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000099static const char kTurnUsername[] = "test";
100static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
102static const char kSessionVersion[] = "1";
103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104// Media index of candidates belonging to the first media content.
105static const int kMediaContentIndex0 = 0;
106static const char kMediaContentName0[] = "audio";
107
108// Media index of candidates belonging to the second media content.
109static const int kMediaContentIndex1 = 1;
110static const char kMediaContentName1[] = "video";
111
112static const int kIceCandidatesTimeout = 10000;
113
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000114static const char kFakeDtlsFingerprint[] =
115 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
116 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
117
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000118static const char kTooLongIceUfragPwd[] =
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
123
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000124static const char kSdpWithRtx[] =
125 "v=0\r\n"
126 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
129 "a=msid-semantic: WMS stream1\r\n"
130 "m=video 9 RTP/SAVPF 0 96\r\n"
131 "c=IN IP4 0.0.0.0\r\n"
132 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
133 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
134 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
135 "a=mid:video\r\n"
136 "a=sendrecv\r\n"
137 "a=rtcp-mux\r\n"
138 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
139 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
140 "a=rtpmap:0 fake_video_codec/90000\r\n"
141 "a=rtpmap:96 rtx/90000\r\n"
142 "a=fmtp:96 apt=0\r\n";
143
deadbeefab9b2d12015-10-14 11:33:11 -0700144static const char kStream1[] = "stream1";
145static const char kVideoTrack1[] = "video1";
146static const char kAudioTrack1[] = "audio1";
147
148static const char kStream2[] = "stream2";
149static const char kVideoTrack2[] = "video2";
150static const char kAudioTrack2[] = "audio2";
151
Henrik Boström87713d02015-08-25 09:53:21 +0200152enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
153
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154class MockIceObserver : public webrtc::IceObserver {
155 public:
156 MockIceObserver()
157 : oncandidatesready_(false),
158 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
159 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
160 }
161
perkjdfb769d2016-02-09 03:09:43 -0800162 void OnIceConnectionChange(
163 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 ice_connection_state_ = new_state;
165 }
perkjdfb769d2016-02-09 03:09:43 -0800166 void OnIceGatheringChange(
167 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 // We can never transition back to "new".
169 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
170 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800171 oncandidatesready_ =
172 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174
175 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800176 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000177 switch (candidate->sdp_mline_index()) {
178 case kMediaContentIndex0:
179 mline_0_candidates_.push_back(candidate->candidate());
180 break;
181 case kMediaContentIndex1:
182 mline_1_candidates_.push_back(candidate->candidate());
183 break;
184 default:
185 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // The ICE gathering state should always be Gathering when a candidate is
189 // received (or possibly Completed in the case of the final candidate).
190 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
191 }
192
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700193 // Some local candidates are removed.
194 void OnIceCandidatesRemoved(
195 const std::vector<cricket::Candidate>& candidates) {
196 num_candidates_removed_ += candidates.size();
197 }
198
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 bool oncandidatesready_;
200 std::vector<cricket::Candidate> mline_0_candidates_;
201 std::vector<cricket::Candidate> mline_1_candidates_;
202 PeerConnectionInterface::IceConnectionState ice_connection_state_;
203 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700204 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205};
206
207class WebRtcSessionForTest : public webrtc::WebRtcSession {
208 public:
stefanc1aeaf02015-10-15 07:26:07 -0700209 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000210 rtc::Thread* signaling_thread,
211 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700213 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700214 : WebRtcSession(media_controller,
215 signaling_thread,
216 worker_thread,
217 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 RegisterIceObserver(ice_observer);
219 }
220 virtual ~WebRtcSessionForTest() {}
221
deadbeefcbecd352015-09-23 11:50:27 -0700222 // Note that these methods are only safe to use if the signaling thread
223 // is the same as the worker thread
224 cricket::TransportChannel* voice_rtp_transport_channel() {
225 return rtp_transport_channel(voice_channel());
226 }
227
228 cricket::TransportChannel* voice_rtcp_transport_channel() {
229 return rtcp_transport_channel(voice_channel());
230 }
231
232 cricket::TransportChannel* video_rtp_transport_channel() {
233 return rtp_transport_channel(video_channel());
234 }
235
236 cricket::TransportChannel* video_rtcp_transport_channel() {
237 return rtcp_transport_channel(video_channel());
238 }
239
240 cricket::TransportChannel* data_rtp_transport_channel() {
241 return rtp_transport_channel(data_channel());
242 }
243
244 cricket::TransportChannel* data_rtcp_transport_channel() {
245 return rtcp_transport_channel(data_channel());
246 }
247
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 using webrtc::WebRtcSession::SetAudioPlayout;
249 using webrtc::WebRtcSession::SetAudioSend;
nisse2ded9b12016-04-08 02:23:55 -0700250 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 using webrtc::WebRtcSession::SetVideoPlayout;
252 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700253
254 private:
255 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
256 if (!ch) {
257 return nullptr;
258 }
259 return ch->transport_channel();
260 }
261
262 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
263 if (!ch) {
264 return nullptr;
265 }
266 return ch->rtcp_transport_channel();
267 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268};
269
wu@webrtc.org91053e72013-08-10 07:18:04 +0000270class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000271 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000273 enum State {
274 kInit,
275 kFailed,
276 kSucceeded,
277 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000278 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000279
280 // CreateSessionDescriptionObserver implementation.
281 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000282 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283 state_ = kSucceeded;
284 }
285 virtual void OnFailure(const std::string& error) {
286 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 }
288
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000289 SessionDescriptionInterface* description() { return description_.get(); }
290
291 SessionDescriptionInterface* ReleaseDescription() {
292 return description_.release();
293 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
wu@webrtc.org91053e72013-08-10 07:18:04 +0000295 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296
wu@webrtc.org91053e72013-08-10 07:18:04 +0000297 protected:
298 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299
300 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000301 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000302 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303};
304
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800305class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000306 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800307 FakeAudioSource() : sink_(NULL) {}
308 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 if (sink_)
310 sink_->OnClose();
311 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000313 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800315 const cricket::AudioSource::Sink* sink() const { return sink_; }
316
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800318 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319};
320
Henrik Boström87713d02015-08-25 09:53:21 +0200321class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700322 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
323 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 protected:
325 // TODO Investigate why ChannelManager crashes, if it's created
326 // after stun_server.
327 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700328 : media_engine_(new cricket::FakeMediaEngine()),
329 data_engine_(new cricket::FakeDataEngine()),
330 channel_manager_(
331 new cricket::ChannelManager(media_engine_,
332 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700333 rtc::Thread::Current())),
334 fake_call_(webrtc::Call::Config()),
335 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800336 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
337 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700338 channel_manager_.get())),
339 tdesc_factory_(new cricket::TransportDescriptionFactory()),
340 desc_factory_(
341 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
342 tdesc_factory_.get())),
343 pss_(new rtc::PhysicalSocketServer),
344 vss_(new rtc::VirtualSocketServer(pss_.get())),
345 fss_(new rtc::FirewallSocketServer(vss_.get())),
346 ss_scope_(fss_.get()),
347 stun_socket_addr_(
348 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
349 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
350 stun_socket_addr_)),
351 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
352 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000353 cricket::ServerAddresses stun_servers;
354 stun_servers.insert(stun_socket_addr_);
355 allocator_.reset(new cricket::BasicPortAllocator(
356 &network_manager_,
357 stun_servers,
358 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000359 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700360 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 EXPECT_TRUE(channel_manager_->Init());
362 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000363 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 }
365
366 void AddInterface(const SocketAddress& addr) {
367 network_manager_.AddInterface(addr);
368 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700369 void RemoveInterface(const SocketAddress& addr) {
370 network_manager_.RemoveInterface(addr);
371 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372
Henrik Boström87713d02015-08-25 09:53:21 +0200373 // If |dtls_identity_store| != null or |rtc_configuration| contains
374 // |certificates| then DTLS will be enabled unless explicitly disabled by
375 // |rtc_configuration| options. When DTLS is enabled a certificate will be
376 // used if provided, otherwise one will be generated using the
377 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000378 void Init(
htaa2a49d92016-03-04 02:51:39 -0800379 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 ASSERT_TRUE(session_.get() == NULL);
381 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700382 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700383 allocator_.get(), &observer_));
384 session_->SignalDataChannelOpenMessage.connect(
385 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800386 session_->GetOnDestroyedSignal()->connect(
387 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388
389 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
390 observer_.ice_connection_state_);
391 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
392 observer_.ice_gathering_state_);
393
htaa2a49d92016-03-04 02:51:39 -0800394 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
395 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700396 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 }
398
deadbeefab9b2d12015-10-14 11:33:11 -0700399 void OnDataChannelOpenMessage(const std::string& label,
400 const InternalDataChannelInit& config) {
401 last_data_channel_label_ = label;
402 last_data_channel_config_ = config;
403 }
404
deadbeef057ecf02016-01-20 14:30:43 -0800405 void OnSessionDestroyed() { session_destroyed_ = true; }
406
htaa2a49d92016-03-04 02:51:39 -0800407 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000408
409 void InitWithIceTransport(
410 PeerConnectionInterface::IceTransportsType ice_transport_type) {
htaa2a49d92016-03-04 02:51:39 -0800411 configuration_.type = ice_transport_type;
412 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 }
414
415 void InitWithBundlePolicy(
416 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800417 configuration_.bundle_policy = bundle_policy;
418 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700419 }
420
421 void InitWithRtcpMuxPolicy(
422 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
423 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800424 configuration_.rtcp_mux_policy = rtcp_mux_policy;
425 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000426 }
427
Henrik Boström87713d02015-08-25 09:53:21 +0200428 // Successfully init with DTLS; with a certificate generated and supplied or
429 // with a store that generates it for us.
430 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
431 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200432 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800433 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200434 FakeDtlsIdentityStore::GenerateCertificate());
435 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
436 dtls_identity_store.reset(new FakeDtlsIdentityStore());
437 dtls_identity_store->set_should_fail(false);
438 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700439 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200440 }
htaa2a49d92016-03-04 02:51:39 -0800441 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200442 }
443
444 // Init with DTLS with a store that will fail to generate a certificate.
445 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200446 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
447 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200448 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800449 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000450 }
451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 void InitWithDtmfCodec() {
453 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700454 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
455 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 std::vector<cricket::AudioCodec> codecs;
457 codecs.push_back(kTelephoneEventCodec);
458 media_engine_->SetAudioCodecs(codecs);
459 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000460 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 }
462
deadbeefab9b2d12015-10-14 11:33:11 -0700463 void SendAudioVideoStream1() {
464 send_stream_1_ = true;
465 send_stream_2_ = false;
466 send_audio_ = true;
467 send_video_ = true;
468 }
469
470 void SendAudioVideoStream2() {
471 send_stream_1_ = false;
472 send_stream_2_ = true;
473 send_audio_ = true;
474 send_video_ = true;
475 }
476
477 void SendAudioVideoStream1And2() {
478 send_stream_1_ = true;
479 send_stream_2_ = true;
480 send_audio_ = true;
481 send_video_ = true;
482 }
483
484 void SendNothing() {
485 send_stream_1_ = false;
486 send_stream_2_ = false;
487 send_audio_ = false;
488 send_video_ = false;
489 }
490
491 void SendAudioOnlyStream2() {
492 send_stream_1_ = false;
493 send_stream_2_ = true;
494 send_audio_ = true;
495 send_video_ = false;
496 }
497
498 void SendVideoOnlyStream2() {
499 send_stream_1_ = false;
500 send_stream_2_ = true;
501 send_audio_ = false;
502 send_video_ = true;
503 }
504
505 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
506 if (send_stream_1_ && send_audio_) {
507 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
508 kStream1);
509 }
510 if (send_stream_1_ && send_video_) {
511 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
512 kStream1);
513 }
514 if (send_stream_2_ && send_audio_) {
515 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
516 kStream2);
517 }
518 if (send_stream_2_ && send_video_) {
519 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
520 kStream2);
521 }
522 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
523 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
524 data_channel_->label(),
525 data_channel_->label());
526 }
527 }
528
529 void GetOptionsForOffer(
530 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
531 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800532 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700533
deadbeefc80741f2015-10-22 13:14:45 -0700534 AddStreamsToOptions(session_options);
535 if (rtc_options.offer_to_receive_audio ==
536 RTCOfferAnswerOptions::kUndefined) {
537 session_options->recv_audio =
538 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
539 }
540 if (rtc_options.offer_to_receive_video ==
541 RTCOfferAnswerOptions::kUndefined) {
542 session_options->recv_video =
543 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
544 }
545 session_options->bundle_enabled =
546 session_options->bundle_enabled &&
547 (session_options->has_audio() || session_options->has_video() ||
548 session_options->has_data());
549
deadbeefab9b2d12015-10-14 11:33:11 -0700550 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
551 session_options->data_channel_type = cricket::DCT_SCTP;
552 }
553 }
554
htaa2a49d92016-03-04 02:51:39 -0800555 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
556 // ParseConstraintsForAnswer is used to set some defaults.
557 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700558
deadbeefc80741f2015-10-22 13:14:45 -0700559 AddStreamsToOptions(session_options);
560 session_options->bundle_enabled =
561 session_options->bundle_enabled &&
562 (session_options->has_audio() || session_options->has_video() ||
563 session_options->has_data());
564
deadbeefab9b2d12015-10-14 11:33:11 -0700565 if (session_->data_channel_type() == cricket::DCT_SCTP) {
566 session_options->data_channel_type = cricket::DCT_SCTP;
567 }
568 }
569
570 // Creates a local offer and applies it. Starts ICE.
571 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 // to decide which streams to create.
573 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000574 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 SetLocalDescriptionWithoutError(offer);
576 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
577 observer_.ice_gathering_state_,
578 kIceCandidatesTimeout);
579 }
580
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000581 SessionDescriptionInterface* CreateOffer() {
582 PeerConnectionInterface::RTCOfferAnswerOptions options;
583 options.offer_to_receive_audio =
584 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
585
586 return CreateOffer(options);
587 }
588
wu@webrtc.org91053e72013-08-10 07:18:04 +0000589 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800590 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000592 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700593 cricket::MediaSessionOptions session_options;
594 GetOptionsForOffer(options, &session_options);
595 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000596 EXPECT_TRUE_WAIT(
597 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000598 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000599 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000600 }
601
602 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800603 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000604 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000605 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800606 cricket::MediaSessionOptions session_options = options;
607 GetOptionsForAnswer(&session_options);
608 // Overwrite recv_audio and recv_video with passed-in values.
609 session_options.recv_video = options.recv_video;
610 session_options.recv_audio = options.recv_audio;
611 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 EXPECT_TRUE_WAIT(
613 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000614 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000615 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 }
617
htaa2a49d92016-03-04 02:51:39 -0800618 SessionDescriptionInterface* CreateAnswer() {
619 cricket::MediaSessionOptions options;
620 options.recv_video = true;
621 options.recv_audio = true;
622 return CreateAnswer(options);
623 }
624
wu@webrtc.org364f2042013-11-20 21:49:41 +0000625 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 return (session_->voice_channel() != NULL &&
627 session_->video_channel() != NULL);
628 }
629
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
631 ASSERT_TRUE(session_.get() != NULL);
632 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
633 ASSERT_TRUE(content != NULL);
634 const cricket::AudioContentDescription* audio_content =
635 static_cast<const cricket::AudioContentDescription*>(
636 content->description);
637 ASSERT_TRUE(audio_content != NULL);
638 ASSERT_EQ(1U, audio_content->cryptos().size());
639 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
640 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
641 audio_content->cryptos()[0].cipher_suite);
642 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
643 audio_content->protocol());
644
645 content = cricket::GetFirstVideoContent(sdp);
646 ASSERT_TRUE(content != NULL);
647 const cricket::VideoContentDescription* video_content =
648 static_cast<const cricket::VideoContentDescription*>(
649 content->description);
650 ASSERT_TRUE(video_content != NULL);
651 ASSERT_EQ(1U, video_content->cryptos().size());
652 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
653 video_content->cryptos()[0].cipher_suite);
654 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
655 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
656 video_content->protocol());
657 }
658
659 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
660 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
661 ASSERT_TRUE(content != NULL);
662 const cricket::AudioContentDescription* audio_content =
663 static_cast<const cricket::AudioContentDescription*>(
664 content->description);
665 ASSERT_TRUE(audio_content != NULL);
666 ASSERT_EQ(0U, audio_content->cryptos().size());
667
668 content = cricket::GetFirstVideoContent(sdp);
669 ASSERT_TRUE(content != NULL);
670 const cricket::VideoContentDescription* video_content =
671 static_cast<const cricket::VideoContentDescription*>(
672 content->description);
673 ASSERT_TRUE(video_content != NULL);
674 ASSERT_EQ(0U, video_content->cryptos().size());
675
676 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700677 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700679 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 video_content->protocol());
681 } else {
682 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
683 audio_content->protocol());
684 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
685 video_content->protocol());
686 }
687 }
688
689 // Set the internal fake description factories to do DTLS-SRTP.
690 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000691 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000693 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200694 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800695 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700696 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800697 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
699 }
700
701 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
702 bool expected) {
703 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
704 ASSERT_TRUE(audio != NULL);
705 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 const TransportInfo* video = sdp->GetTransportInfoByName("video");
707 ASSERT_TRUE(video != NULL);
708 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 }
710
711 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000712 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000714 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000715 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000717 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000719 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
720 offer);
htaa2a49d92016-03-04 02:51:39 -0800721 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 // Answer should be NULL as no crypto params in offer.
723 ASSERT_TRUE(answer == NULL);
724 }
725
726 void VerifyAnswerFromCryptoOffer() {
727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000728 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 options.bundle_enabled = true;
730 scoped_ptr<JsepSessionDescription> offer(
731 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
732 ASSERT_TRUE(offer.get() != NULL);
733 VerifyCryptoParams(offer->description());
734 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -0800735 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 ASSERT_TRUE(answer.get() != NULL);
737 VerifyCryptoParams(answer->description());
738 }
739
deadbeef0ed85b22016-02-23 17:24:52 -0800740 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
741 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800743 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 }
745
746 const cricket::ContentInfos& contents = desc1->contents();
747 cricket::ContentInfos::const_iterator it = contents.begin();
748
749 for (; it != contents.end(); ++it) {
750 const cricket::TransportDescription* transport_desc1 =
751 desc1->GetTransportDescriptionByName(it->name);
752 const cricket::TransportDescription* transport_desc2 =
753 desc2->GetTransportDescriptionByName(it->name);
754 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800755 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 }
757 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
758 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800759 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 }
761 }
deadbeef0ed85b22016-02-23 17:24:52 -0800762 return true;
763 }
764
765 // Compares ufrag/password only for the specified |media_type|.
766 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
767 const cricket::SessionDescription* desc2,
768 cricket::MediaType media_type) {
769 if (desc1->contents().size() != desc2->contents().size()) {
770 return false;
771 }
772
773 const cricket::ContentInfo* cinfo =
774 cricket::GetFirstMediaContent(desc1->contents(), media_type);
775 const cricket::TransportDescription* transport_desc1 =
776 desc1->GetTransportDescriptionByName(cinfo->name);
777 const cricket::TransportDescription* transport_desc2 =
778 desc2->GetTransportDescriptionByName(cinfo->name);
779 if (!transport_desc1 || !transport_desc2) {
780 return false;
781 }
782 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
783 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
784 return false;
785 }
786 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000788
789 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
790 std::string *sdp) {
791 const cricket::SessionDescription* desc = current_desc->description();
792 EXPECT_TRUE(current_desc->ToString(sdp));
793
794 const cricket::ContentInfos& contents = desc->contents();
795 cricket::ContentInfos::const_iterator it = contents.begin();
796 // Replace ufrag and pwd lines with empty strings.
797 for (; it != contents.end(); ++it) {
798 const cricket::TransportDescription* transport_desc =
799 desc->GetTransportDescriptionByName(it->name);
800 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
801 + "\r\n";
802 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
803 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000804 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000805 "", 0,
806 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000808 "", 0,
809 sdp);
810 }
811 }
812
deadbeef0ed85b22016-02-23 17:24:52 -0800813 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
814 const std::string& ufrag,
815 const std::string& pwd) {
816 cricket::SessionDescription* desc = current_desc->description();
817 for (TransportInfo& transport_info : desc->transport_infos()) {
818 cricket::TransportDescription& transport_desc =
819 transport_info.description;
820 transport_desc.ice_ufrag = ufrag;
821 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000822 }
823 }
824
deadbeef0ed85b22016-02-23 17:24:52 -0800825 // Sets ufrag/pwd for specified |media_type|.
826 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
827 cricket::MediaType media_type,
828 const std::string& ufrag,
829 const std::string& pwd) {
830 cricket::SessionDescription* desc = current_desc->description();
831 const cricket::ContentInfo* cinfo =
832 cricket::GetFirstMediaContent(desc->contents(), media_type);
833 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
834 cricket::TransportDescription* transport_desc =
835 &transport_info->description;
836 transport_desc->ice_ufrag = ufrag;
837 transport_desc->ice_pwd = pwd;
838 }
839
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 // Creates a remote offer and and applies it as a remote description,
841 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700842 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // to decide which local and remote streams to create.
844 void CreateAndSetRemoteOfferAndLocalAnswer() {
845 SessionDescriptionInterface* offer = CreateRemoteOffer();
846 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800847 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 SetLocalDescriptionWithoutError(answer);
849 }
850 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
851 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700852 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 }
854 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700855 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 SetLocalDescriptionWithoutError(desc);
857 EXPECT_EQ(expected_state, session_->state());
858 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 void SetLocalDescriptionExpectError(const std::string& action,
860 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 SessionDescriptionInterface* desc) {
862 std::string error;
863 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000864 std::string sdp_type = "local ";
865 sdp_type.append(action);
866 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_NE(std::string::npos, error.find(expected_error));
868 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000869 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
870 SessionDescriptionInterface* desc) {
871 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
872 expected_error, desc);
873 }
874 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
875 SessionDescriptionInterface* desc) {
876 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
877 expected_error, desc);
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
880 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
881 }
882 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700883 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 SetRemoteDescriptionWithoutError(desc);
885 EXPECT_EQ(expected_state, session_->state());
886 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000887 void SetRemoteDescriptionExpectError(const std::string& action,
888 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 SessionDescriptionInterface* desc) {
890 std::string error;
891 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000892 std::string sdp_type = "remote ";
893 sdp_type.append(action);
894 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_NE(std::string::npos, error.find(expected_error));
896 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000897 void SetRemoteDescriptionOfferExpectError(
898 const std::string& expected_error, SessionDescriptionInterface* desc) {
899 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
900 expected_error, desc);
901 }
902 void SetRemoteDescriptionPranswerExpectError(
903 const std::string& expected_error, SessionDescriptionInterface* desc) {
904 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
905 expected_error, desc);
906 }
907 void SetRemoteDescriptionAnswerExpectError(
908 const std::string& expected_error, SessionDescriptionInterface* desc) {
909 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
910 expected_error, desc);
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
913 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
914 SessionDescriptionInterface** nocrypto_answer) {
915 // Create a SDP without Crypto.
916 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000917 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 options.bundle_enabled = true;
919 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
920 ASSERT_TRUE(*offer != NULL);
921 VerifyCryptoParams((*offer)->description());
922
923 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
924 cricket::SEC_DISABLED);
925 EXPECT_TRUE(*nocrypto_answer != NULL);
926 }
927
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000928 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
929 SessionDescriptionInterface** nodtls_answer) {
930 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000931 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000932 options.bundle_enabled = true;
933
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000934 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000935 CreateRemoteOffer(options, cricket::SEC_ENABLED));
936
937 *nodtls_answer =
938 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
939 EXPECT_TRUE(*nodtls_answer != NULL);
940 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
941 VerifyCryptoParams((*nodtls_answer)->description());
942
943 SetFactoryDtlsSrtp();
944 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
945 ASSERT_TRUE(*offer != NULL);
946 VerifyFingerprintStatus((*offer)->description(), true);
947 VerifyCryptoParams((*offer)->description());
948 }
949
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 JsepSessionDescription* CreateRemoteOfferWithVersion(
951 cricket::MediaSessionOptions options,
952 cricket::SecurePolicy secure_policy,
953 const std::string& session_version,
954 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000955 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 const cricket::SessionDescription* cricket_desc = NULL;
957 if (current_desc) {
958 cricket_desc = current_desc->description();
959 session_id = current_desc->session_id();
960 }
961
962 desc_factory_->set_secure(secure_policy);
963 JsepSessionDescription* offer(
964 new JsepSessionDescription(JsepSessionDescription::kOffer));
965 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
966 session_id, session_version)) {
967 delete offer;
968 offer = NULL;
969 }
970 return offer;
971 }
972 JsepSessionDescription* CreateRemoteOffer(
973 cricket::MediaSessionOptions options) {
974 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
975 kSessionVersion, NULL);
976 }
977 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000978 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
979 return CreateRemoteOfferWithVersion(
980 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 }
982 JsepSessionDescription* CreateRemoteOffer(
983 cricket::MediaSessionOptions options,
984 const SessionDescriptionInterface* current_desc) {
985 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
986 kSessionVersion, current_desc);
987 }
988
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000989 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
990 const char* sctp_stream_name, int new_port,
991 cricket::MediaSessionOptions options) {
992 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000993 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
994 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000995 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
996 }
997
998 // Takes ownership of offer_basis (and deletes it).
999 JsepSessionDescription* ChangeSDPSctpPort(
1000 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1001 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1002 // SessionDescription from the mutated string.
1003 const char* default_port_str = "5000";
1004 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001005 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001006 std::string offer_str;
1007 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001008 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001009 new_port_str, strlen(new_port_str),
1010 &offer_str);
1011 JsepSessionDescription* offer = new JsepSessionDescription(
1012 offer_basis->type());
1013 delete offer_basis;
1014 offer->Initialize(offer_str, NULL);
1015 return offer;
1016 }
1017
deadbeefab9b2d12015-10-14 11:33:11 -07001018 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // before this function to decide which streams to create.
1020 JsepSessionDescription* CreateRemoteOffer() {
1021 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001022 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 return CreateRemoteOffer(options, session_->remote_description());
1024 }
1025
1026 JsepSessionDescription* CreateRemoteAnswer(
1027 const SessionDescriptionInterface* offer,
1028 cricket::MediaSessionOptions options,
1029 cricket::SecurePolicy policy) {
1030 desc_factory_->set_secure(policy);
1031 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001032 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 JsepSessionDescription* answer(
1034 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1035 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1036 options, NULL),
1037 session_id, kSessionVersion)) {
1038 delete answer;
1039 answer = NULL;
1040 }
1041 return answer;
1042 }
1043
1044 JsepSessionDescription* CreateRemoteAnswer(
1045 const SessionDescriptionInterface* offer,
1046 cricket::MediaSessionOptions options) {
1047 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1048 }
1049
deadbeefab9b2d12015-10-14 11:33:11 -07001050 // Creates an answer session description.
1051 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 // to decide which streams to create.
1053 JsepSessionDescription* CreateRemoteAnswer(
1054 const SessionDescriptionInterface* offer) {
1055 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001056 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1058 }
1059
1060 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001062 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001063 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001064
1065 PeerConnectionInterface::RTCOfferAnswerOptions options;
1066 options.use_rtp_mux = bundle;
1067
1068 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1070 // and answer.
1071 SetLocalDescriptionWithoutError(offer);
1072
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001073 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001074 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 std::string sdp;
1076 EXPECT_TRUE(answer->ToString(&sdp));
1077
1078 size_t expected_candidate_num = 2;
1079 if (!rtcp_mux) {
1080 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1081 // for rtp and rtcp.
1082 expected_candidate_num = 4;
1083 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 const std::string kRtcpMux = "a=rtcp-mux";
1085 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 kXRtcpMux.c_str(), kXRtcpMux.length(),
1088 &sdp);
1089 }
1090
1091 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1092 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093
1094 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001095 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1097 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001098 if (bundle) {
1099 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1100 } else {
1101 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 }
1103 }
1104 // Tests that we can only send DTMF when the dtmf codec is supported.
1105 void TestCanInsertDtmf(bool can) {
1106 if (can) {
1107 InitWithDtmfCodec();
1108 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001109 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 }
deadbeefab9b2d12015-10-14 11:33:11 -07001111 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 CreateAndSetRemoteOfferAndLocalAnswer();
1113 EXPECT_FALSE(session_->CanInsertDtmf(""));
1114 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1115 }
1116
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001117 // Helper class to configure loopback network and verify Best
1118 // Connection using right IP protocol for TestLoopbackCall
1119 // method. LoopbackNetworkManager applies firewall rules to block
1120 // all ping traffic once ICE completed, and remove them to observe
1121 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1122 // verifies the best connection is using the right IP protocol after
1123 // initial ICE convergences.
1124
1125 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001126 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001127 LoopbackNetworkConfiguration()
1128 : test_ipv6_network_(false),
1129 test_extra_ipv4_network_(false),
1130 best_connection_after_initial_ice_converged_(1, 0) {}
1131
1132 // Used to track the expected best connection count in each IP protocol.
1133 struct ExpectedBestConnection {
1134 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1135 : ipv4_count_(ipv4_count),
1136 ipv6_count_(ipv6_count) {}
1137
1138 int ipv4_count_;
1139 int ipv6_count_;
1140 };
1141
1142 bool test_ipv6_network_;
1143 bool test_extra_ipv4_network_;
1144 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1145
1146 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001147 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001148 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1149 }
1150
1151 private:
jbauchac8869e2015-07-03 01:36:14 -07001152 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 const ExpectedBestConnection& expected) const {
1154 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001155 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1156 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 expected.ipv4_count_);
1158 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001159 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1160 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001161 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001162 // This is used in the loopback call so there is only single host to host
1163 // candidate pair.
1164 EXPECT_EQ(metrics_observer->GetEnumCounter(
1165 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1166 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001167 0);
1168 EXPECT_EQ(metrics_observer->GetEnumCounter(
1169 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1170 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001171 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172 }
1173 };
1174
1175 class LoopbackNetworkManager {
1176 public:
1177 LoopbackNetworkManager(WebRtcSessionTest* session,
1178 const LoopbackNetworkConfiguration& config)
1179 : config_(config) {
1180 session->AddInterface(
1181 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1182 if (config_.test_extra_ipv4_network_) {
1183 session->AddInterface(
1184 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1185 }
1186 if (config_.test_ipv6_network_) {
1187 session->AddInterface(
1188 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1189 }
1190 }
1191
1192 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1193 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1194 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1195 if (config_.test_extra_ipv4_network_) {
1196 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1197 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1198 }
1199 if (config_.test_ipv6_network_) {
1200 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1201 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1202 }
1203 }
1204
1205 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1206
1207 private:
1208 LoopbackNetworkConfiguration config_;
1209 };
1210
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 // The method sets up a call from the session to itself, in a loopback
1212 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001213 // disconnection, and then a permanent disconnection.
1214 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1216 // While running the call, this method also checks if the session goes through
1217 // the correct sequence of ICE states when a connection is established,
1218 // broken, and re-established.
1219 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001220 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1221 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001223
stefanc1aeaf02015-10-15 07:26:07 -07001224 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001225 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001226 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001227 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228
1229 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1230 observer_.ice_gathering_state_);
1231 SetLocalDescriptionWithoutError(offer);
1232 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1233 observer_.ice_connection_state_);
1234 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001235 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1237 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001238 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239
1240 std::string sdp;
1241 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001242 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1243 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244 ASSERT_TRUE(desc != NULL);
1245 SetRemoteDescriptionWithoutError(desc);
1246
1247 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001248 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001249
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001250 // The ice connection state is "Connected" too briefly to catch in a test.
1251 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001252 observer_.ice_connection_state_, kIceCandidatesTimeout);
1253 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
stefanc1aeaf02015-10-15 07:26:07 -07001255 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1256 LoopbackNetworkManager loopback_network_manager(this, config);
1257 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 // Adding firewall rule to block ping requests, which should cause
1260 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001261
1262 loopback_network_manager.ApplyFirewallRules(fss_.get());
1263
1264 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1266 observer_.ice_connection_state_,
1267 kIceCandidatesTimeout);
1268
jbauchac8869e2015-07-03 01:36:14 -07001269 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001270
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001272 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001274 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001275 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 observer_.ice_connection_state_,
1277 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001278
1279 // Now we block ping requests and wait until the ICE connection transitions
1280 // to the Failed state. This will take at least 30 seconds because it must
1281 // wait for the Port to timeout.
1282 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001283
1284 loopback_network_manager.ApplyFirewallRules(fss_.get());
1285 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001286 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001287 observer_.ice_connection_state_,
1288 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 }
1290
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 void TestLoopbackCall() {
1292 LoopbackNetworkConfiguration config;
1293 TestLoopbackCall(config);
1294 }
1295
stefanc1aeaf02015-10-15 07:26:07 -07001296 void TestPacketOptions() {
1297 media_controller_.reset(
1298 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1299 LoopbackNetworkConfiguration config;
1300 LoopbackNetworkManager loopback_network_manager(this, config);
1301
1302 SetupLoopbackCall();
1303
1304 uint8_t test_packet[15] = {0};
1305 rtc::PacketOptions options;
1306 options.packet_id = 10;
1307 media_engine_->GetVideoChannel(0)
1308 ->SendRtp(test_packet, sizeof(test_packet), options);
1309
1310 const int kPacketTimeout = 2000;
1311 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1312 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1313 }
1314
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1316 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001317 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1318 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001319
1320 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1322 codecs.push_back(kCNCodec1);
1323 codecs.push_back(kCNCodec2);
1324 media_engine_->SetAudioCodecs(codecs);
1325 desc_factory_->set_audio_codecs(codecs);
1326 }
1327
1328 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1329 const cricket::ContentDescription* description = content->description;
1330 ASSERT(description != NULL);
1331 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001332 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 ASSERT(audio_content_desc != NULL);
1334 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1335 if (audio_content_desc->codecs()[i].name == "CN")
1336 return false;
1337 }
1338 return true;
1339 }
1340
deadbeefab9b2d12015-10-14 11:33:11 -07001341 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001342 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001343 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001344 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1345 data_channel_ = DataChannel::Create(
1346 session_.get(), session_->data_channel_type(), "datachannel", dci);
1347 }
1348
1349 void SetLocalDescriptionWithDataChannel() {
1350 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001351 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 SetLocalDescriptionWithoutError(offer);
1353 }
1354
wu@webrtc.org91053e72013-08-10 07:18:04 +00001355 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001356 RTCCertificateGenerationMethod cert_gen_method,
1357 CreateSessionDescriptionRequest::Type type) {
1358 InitWithDtls(cert_gen_method);
1359 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1360 }
1361
1362 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1363 CreateSessionDescriptionRequest::Type type) {
1364 InitWithDtlsIdentityGenFail();
1365 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1366 }
1367
1368 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001369 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001370 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001371 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001372 if (type == CreateSessionDescriptionRequest::kAnswer) {
1373 cricket::MediaSessionOptions options;
1374 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001375 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001376 ASSERT_TRUE(offer.get() != NULL);
1377 SetRemoteDescriptionWithoutError(offer.release());
1378 }
1379
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001380 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001381 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001382 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001383 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 observers[kNumber];
1385 for (int i = 0; i < kNumber; ++i) {
1386 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1387 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001388 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 } else {
htaa2a49d92016-03-04 02:51:39 -08001390 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001391 }
1392 }
1393
1394 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1395 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1396 WebRtcSessionCreateSDPObserverForTest::kFailed;
1397
1398 for (int i = 0; i < kNumber; ++i) {
1399 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1400 if (success) {
1401 EXPECT_TRUE(observers[i]->description() != NULL);
1402 } else {
1403 EXPECT_TRUE(observers[i]->description() == NULL);
1404 }
1405 }
1406 }
1407
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001408 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001409 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001410 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001411 turn_server.credentials = credentials;
1412 turn_server.ports.push_back(
1413 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1414 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001415 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001416 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001417 }
1418
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 cricket::FakeMediaEngine* media_engine_;
1420 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001421 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001422 cricket::FakeCall fake_call_;
1423 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001424 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001425 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1426 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1427 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1428 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1429 rtc::SocketServerScope ss_scope_;
1430 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001431 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001432 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001433 rtc::FakeNetworkManager network_manager_;
1434 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001435 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001436 PeerConnectionInterface::RTCConfiguration configuration_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001437 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 MockIceObserver observer_;
1439 cricket::FakeVideoMediaChannel* video_channel_;
1440 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001441 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001442 // The following flags affect options created for CreateOffer/CreateAnswer.
1443 bool send_stream_1_ = false;
1444 bool send_stream_2_ = false;
1445 bool send_audio_ = false;
1446 bool send_video_ = false;
1447 rtc::scoped_refptr<DataChannel> data_channel_;
1448 // Last values received from data channel creation signal.
1449 std::string last_data_channel_label_;
1450 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001451 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452};
1453
Henrik Boström87713d02015-08-25 09:53:21 +02001454TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1455 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001456 // SDES is disabled when DTLS is on.
1457 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458}
1459
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001460TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001461 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001462 // SDES is required if DTLS is off.
1463 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001464}
1465
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1467 TestSessionCandidatesWithBundleRtcpMux(false, false);
1468}
1469
1470// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1471// with rtcp-mux and/or bundle.
1472TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1473 TestSessionCandidatesWithBundleRtcpMux(false, true);
1474}
1475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1477 TestSessionCandidatesWithBundleRtcpMux(true, true);
1478}
1479
1480TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001481 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1482 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001483 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001484 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 InitiateCall();
1486 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1487 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1488 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1489}
1490
minyuec8930ba2016-01-22 06:17:46 -08001491// Crashes on Win only. See webrtc:5411.
1492#if defined(WEBRTC_WIN)
1493#define MAYBE_TestStunError DISABLED_TestStunError
1494#else
1495#define MAYBE_TestStunError TestStunError
1496#endif
1497TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001498 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1499 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001500 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001501 rtc::FP_UDP,
1502 rtc::FD_ANY,
1503 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001504 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001505 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001507 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1509 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1510 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1511}
1512
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001513// Test session delivers no candidates gathered when constraint set to "none".
1514TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1515 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001516 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001517 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001518 InitiateCall();
1519 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1520 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1521 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1522}
1523
1524// Test session delivers only relay candidates gathered when constaint set to
1525// "relay".
1526TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1527 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1528 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001529 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001530 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001531 InitiateCall();
1532 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1533 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1534 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1535 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1536 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1537 observer_.mline_0_candidates_[i].type());
1538 }
1539 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1540 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1541 observer_.mline_1_candidates_[i].type());
1542 }
1543}
1544
1545// Test session delivers all candidates gathered when constaint set to "all".
1546TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1547 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001548 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001549 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001550 InitiateCall();
1551 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1552 // Host + STUN. By default allocator is disabled to gather relay candidates.
1553 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1554 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1555}
1556
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001557TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001558 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001559 SessionDescriptionInterface* offer = NULL;
1560 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1561 std::string unknown_action;
1562 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1563 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1564}
1565
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566// Test creating offers and receive answers and make sure the
1567// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001568TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001569 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001570 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001571 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 const std::string session_id_orig = offer->session_id();
1573 const std::string session_version_orig = offer->session_version();
1574 SetLocalDescriptionWithoutError(offer);
1575
deadbeefab9b2d12015-10-14 11:33:11 -07001576 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 SessionDescriptionInterface* answer =
1578 CreateRemoteAnswer(session_->local_description());
1579 SetRemoteDescriptionWithoutError(answer);
1580
1581 video_channel_ = media_engine_->GetVideoChannel(0);
1582 voice_channel_ = media_engine_->GetVoiceChannel(0);
1583
1584 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1585 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1586
1587 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1588 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1589
1590 ASSERT_EQ(1u, video_channel_->send_streams().size());
1591 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1592 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1593 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1594
1595 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001597 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598
1599 // Verify the session id is the same and the session version is
1600 // increased.
1601 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001602 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1603 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604
1605 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001606 EXPECT_EQ(0u, video_channel_->send_streams().size());
1607 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608
deadbeefab9b2d12015-10-14 11:33:11 -07001609 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 answer = CreateRemoteAnswer(session_->local_description());
1611 SetRemoteDescriptionWithoutError(answer);
1612
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 // Make sure the receive streams have not changed.
1614 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1615 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1616 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1617 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1618}
1619
1620// Test receiving offers and creating answers and make sure the
1621// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001623 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001624 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001625 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001626 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 SetRemoteDescriptionWithoutError(offer);
1628
deadbeefab9b2d12015-10-14 11:33:11 -07001629 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001630 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001631 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 SetLocalDescriptionWithoutError(answer);
1633
1634 const std::string session_id_orig = answer->session_id();
1635 const std::string session_version_orig = answer->session_version();
1636
1637 video_channel_ = media_engine_->GetVideoChannel(0);
1638 voice_channel_ = media_engine_->GetVoiceChannel(0);
1639
htaa2a49d92016-03-04 02:51:39 -08001640 ASSERT_TRUE(video_channel_);
1641 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1643 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1644
1645 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1646 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1647
1648 ASSERT_EQ(1u, video_channel_->send_streams().size());
1649 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1650 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1651 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1652
deadbeefab9b2d12015-10-14 11:33:11 -07001653 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001654 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 SetRemoteDescriptionWithoutError(offer);
1656
1657 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001658 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001659 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660
1661 // Verify the session id is the same and the session version is
1662 // increased.
1663 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001664 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1665 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 SetLocalDescriptionWithoutError(answer);
1667
1668 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1669 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1670 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1671 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1672 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1673 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1674
1675 // Make sure we have no send streams.
1676 EXPECT_EQ(0u, video_channel_->send_streams().size());
1677 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1678}
1679
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001680TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001681 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001682 media_engine_->set_fail_create_channel(true);
1683
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001684 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001685 ASSERT_TRUE(offer != NULL);
1686 // SetRemoteDescription and SetLocalDescription will take the ownership of
1687 // the offer.
1688 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001689 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001690 ASSERT_TRUE(offer != NULL);
1691 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1692}
1693
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001694//
1695// Tests for creating/setting SDP under different SDES/DTLS polices:
1696//
1697// --DTLS off and SDES on
1698// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1699// set local/remote offer/answer with crypto --> success
1700// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1701// failure
1702// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1703// failure
1704// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1705// failure
1706//
1707// --DTLS on and SDES off
1708// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1709// set local/remote offer/answer with DTLS fingerprint --> success
1710// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1711// fingerprint --> failure
1712// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1713// --> failure
1714// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1715// --> failure
1716//
1717// --Encryption disabled: DTLS off and SDES off
1718// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1719// answer without SDES or DTLS --> success
1720// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1721// answer without SDES or DTLS --> success
1722//
1723
1724// Test that we return a failure when applying a remote/local offer that doesn't
1725// have cryptos enabled when DTLS is off.
1726TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001727 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001729 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 JsepSessionDescription* offer = CreateRemoteOffer(
1731 options, cricket::SEC_DISABLED);
1732 ASSERT_TRUE(offer != NULL);
1733 VerifyNoCryptoParams(offer->description(), false);
1734 // SetRemoteDescription and SetLocalDescription will take the ownership of
1735 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001736 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1738 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001739 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740}
1741
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742// Test that we return a failure when applying a local answer that doesn't have
1743// cryptos enabled when DTLS is off.
1744TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001745 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 SessionDescriptionInterface* offer = NULL;
1747 SessionDescriptionInterface* answer = NULL;
1748 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1749 // SetRemoteDescription and SetLocalDescription will take the ownership of
1750 // the offer.
1751 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001752 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753}
1754
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001755// Test we will return fail when apply an remote answer that doesn't have
1756// crypto enabled when DTLS is off.
1757TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001758 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 SessionDescriptionInterface* offer = NULL;
1760 SessionDescriptionInterface* answer = NULL;
1761 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1762 // SetRemoteDescription and SetLocalDescription will take the ownership of
1763 // the offer.
1764 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766}
1767
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1769// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001770TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001771 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001772 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001773 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 SetFactoryDtlsSrtp();
1775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001776 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777 JsepSessionDescription* offer =
1778 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 ASSERT_TRUE(offer != NULL);
1780 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001781 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782
1783 // SetRemoteDescription will take the ownership of the offer.
1784 SetRemoteDescriptionWithoutError(offer);
1785
1786 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001787 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 ASSERT_TRUE(answer != NULL);
1789 VerifyFingerprintStatus(answer->description(), true);
1790 // Check that we don't have an a=crypto line in the answer.
1791 VerifyNoCryptoParams(answer->description(), true);
1792
1793 // Now set the local description, which should work, even without a=crypto.
1794 SetLocalDescriptionWithoutError(answer);
1795}
1796
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001797// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1798// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001799TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001800 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001801 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001802 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803 SetFactoryDtlsSrtp();
1804
1805 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001806 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807 ASSERT_TRUE(offer != NULL);
1808 VerifyFingerprintStatus(offer->description(), true);
1809 // Check that we don't have an a=crypto line in the offer.
1810 VerifyNoCryptoParams(offer->description(), true);
1811
1812 // Now set the local description, which should work, even without a=crypto.
1813 SetLocalDescriptionWithoutError(offer);
1814
1815 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001816 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001817 JsepSessionDescription* answer =
1818 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1819 ASSERT_TRUE(answer != NULL);
1820 VerifyFingerprintStatus(answer->description(), true);
1821 VerifyNoCryptoParams(answer->description(), true);
1822
1823 // SetRemoteDescription will take the ownership of the answer.
1824 SetRemoteDescriptionWithoutError(answer);
1825}
1826
1827// Test that if we support DTLS and the other side didn't offer a fingerprint,
1828// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001829TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001830 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001831 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001833 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001834 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 JsepSessionDescription* offer = CreateRemoteOffer(
1836 options, cricket::SEC_REQUIRED);
1837 ASSERT_TRUE(offer != NULL);
1838 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001839 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001841 // SetRemoteDescription will take the ownership of the offer.
1842 SetRemoteDescriptionOfferExpectError(
1843 kSdpWithoutDtlsFingerprint, offer);
1844
1845 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1846 // SetLocalDescription will take the ownership of the offer.
1847 SetLocalDescriptionOfferExpectError(
1848 kSdpWithoutDtlsFingerprint, offer);
1849}
1850
1851// Test that we return a failure when applying a local answer that doesn't have
1852// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001853TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001854 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001855 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856 SessionDescriptionInterface* offer = NULL;
1857 SessionDescriptionInterface* answer = NULL;
1858 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1859
1860 // SetRemoteDescription and SetLocalDescription will take the ownership of
1861 // the offer and answer.
1862 SetRemoteDescriptionWithoutError(offer);
1863 SetLocalDescriptionAnswerExpectError(
1864 kSdpWithoutDtlsFingerprint, answer);
1865}
1866
1867// Test that we return a failure when applying a remote answer that doesn't have
1868// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001869TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001870 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001871 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001872 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001873 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001874 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001875 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1876 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001877 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001878 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879
1880 // SetRemoteDescription and SetLocalDescription will take the ownership of
1881 // the offer and answer.
1882 SetLocalDescriptionWithoutError(offer);
1883 SetRemoteDescriptionAnswerExpectError(
1884 kSdpWithoutDtlsFingerprint, answer);
1885}
1886
1887// Test that we create a local offer without SDES or DTLS and accept a remote
1888// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001889TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001890 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001892 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001893
1894 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001895 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 ASSERT_TRUE(offer != NULL);
1897 VerifyFingerprintStatus(offer->description(), false);
1898 // Check that we don't have an a=crypto line in the offer.
1899 VerifyNoCryptoParams(offer->description(), false);
1900
1901 // Now set the local description, which should work, even without a=crypto.
1902 SetLocalDescriptionWithoutError(offer);
1903
1904 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001905 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906 JsepSessionDescription* answer =
1907 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1908 ASSERT_TRUE(answer != NULL);
1909 VerifyFingerprintStatus(answer->description(), false);
1910 VerifyNoCryptoParams(answer->description(), false);
1911
1912 // SetRemoteDescription will take the ownership of the answer.
1913 SetRemoteDescriptionWithoutError(answer);
1914}
1915
1916// Test that we create a local answer without SDES or DTLS and accept a remote
1917// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001918TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001920 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921
1922 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001923 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924 JsepSessionDescription* offer =
1925 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1926 ASSERT_TRUE(offer != NULL);
1927 VerifyFingerprintStatus(offer->description(), false);
1928 VerifyNoCryptoParams(offer->description(), false);
1929
1930 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 SetRemoteDescriptionWithoutError(offer);
1932
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001933 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001934 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 ASSERT_TRUE(answer != NULL);
1936 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001937 // Check that we don't have an a=crypto line in the answer.
1938 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 SetLocalDescriptionWithoutError(answer);
1942}
1943
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001944// Test that we can create and set an answer correctly when different
1945// SSL roles have been negotiated for different transports.
1946// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1947TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1948 SendAudioVideoStream1();
1949 InitWithDtls(GetParam());
1950 SetFactoryDtlsSrtp();
1951
1952 SessionDescriptionInterface* offer = CreateOffer();
1953 SetLocalDescriptionWithoutError(offer);
1954
1955 cricket::MediaSessionOptions options;
1956 options.recv_video = true;
1957
1958 // First, negotiate different SSL roles.
1959 SessionDescriptionInterface* answer =
1960 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1961 TransportInfo* audio_transport_info =
1962 answer->description()->GetTransportInfoByName("audio");
1963 audio_transport_info->description.connection_role =
1964 cricket::CONNECTIONROLE_ACTIVE;
1965 TransportInfo* video_transport_info =
1966 answer->description()->GetTransportInfoByName("video");
1967 video_transport_info->description.connection_role =
1968 cricket::CONNECTIONROLE_PASSIVE;
1969 SetRemoteDescriptionWithoutError(answer);
1970
1971 // Now create an offer in the reverse direction, and ensure the initial
1972 // offerer responds with an answer with correct SSL roles.
1973 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1974 kSessionVersion,
1975 session_->remote_description());
1976 SetRemoteDescriptionWithoutError(offer);
1977
htaa2a49d92016-03-04 02:51:39 -08001978 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001979 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1980 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1981 audio_transport_info->description.connection_role);
1982 video_transport_info = answer->description()->GetTransportInfoByName("video");
1983 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1984 video_transport_info->description.connection_role);
1985 SetLocalDescriptionWithoutError(answer);
1986
1987 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1988 // audio is transferred over to video in the answer that completes the BUNDLE
1989 // negotiation.
1990 options.bundle_enabled = true;
1991 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1992 kSessionVersion,
1993 session_->remote_description());
1994 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001995 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001996 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1997 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1998 audio_transport_info->description.connection_role);
1999 video_transport_info = answer->description()->GetTransportInfoByName("video");
2000 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2001 video_transport_info->description.connection_role);
2002 SetLocalDescriptionWithoutError(answer);
2003}
2004
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002006 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002007 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002009 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010 SetLocalDescriptionWithoutError(offer);
2011
2012 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetLocalDescriptionWithoutError(offer2);
2015}
2016
2017TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002018 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002019 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002021 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 SetRemoteDescriptionWithoutError(offer);
2023
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002024 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 SetRemoteDescriptionWithoutError(offer2);
2026}
2027
2028TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002029 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002030 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002031 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002033 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002034 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2035 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036}
2037
2038TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002039 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002040 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002041 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002043 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002044 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002045 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046}
2047
2048TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002049 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002052 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053
htaa2a49d92016-03-04 02:51:39 -08002054 JsepSessionDescription* pranswer =
2055 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002057 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
deadbeefab9b2d12015-10-14 11:33:11 -07002059 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002060 JsepSessionDescription* pranswer2 =
2061 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2063
deadbeefd59daf82015-10-14 15:02:44 -07002064 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002067 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002068 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069}
2070
2071TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002072 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002074 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002075 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076
2077 JsepSessionDescription* pranswer =
2078 CreateRemoteAnswer(session_->local_description());
2079 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2080
2081 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002082 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083
deadbeefab9b2d12015-10-14 11:33:11 -07002084 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 JsepSessionDescription* pranswer2 =
2086 CreateRemoteAnswer(session_->local_description());
2087 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2088
2089 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002090 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 SessionDescriptionInterface* answer =
2094 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002095 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096}
2097
2098TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
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 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2106 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002110 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002112 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2113
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 SessionDescriptionInterface* answer =
2115 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002116 SetRemoteDescriptionAnswerExpectError(
2117 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118}
2119
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002120// Tests that the remote candidates are added and removed successfully.
2121TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002122 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002123 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002125 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2126 "", "", "host", 0, "");
2127 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2129
deadbeefd59daf82015-10-14 15:02:44 -07002130 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2132
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002133 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002135
2136 // Fail since we have not set a remote description.
2137 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138
2139 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2140 session_->local_description());
2141 SetRemoteDescriptionWithoutError(answer);
2142
deadbeefd59daf82015-10-14 15:02:44 -07002143 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2144 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002145 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002146 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2147 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 // Verifying the candidates are copied properly from internal vector.
2150 const SessionDescriptionInterface* remote_desc =
2151 session_->remote_description();
2152 ASSERT_TRUE(remote_desc != NULL);
2153 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2154 const IceCandidateCollection* candidates =
2155 remote_desc->candidates(kMediaContentIndex0);
2156 ASSERT_EQ(2u, candidates->count());
2157 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2158 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2159 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2160 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2161
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002162 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2163 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 candidate.set_component(2);
2165 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2166 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002167 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168
2169 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2170 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002171
2172 // Remove candidate1 and candidate2
2173 std::vector<cricket::Candidate> remote_candidates;
2174 remote_candidates.push_back(ice_candidate1.candidate());
2175 remote_candidates.push_back(ice_candidate2.candidate());
2176 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2177 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178}
2179
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002180// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181// that it is retained if the remote session description is changed.
2182TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002183 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 cricket::Candidate candidate1;
2185 candidate1.set_component(1);
2186 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2187 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002188 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 CreateAndSetRemoteOfferAndLocalAnswer();
2190
2191 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2192 const SessionDescriptionInterface* remote_desc =
2193 session_->remote_description();
2194 ASSERT_TRUE(remote_desc != NULL);
2195 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2196 const IceCandidateCollection* candidates =
2197 remote_desc->candidates(kMediaContentIndex0);
2198 ASSERT_EQ(1u, candidates->count());
2199 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2200
2201 // Update the RemoteSessionDescription with a new session description and
2202 // a candidate and check that the new remote session description contains both
2203 // candidates.
2204 SessionDescriptionInterface* offer = CreateRemoteOffer();
2205 cricket::Candidate candidate2;
2206 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2207 candidate2);
2208 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2209 SetRemoteDescriptionWithoutError(offer);
2210
2211 remote_desc = session_->remote_description();
2212 ASSERT_TRUE(remote_desc != NULL);
2213 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2214 candidates = remote_desc->candidates(kMediaContentIndex0);
2215 ASSERT_EQ(2u, candidates->count());
2216 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2217 // Username and password have be updated with the TransportInfo of the
2218 // SessionDescription, won't be equal to the original one.
2219 candidate2.set_username(candidates->at(0)->candidate().username());
2220 candidate2.set_password(candidates->at(0)->candidate().password());
2221 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2222 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2223 // No need to verify the username and password.
2224 candidate1.set_username(candidates->at(1)->candidate().username());
2225 candidate1.set_password(candidates->at(1)->candidate().password());
2226 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2227
2228 // Test that the candidate is ignored if we can add the same candidate again.
2229 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2230}
2231
2232// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002233// that they are retained if the local session description is changed. And if
2234// continual gathering is enabled, they are removed from the local session
2235// description when the network is down.
2236TEST_F(WebRtcSessionTest,
2237 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002238 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002239 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002240 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 CreateAndSetRemoteOfferAndLocalAnswer();
2242
2243 const SessionDescriptionInterface* local_desc = session_->local_description();
2244 const IceCandidateCollection* candidates =
2245 local_desc->candidates(kMediaContentIndex0);
2246 ASSERT_TRUE(candidates != NULL);
2247 EXPECT_EQ(0u, candidates->count());
2248
2249 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2250
2251 local_desc = session_->local_description();
2252 candidates = local_desc->candidates(kMediaContentIndex0);
2253 ASSERT_TRUE(candidates != NULL);
2254 EXPECT_LT(0u, candidates->count());
2255 candidates = local_desc->candidates(1);
2256 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002257 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258
2259 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002260 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 CreateAndSetRemoteOfferAndLocalAnswer();
2262
2263 local_desc = session_->local_description();
2264 candidates = local_desc->candidates(kMediaContentIndex0);
2265 ASSERT_TRUE(candidates != NULL);
2266 EXPECT_LT(0u, candidates->count());
2267 candidates = local_desc->candidates(1);
2268 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002269 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002270
2271 candidates = local_desc->candidates(kMediaContentIndex0);
2272 size_t num_local_candidates = candidates->count();
2273 // Enable Continual Gathering
2274 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2275 // Bring down the network interface to trigger candidate removals.
2276 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2277 // Verify that all local candidates are removed.
2278 EXPECT_EQ(0, observer_.num_candidates_removed_);
2279 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2280 kIceCandidatesTimeout);
2281 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2282}
2283
2284// Tests that if continual gathering is disabled, local candidates won't be
2285// removed when the interface is turned down.
2286TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2287 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2288 Init();
2289 SendAudioVideoStream1();
2290 CreateAndSetRemoteOfferAndLocalAnswer();
2291
2292 const SessionDescriptionInterface* local_desc = session_->local_description();
2293 const IceCandidateCollection* candidates =
2294 local_desc->candidates(kMediaContentIndex0);
2295 ASSERT_TRUE(candidates != NULL);
2296 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2297
2298 size_t num_local_candidates = candidates->count();
2299 EXPECT_LT(0u, num_local_candidates);
2300 // By default, Continual Gathering is disabled.
2301 // Bring down the network interface.
2302 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2303 // Verify that the local candidates are not removed.
2304 rtc::Thread::Current()->ProcessMessages(1000);
2305 EXPECT_EQ(0, observer_.num_candidates_removed_);
2306 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307}
2308
2309// Test that we can set a remote session description with remote candidates.
2310TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002311 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312
2313 cricket::Candidate candidate1;
2314 candidate1.set_component(1);
2315 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2316 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002317 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002318 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319
2320 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2321 SetRemoteDescriptionWithoutError(offer);
2322
2323 const SessionDescriptionInterface* remote_desc =
2324 session_->remote_description();
2325 ASSERT_TRUE(remote_desc != NULL);
2326 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2327 const IceCandidateCollection* candidates =
2328 remote_desc->candidates(kMediaContentIndex0);
2329 ASSERT_EQ(1u, candidates->count());
2330 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2331
htaa2a49d92016-03-04 02:51:39 -08002332 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 SetLocalDescriptionWithoutError(answer);
2334}
2335
2336// Test that offers and answers contains ice candidates when Ice candidates have
2337// been gathered.
2338TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002339 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002340 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002341 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 // Ice is started but candidates are not provided until SetLocalDescription
2343 // is called.
2344 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2345 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2346 CreateAndSetRemoteOfferAndLocalAnswer();
2347 // Wait until at least one local candidate has been collected.
2348 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2349 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002351 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2354 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
2356 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2357 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002358 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2360 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 SetLocalDescriptionWithoutError(answer);
2362}
2363
2364// Verifies TransportProxy and media channels are created with content names
2365// present in the SessionDescription.
2366TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002367 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002368 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002369 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370
2371 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002372 // "video". Goal is to modify these content names and verify transport
2373 // channels
2374 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 // present in SDP.
2376 std::string sdp;
2377 EXPECT_TRUE(offer->ToString(&sdp));
2378 const std::string kAudioMid = "a=mid:audio";
2379 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2380 const std::string kVideoMid = "a=mid:video";
2381 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2382
2383 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002384 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 kAudioMidReplaceStr.c_str(),
2386 kAudioMidReplaceStr.length(),
2387 &sdp);
2388 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002389 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 kVideoMidReplaceStr.c_str(),
2391 kVideoMidReplaceStr.length(),
2392 &sdp);
2393
2394 SessionDescriptionInterface* modified_offer =
2395 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2396
2397 SetRemoteDescriptionWithoutError(modified_offer);
2398
htaa2a49d92016-03-04 02:51:39 -08002399 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 SetLocalDescriptionWithoutError(answer);
2401
deadbeefcbecd352015-09-23 11:50:27 -07002402 cricket::TransportChannel* voice_transport_channel =
2403 session_->voice_rtp_transport_channel();
2404 EXPECT_TRUE(voice_transport_channel != NULL);
2405 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2406 cricket::TransportChannel* video_transport_channel =
2407 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002408 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002409 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2411 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2412}
2413
2414// Test that an offer contains the correct media content descriptions based on
2415// the send streams when no constraints have been set.
2416TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002417 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002418 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2419
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 ASSERT_TRUE(offer != NULL);
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 the correct media content descriptions based on
2429// the send streams when no constraints have been set.
2430TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002431 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002433 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2435
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 const cricket::ContentInfo* content =
2437 cricket::GetFirstAudioContent(offer->description());
2438 EXPECT_TRUE(content != NULL);
2439 content = cricket::GetFirstVideoContent(offer->description());
2440 EXPECT_TRUE(content == NULL);
2441
2442 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002443 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002444 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 content = cricket::GetFirstAudioContent(offer->description());
2446 EXPECT_TRUE(content != NULL);
2447 content = cricket::GetFirstVideoContent(offer->description());
2448 EXPECT_TRUE(content != NULL);
2449}
2450
2451// Test that an offer contains no media content descriptions if
2452// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2453TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002454 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002455 PeerConnectionInterface::RTCOfferAnswerOptions options;
2456 options.offer_to_receive_audio = 0;
2457 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002459 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002460 CreateOffer(options));
2461
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 ASSERT_TRUE(offer != NULL);
2463 const cricket::ContentInfo* content =
2464 cricket::GetFirstAudioContent(offer->description());
2465 EXPECT_TRUE(content == NULL);
2466 content = cricket::GetFirstVideoContent(offer->description());
2467 EXPECT_TRUE(content == NULL);
2468}
2469
2470// Test that an offer contains only audio media content descriptions if
2471// kOfferToReceiveAudio constraints are set to true.
2472TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002473 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002474 PeerConnectionInterface::RTCOfferAnswerOptions options;
2475 options.offer_to_receive_audio =
2476 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2477
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002478 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002479 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480
2481 const cricket::ContentInfo* content =
2482 cricket::GetFirstAudioContent(offer->description());
2483 EXPECT_TRUE(content != NULL);
2484 content = cricket::GetFirstVideoContent(offer->description());
2485 EXPECT_TRUE(content == NULL);
2486}
2487
2488// Test that an offer contains audio and video media content descriptions if
2489// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2490TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002493 PeerConnectionInterface::RTCOfferAnswerOptions options;
2494 options.offer_to_receive_audio =
2495 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2496 options.offer_to_receive_video =
2497 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2498
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002499 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002500 CreateOffer(options));
2501
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 const cricket::ContentInfo* content =
2503 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002504 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002505
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 content = cricket::GetFirstVideoContent(offer->description());
2507 EXPECT_TRUE(content != NULL);
2508
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002509 // Sets constraints to false and verifies that audio/video contents are
2510 // removed.
2511 options.offer_to_receive_audio = 0;
2512 options.offer_to_receive_video = 0;
2513 offer.reset(CreateOffer(options));
2514
2515 content = cricket::GetFirstAudioContent(offer->description());
2516 EXPECT_TRUE(content == NULL);
2517 content = cricket::GetFirstVideoContent(offer->description());
2518 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519}
2520
2521// Test that an answer can not be created if the last remote description is not
2522// an offer.
2523TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002524 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002525 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526 SetLocalDescriptionWithoutError(offer);
2527 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2528 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002529 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530}
2531
2532// Test that an answer contains the correct media content descriptions when no
2533// constraints have been set.
2534TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002535 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002537 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002539 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 const cricket::ContentInfo* content =
2541 cricket::GetFirstAudioContent(answer->description());
2542 ASSERT_TRUE(content != NULL);
2543 EXPECT_FALSE(content->rejected);
2544
2545 content = cricket::GetFirstVideoContent(answer->description());
2546 ASSERT_TRUE(content != NULL);
2547 EXPECT_FALSE(content->rejected);
2548}
2549
2550// Test that an answer contains the correct media content descriptions when no
2551// constraints have been set and the offer only contain audio.
2552TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002553 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 // Create a remote offer with audio only.
2555 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002556
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002557 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 CreateRemoteOffer(options));
2559 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2560 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2561
2562 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002563 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564 const cricket::ContentInfo* content =
2565 cricket::GetFirstAudioContent(answer->description());
2566 ASSERT_TRUE(content != NULL);
2567 EXPECT_FALSE(content->rejected);
2568
2569 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2570}
2571
2572// Test that an answer contains the correct media content descriptions when no
2573// constraints have been set.
2574TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002575 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002577 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 SetRemoteDescriptionWithoutError(offer.release());
2579 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002580 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002581 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 const cricket::ContentInfo* content =
2583 cricket::GetFirstAudioContent(answer->description());
2584 ASSERT_TRUE(content != NULL);
2585 EXPECT_FALSE(content->rejected);
2586
2587 content = cricket::GetFirstVideoContent(answer->description());
2588 ASSERT_TRUE(content != NULL);
2589 EXPECT_FALSE(content->rejected);
2590}
2591
2592// Test that an answer contains the correct media content descriptions when
2593// constraints have been set but no stream is sent.
2594TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002595 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002597 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 SetRemoteDescriptionWithoutError(offer.release());
2599
htaa2a49d92016-03-04 02:51:39 -08002600 cricket::MediaSessionOptions session_options;
2601 session_options.recv_audio = false;
2602 session_options.recv_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002603 rtc::scoped_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002604 CreateAnswer(session_options));
2605
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 const cricket::ContentInfo* content =
2607 cricket::GetFirstAudioContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_TRUE(content->rejected);
2610
2611 content = cricket::GetFirstVideoContent(answer->description());
2612 ASSERT_TRUE(content != NULL);
2613 EXPECT_TRUE(content->rejected);
2614}
2615
2616// Test that an answer contains the correct media content descriptions when
2617// constraints have been set and streams are sent.
2618TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002619 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002621 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 SetRemoteDescriptionWithoutError(offer.release());
2623
htaa2a49d92016-03-04 02:51:39 -08002624 cricket::MediaSessionOptions options;
2625 options.recv_audio = false;
2626 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627
2628 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002629 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002630 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631
2632 // TODO(perkj): Should the direction be set to SEND_ONLY?
2633 const cricket::ContentInfo* content =
2634 cricket::GetFirstAudioContent(answer->description());
2635 ASSERT_TRUE(content != NULL);
2636 EXPECT_FALSE(content->rejected);
2637
2638 // TODO(perkj): Should the direction be set to SEND_ONLY?
2639 content = cricket::GetFirstVideoContent(answer->description());
2640 ASSERT_TRUE(content != NULL);
2641 EXPECT_FALSE(content->rejected);
2642}
2643
2644TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2645 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002646 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002647 PeerConnectionInterface::RTCOfferAnswerOptions options;
2648 options.offer_to_receive_audio =
2649 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2650 options.voice_activity_detection = false;
2651
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002652 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002653 CreateOffer(options));
2654
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 const cricket::ContentInfo* content =
2656 cricket::GetFirstAudioContent(offer->description());
2657 EXPECT_TRUE(content != NULL);
2658 EXPECT_TRUE(VerifyNoCNCodecs(content));
2659}
2660
2661TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2662 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002663 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002665 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666 SetRemoteDescriptionWithoutError(offer.release());
2667
htaa2a49d92016-03-04 02:51:39 -08002668 cricket::MediaSessionOptions options;
2669 options.vad_enabled = false;
2670 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671 const cricket::ContentInfo* content =
2672 cricket::GetFirstAudioContent(answer->description());
2673 ASSERT_TRUE(content != NULL);
2674 EXPECT_TRUE(VerifyNoCNCodecs(content));
2675}
2676
2677// This test verifies the call setup when remote answer with audio only and
2678// later updates with video.
2679TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002680 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2682 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2683
deadbeefab9b2d12015-10-14 11:33:11 -07002684 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002685 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686
2687 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2689
2690 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2691 // and answer;
2692 SetLocalDescriptionWithoutError(offer);
2693 SetRemoteDescriptionWithoutError(answer);
2694
2695 video_channel_ = media_engine_->GetVideoChannel(0);
2696 voice_channel_ = media_engine_->GetVoiceChannel(0);
2697
2698 ASSERT_TRUE(video_channel_ == NULL);
2699
2700 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2701 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2702 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2703
2704 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002705 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 CreateAndSetRemoteOfferAndLocalAnswer();
2707
2708 video_channel_ = media_engine_->GetVideoChannel(0);
2709 voice_channel_ = media_engine_->GetVoiceChannel(0);
2710
2711 ASSERT_TRUE(video_channel_ != NULL);
2712 ASSERT_TRUE(voice_channel_ != NULL);
2713
2714 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2715 ASSERT_EQ(1u, video_channel_->send_streams().size());
2716 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2717 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2718 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2719 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2720 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2721 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2722
2723 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002724 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 CreateAndSetRemoteOfferAndLocalAnswer();
2726
2727 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2728 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2729 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2730 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2731 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2732}
2733
2734// This test verifies the call setup when remote answer with video only and
2735// later updates with audio.
2736TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002737 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2739 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002740 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002741 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742
2743 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002744 options.recv_audio = false;
2745 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2747 offer, options, cricket::SEC_ENABLED);
2748
2749 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2750 // and answer.
2751 SetLocalDescriptionWithoutError(offer);
2752 SetRemoteDescriptionWithoutError(answer);
2753
2754 video_channel_ = media_engine_->GetVideoChannel(0);
2755 voice_channel_ = media_engine_->GetVoiceChannel(0);
2756
2757 ASSERT_TRUE(voice_channel_ == NULL);
2758 ASSERT_TRUE(video_channel_ != NULL);
2759
2760 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2761 ASSERT_EQ(1u, video_channel_->send_streams().size());
2762 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2763
2764 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002765 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 CreateAndSetRemoteOfferAndLocalAnswer();
2767
2768 voice_channel_ = media_engine_->GetVoiceChannel(0);
2769 ASSERT_TRUE(voice_channel_ != NULL);
2770
2771 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2772 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2773 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2774 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2775
2776 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002777 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778 CreateAndSetRemoteOfferAndLocalAnswer();
2779
2780 video_channel_ = media_engine_->GetVideoChannel(0);
2781 voice_channel_ = media_engine_->GetVoiceChannel(0);
2782
2783 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2784 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2785 ASSERT_EQ(1u, video_channel_->send_streams().size());
2786 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2787}
2788
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002789TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002790 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002791 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002792 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793 VerifyCryptoParams(offer->description());
2794 SetRemoteDescriptionWithoutError(offer.release());
htaa2a49d92016-03-04 02:51:39 -08002795 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796 VerifyCryptoParams(answer->description());
2797}
2798
2799TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002800 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002801 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002802 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002803 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804 VerifyNoCryptoParams(offer->description(), false);
2805}
2806
2807TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002808 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809 VerifyAnswerFromNonCryptoOffer();
2810}
2811
2812TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002813 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 VerifyAnswerFromCryptoOffer();
2815}
2816
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002817// This test verifies that setLocalDescription fails if
2818// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2819TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002820 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002821 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002822 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2823
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002824 std::string sdp;
2825 RemoveIceUfragPwdLines(offer.get(), &sdp);
2826 SessionDescriptionInterface* modified_offer =
2827 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002828 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002829}
2830
2831// This test verifies that setRemoteDescription fails if
2832// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2833TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002834 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002835 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002836 std::string sdp;
2837 RemoveIceUfragPwdLines(offer.get(), &sdp);
2838 SessionDescriptionInterface* modified_offer =
2839 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002840 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002841}
2842
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002843// This test verifies that setLocalDescription fails if local offer has
2844// too short ice ufrag and pwd strings.
2845TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002846 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002847 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002848 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002849 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2850 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002851 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002852 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002853 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002854
2855 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002856 offer.reset(CreateOffer());
2857 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2858 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002859}
2860
2861// This test verifies that setRemoteDescription fails if remote offer has
2862// too short ice ufrag and pwd strings.
2863TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002864 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002865 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002866 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2867 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002868 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002869 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002870 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002871
deadbeef0ed85b22016-02-23 17:24:52 -08002872 offer.reset(CreateRemoteOffer());
2873 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2874 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002875}
2876
Honghai Zhang04e91462015-12-11 14:26:22 -08002877// Test that if the remote offer indicates the peer requested ICE restart (via
2878// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2879TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002880 Init();
honghaiz503726c2015-07-31 12:37:38 -07002881
2882 // Create the first offer.
deadbeef0ed85b22016-02-23 17:24:52 -08002883 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2884 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002885 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2886 0, "", "", "relay", 0, "");
2887 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2888 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002889 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2890 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002891 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2892
2893 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002894 offer.reset(CreateRemoteOffer());
2895 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002896 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2897 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2898 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002899 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2900 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002901 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2902
2903 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002904 offer.reset(CreateRemoteOffer());
2905 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002906 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2907 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2908 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002909 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2910 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002911 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2912
2913 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002914 offer.reset(CreateRemoteOffer());
2915 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2916 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002917 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2918}
2919
Honghai Zhang04e91462015-12-11 14:26:22 -08002920// Test that if the remote answer indicates the peer requested ICE restart (via
2921// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2922TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2923 Init();
2924 SessionDescriptionInterface* offer = CreateOffer();
2925 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002926
2927 // Create the first answer.
deadbeef0ed85b22016-02-23 17:24:52 -08002928 scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
2929 answer->set_type(JsepSessionDescription::kPrAnswer);
2930 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002931 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2932 0, "", "", "relay", 0, "");
2933 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2934 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002935 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2936 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002937 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2938
2939 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002940 answer.reset(CreateRemoteAnswer(offer));
2941 answer->set_type(JsepSessionDescription::kPrAnswer);
2942 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002943 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2944 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2945 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002946 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2947 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002948 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2949
2950 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002951 answer.reset(CreateRemoteAnswer(offer));
2952 answer->set_type(JsepSessionDescription::kPrAnswer);
2953 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002954 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2955 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2956 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002957 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2958 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002959 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2960
2961 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002962 answer.reset(CreateRemoteAnswer(offer));
2963 answer->set_type(JsepSessionDescription::kPrAnswer);
2964 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2965 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002966 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2967}
2968
Donald Curtisd4f769d2015-05-28 09:48:21 -07002969// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002970// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002971TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2972 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2973
2974 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002975 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002976
2977 PeerConnectionInterface::RTCOfferAnswerOptions options;
2978 options.use_rtp_mux = true;
2979
2980 SessionDescriptionInterface* offer = CreateRemoteOffer();
2981 SetRemoteDescriptionWithoutError(offer);
2982
htaa2a49d92016-03-04 02:51:39 -08002983 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002984 SetLocalDescriptionWithoutError(answer);
2985
deadbeefcbecd352015-09-23 11:50:27 -07002986 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2987 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002988
deadbeefcbecd352015-09-23 11:50:27 -07002989 cricket::BaseChannel* voice_channel = session_->voice_channel();
2990 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002991
2992 // Checks if one of the transport channels contains a connection using a given
2993 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002994 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002995 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002996 session_->GetChannelTransportStats(voice_channel, &stats);
2997 for (auto& kv : stats.transport_stats) {
2998 for (auto& chan_stat : kv.second.channel_stats) {
2999 for (auto& conn_info : chan_stat.connection_infos) {
3000 if (conn_info.remote_candidate.address().port() == port) {
3001 return true;
3002 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003003 }
3004 }
3005 }
3006 return false;
3007 };
3008
3009 EXPECT_FALSE(connection_with_remote_port(5000));
3010 EXPECT_FALSE(connection_with_remote_port(5001));
3011 EXPECT_FALSE(connection_with_remote_port(6000));
3012
3013 // The way the *_WAIT checks work is they only wait if the condition fails,
3014 // which does not help in the case where state is not changing. This is
3015 // problematic in this test since we want to verify that adding a video
3016 // candidate does _not_ change state. So we interleave candidates and assume
3017 // that messages are executed in the order they were posted.
3018
3019 // First audio candidate.
3020 cricket::Candidate candidate0;
3021 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3022 candidate0.set_component(1);
3023 candidate0.set_protocol("udp");
3024 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3025 candidate0);
3026 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3027
3028 // Video candidate.
3029 cricket::Candidate candidate1;
3030 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3031 candidate1.set_component(1);
3032 candidate1.set_protocol("udp");
3033 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3034 candidate1);
3035 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3036
3037 // Second audio candidate.
3038 cricket::Candidate candidate2;
3039 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3040 candidate2.set_component(1);
3041 candidate2.set_protocol("udp");
3042 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3043 candidate2);
3044 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3045
3046 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3047 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3048
3049 // No need here for a _WAIT check since we are checking that state hasn't
3050 // changed: if this is false we would be doing waits for nothing and if this
3051 // is true then there will be no messages processed anyways.
3052 EXPECT_FALSE(connection_with_remote_port(6000));
3053}
3054
deadbeefcbecd352015-09-23 11:50:27 -07003055// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003056TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3057 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003058 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003059
3060 PeerConnectionInterface::RTCOfferAnswerOptions options;
3061 options.use_rtp_mux = true;
3062
3063 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003064 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003065
deadbeefcbecd352015-09-23 11:50:27 -07003066 EXPECT_NE(session_->voice_rtp_transport_channel(),
3067 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003068
deadbeefab9b2d12015-10-14 11:33:11 -07003069 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003070 SessionDescriptionInterface* answer =
3071 CreateRemoteAnswer(session_->local_description());
3072 SetRemoteDescriptionWithoutError(answer);
3073
deadbeefcbecd352015-09-23 11:50:27 -07003074 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3075 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003076}
3077
deadbeefcbecd352015-09-23 11:50:27 -07003078// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003079TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3080 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003081 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003082
Donald Curtis0e209b02015-03-24 09:29:54 -07003083 PeerConnectionInterface::RTCOfferAnswerOptions options;
3084 options.use_rtp_mux = true;
3085
3086 SessionDescriptionInterface* offer = CreateOffer(options);
3087 SetLocalDescriptionWithoutError(offer);
3088
deadbeefcbecd352015-09-23 11:50:27 -07003089 EXPECT_NE(session_->voice_rtp_transport_channel(),
3090 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003091
deadbeefab9b2d12015-10-14 11:33:11 -07003092 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003093
3094 // Remove BUNDLE from the answer.
3095 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3096 CreateRemoteAnswer(session_->local_description()));
3097 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3098 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3099 JsepSessionDescription* modified_answer =
3100 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3101 modified_answer->Initialize(answer_copy, "1", "1");
3102 SetRemoteDescriptionWithoutError(modified_answer); //
3103
deadbeefcbecd352015-09-23 11:50:27 -07003104 EXPECT_NE(session_->voice_rtp_transport_channel(),
3105 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003106}
3107
3108// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3109TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3110 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003111 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003112
3113 PeerConnectionInterface::RTCOfferAnswerOptions options;
3114 options.use_rtp_mux = true;
3115
3116 SessionDescriptionInterface* offer = CreateOffer(options);
3117 SetLocalDescriptionWithoutError(offer);
3118
deadbeefcbecd352015-09-23 11:50:27 -07003119 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3120 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003121
deadbeefab9b2d12015-10-14 11:33:11 -07003122 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003123 SessionDescriptionInterface* answer =
3124 CreateRemoteAnswer(session_->local_description());
3125 SetRemoteDescriptionWithoutError(answer);
3126
deadbeefcbecd352015-09-23 11:50:27 -07003127 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3128 session_->video_rtp_transport_channel());
3129}
3130
3131// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3132// audio content in the answer.
3133TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3134 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003135 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003136
3137 PeerConnectionInterface::RTCOfferAnswerOptions options;
3138 options.use_rtp_mux = true;
3139
3140 SessionDescriptionInterface* offer = CreateOffer(options);
3141 SetLocalDescriptionWithoutError(offer);
3142
3143 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3144 session_->video_rtp_transport_channel());
3145
deadbeefab9b2d12015-10-14 11:33:11 -07003146 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003147 cricket::MediaSessionOptions recv_options;
3148 recv_options.recv_audio = false;
3149 recv_options.recv_video = true;
3150 SessionDescriptionInterface* answer =
3151 CreateRemoteAnswer(session_->local_description(), recv_options);
3152 SetRemoteDescriptionWithoutError(answer);
3153
deadbeefd59daf82015-10-14 15:02:44 -07003154 EXPECT_TRUE(nullptr == session_->voice_channel());
3155 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003156
deadbeefd59daf82015-10-14 15:02:44 -07003157 session_->Close();
3158 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3159 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3160 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3161 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003162}
3163
3164// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3165TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3166 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003167 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003168
Donald Curtis0e209b02015-03-24 09:29:54 -07003169 PeerConnectionInterface::RTCOfferAnswerOptions options;
3170 options.use_rtp_mux = true;
3171
3172 SessionDescriptionInterface* offer = CreateOffer(options);
3173 SetLocalDescriptionWithoutError(offer);
3174
deadbeefcbecd352015-09-23 11:50:27 -07003175 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3176 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003177
deadbeefab9b2d12015-10-14 11:33:11 -07003178 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003179
3180 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003181 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182 CreateRemoteAnswer(session_->local_description()));
3183 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3184 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3185 JsepSessionDescription* modified_answer =
3186 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3187 modified_answer->Initialize(answer_copy, "1", "1");
3188 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189
deadbeefcbecd352015-09-23 11:50:27 -07003190 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3191 session_->video_rtp_transport_channel());
3192}
3193
3194// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3195TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3196 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003197 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003198
3199 SessionDescriptionInterface* offer = CreateRemoteOffer();
3200 SetRemoteDescriptionWithoutError(offer);
3201
3202 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3203 session_->video_rtp_transport_channel());
3204
deadbeefab9b2d12015-10-14 11:33:11 -07003205 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003206 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003207 SetLocalDescriptionWithoutError(answer);
3208
3209 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3210 session_->video_rtp_transport_channel());
3211}
3212
3213// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3214TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3215 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003216 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003217
3218 // Remove BUNDLE from the offer.
3219 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3220 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3221 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3222 JsepSessionDescription* modified_offer =
3223 new JsepSessionDescription(JsepSessionDescription::kOffer);
3224 modified_offer->Initialize(offer_copy, "1", "1");
3225
3226 // Expect an error when applying the remote description
3227 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3228 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003229}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230
Peter Thatcher4eddf182015-04-30 10:55:59 -07003231// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003232TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3233 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235
Donald Curtis0e209b02015-03-24 09:29:54 -07003236 PeerConnectionInterface::RTCOfferAnswerOptions options;
3237 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238
Donald Curtis0e209b02015-03-24 09:29:54 -07003239 SessionDescriptionInterface* offer = CreateOffer(options);
3240 SetLocalDescriptionWithoutError(offer);
3241
deadbeefcbecd352015-09-23 11:50:27 -07003242 EXPECT_NE(session_->voice_rtp_transport_channel(),
3243 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003244
deadbeefab9b2d12015-10-14 11:33:11 -07003245 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003246 SessionDescriptionInterface* answer =
3247 CreateRemoteAnswer(session_->local_description());
3248 SetRemoteDescriptionWithoutError(answer);
3249
3250 // This should lead to an audio-only call but isn't implemented
3251 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003252 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3253 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003254}
3255
deadbeefcbecd352015-09-23 11:50:27 -07003256// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003257TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3258 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003259 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003260 PeerConnectionInterface::RTCOfferAnswerOptions options;
3261 options.use_rtp_mux = true;
3262
3263 SessionDescriptionInterface* offer = CreateOffer(options);
3264 SetLocalDescriptionWithoutError(offer);
3265
deadbeefcbecd352015-09-23 11:50:27 -07003266 EXPECT_NE(session_->voice_rtp_transport_channel(),
3267 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003268
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003270
3271 // Remove BUNDLE from the answer.
3272 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3273 CreateRemoteAnswer(session_->local_description()));
3274 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3275 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3276 JsepSessionDescription* modified_answer =
3277 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3278 modified_answer->Initialize(answer_copy, "1", "1");
3279 SetRemoteDescriptionWithoutError(modified_answer); //
3280
deadbeefcbecd352015-09-23 11:50:27 -07003281 EXPECT_NE(session_->voice_rtp_transport_channel(),
3282 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283}
3284
Peter Thatcher4eddf182015-04-30 10:55:59 -07003285// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3286TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3287 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003288 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003289
3290 PeerConnectionInterface::RTCOfferAnswerOptions options;
3291 options.use_rtp_mux = true;
3292
3293 SessionDescriptionInterface* offer = CreateOffer(options);
3294 SetRemoteDescriptionWithoutError(offer);
3295
deadbeefcbecd352015-09-23 11:50:27 -07003296 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3297 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003298}
3299
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003300TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3301 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
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
3320TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3321 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003322 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003323
3324 PeerConnectionInterface::RTCOfferAnswerOptions options;
3325 SessionDescriptionInterface* offer = CreateOffer(options);
3326 SetLocalDescriptionWithoutError(offer);
3327
deadbeefcbecd352015-09-23 11:50:27 -07003328 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3329 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003330
deadbeefab9b2d12015-10-14 11:33:11 -07003331 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003332 SessionDescriptionInterface* answer =
3333 CreateRemoteAnswer(session_->local_description());
3334 SetRemoteDescriptionWithoutError(answer);
3335
deadbeefcbecd352015-09-23 11:50:27 -07003336 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3337 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003338}
3339
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003340// This test verifies that SetLocalDescription and SetRemoteDescription fails
3341// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3342TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003343 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003344 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003345
3346 PeerConnectionInterface::RTCOfferAnswerOptions options;
3347 options.use_rtp_mux = true;
3348
3349 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003350 std::string offer_str;
3351 offer->ToString(&offer_str);
3352 // Disable rtcp-mux
3353 const std::string rtcp_mux = "rtcp-mux";
3354 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003355 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003356 xrtcp_mux.c_str(), xrtcp_mux.length(),
3357 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003358 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003359 new JsepSessionDescription(JsepSessionDescription::kOffer);
3360 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003361 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003362 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003363 new JsepSessionDescription(JsepSessionDescription::kOffer);
3364 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003365 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003366 // Trying unmodified SDP.
3367 SetLocalDescriptionWithoutError(offer);
3368}
3369
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003371 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003372 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003373 CreateAndSetRemoteOfferAndLocalAnswer();
3374 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3375 ASSERT_TRUE(channel != NULL);
3376 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003377 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003378 double volume;
3379 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3380 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003381 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003382 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3383 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003384 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003385 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3386 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387}
3388
skvlade0d46372016-04-07 22:59:22 -07003389TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003390 Init();
3391 SendAudioVideoStream1();
3392 CreateAndSetRemoteOfferAndLocalAnswer();
3393 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3394 ASSERT_TRUE(channel != NULL);
3395 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003396 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003397 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003398 EXPECT_EQ(1, params.encodings.size());
3399 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3400 params.encodings[0].max_bitrate_bps = 1000;
3401 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003402
skvlade0d46372016-04-07 22:59:22 -07003403 // Read back the parameters and verify they have been changed.
3404 params = session_->GetAudioRtpParameters(send_ssrc);
3405 EXPECT_EQ(1, params.encodings.size());
3406 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3407
3408 // Verify that the audio channel received the new parameters.
3409 params = channel->GetRtpParameters(send_ssrc);
3410 EXPECT_EQ(1, params.encodings.size());
3411 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3412
3413 // Verify that the global bitrate limit has not been changed.
3414 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003415}
3416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003418 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003419 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 CreateAndSetRemoteOfferAndLocalAnswer();
3421 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3422 ASSERT_TRUE(channel != NULL);
3423 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003424 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3426
3427 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003428 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003430 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
3431 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003433 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003434 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003436 // This will trigger SetSink(nullptr) to the |source|.
3437 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003439 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003440 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003441}
3442
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003443TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003444 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003445 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003446 CreateAndSetRemoteOfferAndLocalAnswer();
3447 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3448 ASSERT_TRUE(channel != NULL);
3449 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003450 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003451
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003452 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003453 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003454 session_->SetAudioSend(send_ssrc, true, options, source.get());
3455 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003456
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003457 // Delete the |source| and it will trigger OnClose() to the sink, and this
3458 // will invalidate the |source_| pointer in the sink and prevent getting a
3459 // SetSink(nullptr) callback afterwards.
3460 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003461
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003462 // This will trigger SetSink(nullptr) if no OnClose() callback.
3463 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464}
3465
3466TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003467 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003468 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469 CreateAndSetRemoteOfferAndLocalAnswer();
3470 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3471 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003472 ASSERT_LT(0u, channel->sinks().size());
3473 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003475 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 cricket::FakeVideoRenderer renderer;
3477 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003478 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003480 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481}
3482
skvladdc1c62c2016-03-16 19:07:43 -07003483TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3484 Init();
3485 SendAudioVideoStream1();
3486 CreateAndSetRemoteOfferAndLocalAnswer();
3487 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3488 ASSERT_TRUE(channel != NULL);
3489 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3490 EXPECT_EQ(-1, channel->max_bps());
3491 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3492 EXPECT_EQ(1, params.encodings.size());
3493 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3494 params.encodings[0].max_bitrate_bps = 1000;
3495 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3496
3497 // Read back the parameters and verify they have been changed.
3498 params = session_->GetVideoRtpParameters(send_ssrc);
3499 EXPECT_EQ(1, params.encodings.size());
3500 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3501
3502 // Verify that the video channel received the new parameters.
3503 params = channel->GetRtpParameters(send_ssrc);
3504 EXPECT_EQ(1, params.encodings.size());
3505 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3506
3507 // Verify that the global bitrate limit has not been changed.
3508 EXPECT_EQ(-1, channel->max_bps());
3509}
3510
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003512 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003513 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 CreateAndSetRemoteOfferAndLocalAnswer();
3515 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3516 ASSERT_TRUE(channel != NULL);
3517 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003518 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003519 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3520 cricket::VideoOptions* options = NULL;
3521 session_->SetVideoSend(send_ssrc, false, options);
3522 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3523 session_->SetVideoSend(send_ssrc, true, options);
3524 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3525}
3526
3527TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3528 TestCanInsertDtmf(false);
3529}
3530
3531TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3532 TestCanInsertDtmf(true);
3533}
3534
3535TEST_F(WebRtcSessionTest, InsertDtmf) {
3536 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003537 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003538 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 CreateAndSetRemoteOfferAndLocalAnswer();
3540 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3541 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3542
3543 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 const int expected_duration = 90;
3545 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3546 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3547 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3548
3549 // Verify
3550 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003551 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003553 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003555 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003557 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558}
3559
deadbeefd59daf82015-10-14 15:02:44 -07003560// This test verifies the |initial_offerer| flag when session initiates the
3561// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003563 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003564 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003565 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3567 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003568 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003569 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003570 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571}
3572
deadbeefd59daf82015-10-14 15:02:44 -07003573// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003575 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003576 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 SessionDescriptionInterface* offer = CreateRemoteOffer();
3578 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003579 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
deadbeefd59daf82015-10-14 15:02:44 -07003581 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003583 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003584}
3585
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3587TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003588 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003589 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003590 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003592 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593 CreateRemoteAnswer(session_->local_description()));
3594
3595 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3596 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003597 JsepSessionDescription* modified_answer =
3598 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599
3600 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3601 answer->session_id(),
3602 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003603 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003604
wu@webrtc.org4e393072014-04-07 17:04:35 +00003605 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 std::string sdp;
3607 EXPECT_TRUE(answer->ToString(&sdp));
3608 const std::string kAudioMid = "a=mid:audio";
3609 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003610 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611 kAudioMidReplaceStr.c_str(),
3612 kAudioMidReplaceStr.length(),
3613 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003614 SessionDescriptionInterface* modified_answer1 =
3615 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003616 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617
wu@webrtc.org4e393072014-04-07 17:04:35 +00003618 // Different media types.
3619 EXPECT_TRUE(answer->ToString(&sdp));
3620 const std::string kAudioMline = "m=audio";
3621 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003622 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003623 kAudioMlineReplaceStr.c_str(),
3624 kAudioMlineReplaceStr.length(),
3625 &sdp);
3626 SessionDescriptionInterface* modified_answer2 =
3627 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3628 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3629
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630 SetRemoteDescriptionWithoutError(answer.release());
3631}
3632
3633// Verifying remote offer and local answer have matching m-lines as per
3634// RFC 3264.
3635TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003636 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003637 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638 SessionDescriptionInterface* offer = CreateRemoteOffer();
3639 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003640 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641
3642 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3643 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003644 JsepSessionDescription* modified_answer =
3645 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003646
3647 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3648 answer->session_id(),
3649 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003650 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651 SetLocalDescriptionWithoutError(answer);
3652}
3653
3654// This test verifies that WebRtcSession does not start candidate allocation
3655// before SetLocalDescription is called.
3656TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003657 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003658 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 SessionDescriptionInterface* offer = CreateRemoteOffer();
3660 cricket::Candidate candidate;
3661 candidate.set_component(1);
3662 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3663 candidate);
3664 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3665 cricket::Candidate candidate1;
3666 candidate1.set_component(1);
3667 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3668 candidate1);
3669 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3670 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003671 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3672 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673
3674 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003675 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3677 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3678
htaa2a49d92016-03-04 02:51:39 -08003679 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003681 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3682}
3683
3684// This test verifies that crypto parameter is updated in local session
3685// description as per security policy set in MediaSessionDescriptionFactory.
3686TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003687 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003688 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003689 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690
3691 // Making sure SetLocalDescription correctly sets crypto value in
3692 // SessionDescription object after de-serialization of sdp string. The value
3693 // will be set as per MediaSessionDescriptionFactory.
3694 std::string offer_str;
3695 offer->ToString(&offer_str);
3696 SessionDescriptionInterface* jsep_offer_str =
3697 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3698 SetLocalDescriptionWithoutError(jsep_offer_str);
3699 EXPECT_TRUE(session_->voice_channel()->secure_required());
3700 EXPECT_TRUE(session_->video_channel()->secure_required());
3701}
3702
3703// This test verifies the crypto parameter when security is disabled.
3704TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003705 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003706 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003707 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003708 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709
3710 // Making sure SetLocalDescription correctly sets crypto value in
3711 // SessionDescription object after de-serialization of sdp string. The value
3712 // will be set as per MediaSessionDescriptionFactory.
3713 std::string offer_str;
3714 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003715 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3717 SetLocalDescriptionWithoutError(jsep_offer_str);
3718 EXPECT_FALSE(session_->voice_channel()->secure_required());
3719 EXPECT_FALSE(session_->video_channel()->secure_required());
3720}
3721
3722// This test verifies that an answer contains new ufrag and password if an offer
3723// with new ufrag and password is received.
3724TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003725 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003727 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003728 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003729 CreateRemoteOffer(options));
3730 SetRemoteDescriptionWithoutError(offer.release());
3731
deadbeefab9b2d12015-10-14 11:33:11 -07003732 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003733 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734 SetLocalDescriptionWithoutError(answer.release());
3735
3736 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003737 for (const cricket::ContentInfo& content :
3738 session_->local_description()->description()->contents()) {
3739 options.transport_options[content.name].ice_restart = true;
3740 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003741 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003742 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 SetRemoteDescriptionWithoutError(updated_offer1.release());
3744
htaa2a49d92016-03-04 02:51:39 -08003745 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
deadbeef0ed85b22016-02-23 17:24:52 -08003747 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3748 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749
deadbeef0ed85b22016-02-23 17:24:52 -08003750 // Even a second answer (created before the description is set) should have
3751 // a new ufrag/password.
htaa2a49d92016-03-04 02:51:39 -08003752 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003753
3754 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3755 session_->local_description()->description()));
3756
3757 SetLocalDescriptionWithoutError(updated_answer2.release());
3758}
3759
3760// This test verifies that an answer contains new ufrag and password if an offer
3761// that changes either the ufrag or password (but not both) is received.
3762// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3763// a=ice-pwd attributes compared to the previous SDP from the peer, it
3764// indicates that ICE is restarting for this media stream."
3765TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3766 Init();
3767 cricket::MediaSessionOptions options;
3768 options.recv_audio = true;
3769 options.recv_video = true;
3770 // Create an offer with audio and video.
3771 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3772 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3773 SetRemoteDescriptionWithoutError(offer.release());
3774
3775 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003776 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003777 SetLocalDescriptionWithoutError(answer.release());
3778
3779 // Receive an offer with a new ufrag but stale password.
3780 rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer(
3781 CreateRemoteOffer(options, session_->remote_description()));
3782 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3783 "original_password12345");
3784 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3785
htaa2a49d92016-03-04 02:51:39 -08003786 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003787 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3788 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003789 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003790
3791 // Receive an offer with a new password but stale ufrag.
3792 rtc::scoped_ptr<JsepSessionDescription> password_changed_offer(
3793 CreateRemoteOffer(options, session_->remote_description()));
3794 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3795 "modified_password12345");
3796 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3797
htaa2a49d92016-03-04 02:51:39 -08003798 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003799 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3800 session_->local_description()->description()));
3801 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003802}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003803
wu@webrtc.org91053e72013-08-10 07:18:04 +00003804// This test verifies that an answer contains old ufrag and password if an offer
3805// with old ufrag and password is received.
3806TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003807 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003808 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003809 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003810 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003811 CreateRemoteOffer(options));
3812 SetRemoteDescriptionWithoutError(offer.release());
3813
deadbeefab9b2d12015-10-14 11:33:11 -07003814 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003815 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003816 SetLocalDescriptionWithoutError(answer.release());
3817
3818 // Receive an offer without changed ufrag or password.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003820 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003821 SetRemoteDescriptionWithoutError(updated_offer2.release());
3822
htaa2a49d92016-03-04 02:51:39 -08003823 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003824
deadbeef0ed85b22016-02-23 17:24:52 -08003825 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3826 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003827
3828 SetLocalDescriptionWithoutError(updated_answer2.release());
3829}
3830
deadbeef0ed85b22016-02-23 17:24:52 -08003831// This test verifies that if an offer does an ICE restart on some, but not all
3832// media sections, the answer will change the ufrag/password in the correct
3833// media sections.
3834TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3835 Init();
3836 cricket::MediaSessionOptions options;
3837 options.recv_video = true;
3838 options.recv_audio = true;
3839 options.bundle_enabled = false;
3840 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
3841
3842 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3843 "aaaaaaaaaaaaaaaaaaaaaa");
3844 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3845 "bbbbbbbbbbbbbbbbbbbbbb");
3846 SetRemoteDescriptionWithoutError(offer.release());
3847
3848 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08003849 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003850 SetLocalDescriptionWithoutError(answer.release());
3851
3852 // Receive an offer with new ufrag and password, but only for the video media
3853 // section.
3854 rtc::scoped_ptr<JsepSessionDescription> updated_offer(
3855 CreateRemoteOffer(options, session_->remote_description()));
3856 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3857 "cccccccccccccccccccccc");
3858 SetRemoteDescriptionWithoutError(updated_offer.release());
3859
htaa2a49d92016-03-04 02:51:39 -08003860 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003861
3862 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3863 session_->local_description()->description(),
3864 cricket::MEDIA_TYPE_AUDIO));
3865
3866 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3867 session_->local_description()->description(),
3868 cricket::MEDIA_TYPE_VIDEO));
3869
3870 SetLocalDescriptionWithoutError(updated_answer.release());
3871}
3872
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003873TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003874 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003875 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003876 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003877 const std::string session_id_orig = offer->session_id();
3878 const std::string session_version_orig = offer->session_version();
3879 SetLocalDescriptionWithoutError(offer);
3880
3881 video_channel_ = media_engine_->GetVideoChannel(0);
3882 video_channel_->set_fail_set_send_codecs(true);
3883
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003884 SessionDescriptionInterface* answer =
3885 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003886 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003887
3888 // Test that after a content error, setting any description will
3889 // result in an error.
3890 video_channel_->set_fail_set_send_codecs(false);
3891 answer = CreateRemoteAnswer(session_->local_description());
3892 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3893 offer = CreateRemoteOffer();
3894 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003895}
3896
3897// Runs the loopback call test with BUNDLE and STUN disabled.
3898TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3899 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003900 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003901 cricket::PORTALLOCATOR_DISABLE_STUN |
3902 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003903 TestLoopbackCall();
3904}
3905
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003906TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003907 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003908 cricket::PORTALLOCATOR_DISABLE_STUN |
3909 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3910 cricket::PORTALLOCATOR_DISABLE_RELAY);
3911
3912 // best connection is IPv6 since it has higher network preference.
3913 LoopbackNetworkConfiguration config;
3914 config.test_ipv6_network_ = true;
3915 config.best_connection_after_initial_ice_converged_ =
3916 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3917
3918 TestLoopbackCall(config);
3919}
3920
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003921// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003922TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003923 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3924 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003925 TestLoopbackCall();
3926}
3927
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003928TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003929 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003930 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003931 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003932 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003933 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3934}
3935
Henrik Boström87713d02015-08-25 09:53:21 +02003936TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003937 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003938
htaa2a49d92016-03-04 02:51:39 -08003939 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003940 options_.disable_sctp_data_channels = false;
3941
Henrik Boström87713d02015-08-25 09:53:21 +02003942 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003943
3944 SetLocalDescriptionWithDataChannel();
3945 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3946}
3947
Henrik Boström87713d02015-08-25 09:53:21 +02003948TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003949 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003950
Henrik Boström87713d02015-08-25 09:53:21 +02003951 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003952
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003953 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003954 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003955 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3956}
3957
Henrik Boström87713d02015-08-25 09:53:21 +02003958TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003959 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003960 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003961 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003962
3963 // Create remote offer with SCTP.
3964 cricket::MediaSessionOptions options;
3965 options.data_channel_type = cricket::DCT_SCTP;
3966 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003967 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003968 SetRemoteDescriptionWithoutError(offer);
3969
3970 // Verifies the answer contains SCTP.
htaa2a49d92016-03-04 02:51:39 -08003971 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003972 EXPECT_TRUE(answer != NULL);
3973 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3974 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003975}
3976
Henrik Boström87713d02015-08-25 09:53:21 +02003977TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003978 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003979 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003980
3981 SetLocalDescriptionWithDataChannel();
3982 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3983}
3984
Henrik Boström87713d02015-08-25 09:53:21 +02003985TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003986 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003987
Henrik Boström87713d02015-08-25 09:53:21 +02003988 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003989
3990 SetLocalDescriptionWithDataChannel();
3991 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3992}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003993
Henrik Boström87713d02015-08-25 09:53:21 +02003994TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003995 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003996 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003997 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003998
3999 SetLocalDescriptionWithDataChannel();
4000 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4001}
4002
Henrik Boström87713d02015-08-25 09:53:21 +02004003TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004004 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004005 const int new_send_port = 9998;
4006 const int new_recv_port = 7775;
4007
Henrik Boström87713d02015-08-25 09:53:21 +02004008 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004009 SetFactoryDtlsSrtp();
4010
4011 // By default, don't actually add the codecs to desc_factory_; they don't
4012 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4013 // let the session description get parsed. That'll get the proper codecs
4014 // into the stream.
4015 cricket::MediaSessionOptions options;
4016 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4017 "stream1", new_send_port, options);
4018
4019 // SetRemoteDescription will take the ownership of the offer.
4020 SetRemoteDescriptionWithoutError(offer);
4021
htaa2a49d92016-03-04 02:51:39 -08004022 SessionDescriptionInterface* answer =
4023 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004024 ASSERT_TRUE(answer != NULL);
4025
4026 // Now set the local description, which'll take ownership of the answer.
4027 SetLocalDescriptionWithoutError(answer);
4028
4029 // TEST PLAN: Set the port number to something new, set it in the SDP,
4030 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004031 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004032 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004033
4034 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4035 int portnum = -1;
4036 ASSERT_TRUE(ch != NULL);
4037 ASSERT_EQ(1UL, ch->send_codecs().size());
4038 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004039 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004040 ch->send_codecs()[0].name.c_str()));
4041 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4042 &portnum));
4043 EXPECT_EQ(new_send_port, portnum);
4044
4045 ASSERT_EQ(1UL, ch->recv_codecs().size());
4046 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004047 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004048 ch->recv_codecs()[0].name.c_str()));
4049 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4050 &portnum));
4051 EXPECT_EQ(new_recv_port, portnum);
4052}
4053
deadbeefab9b2d12015-10-14 11:33:11 -07004054// Verifies that when a session's DataChannel receives an OPEN message,
4055// WebRtcSession signals the DataChannel creation request with the expected
4056// config.
4057TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4058 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4059
4060 InitWithDtls(GetParam());
4061
4062 SetLocalDescriptionWithDataChannel();
4063 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4064
4065 webrtc::DataChannelInit config;
4066 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004067 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004068 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4069 cricket::ReceiveDataParams params;
4070 params.ssrc = config.id;
4071 params.type = cricket::DMT_CONTROL;
4072
4073 cricket::DataChannel* data_channel = session_->data_channel();
4074 data_channel->SignalDataReceived(data_channel, params, payload);
4075
4076 EXPECT_EQ("a", last_data_channel_label_);
4077 EXPECT_EQ(config.id, last_data_channel_config_.id);
4078 EXPECT_FALSE(last_data_channel_config_.negotiated);
4079 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4080 last_data_channel_config_.open_handshake_role);
4081}
4082
4083TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004084 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4085 FakeDtlsIdentityStore::GenerateCertificate();
4086
htaa2a49d92016-03-04 02:51:39 -08004087 configuration_.certificates.push_back(certificate);
4088 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004089 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4090
4091 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4092}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004093
Henrik Boström87713d02015-08-25 09:53:21 +02004094// Verifies that CreateOffer succeeds when CreateOffer is called before async
4095// identity generation is finished (even if a certificate is provided this is
4096// an async op).
4097TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4098 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4099 InitWithDtls(GetParam());
4100
Henrik Boströmd8281982015-08-27 10:12:24 +02004101 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004102 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004103 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
4104
wu@webrtc.org91053e72013-08-10 07:18:04 +00004105 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004106 VerifyNoCryptoParams(offer->description(), true);
4107 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004108}
4109
4110// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004111// identity generation is finished (even if a certificate is provided this is
4112// an async op).
4113TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004114 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004115 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004116 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004117
4118 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004119 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004121 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004122 ASSERT_TRUE(offer.get() != NULL);
4123 SetRemoteDescriptionWithoutError(offer.release());
4124
htaa2a49d92016-03-04 02:51:39 -08004125 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004126 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004127 VerifyNoCryptoParams(answer->description(), true);
4128 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004129}
4130
4131// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004132// identity generation is finished (even if a certificate is provided this is
4133// an async op).
4134TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004135 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004136 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004137
Henrik Boströmd8281982015-08-27 10:12:24 +02004138 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004139
4140 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141 EXPECT_TRUE(offer != NULL);
4142}
4143
4144// Verifies that CreateOffer fails when CreateOffer is called after async
4145// identity generation fails.
4146TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004147 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004148 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004149
Henrik Boströmd8281982015-08-27 10:12:24 +02004150 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004151
4152 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004153 EXPECT_TRUE(offer == NULL);
4154}
4155
4156// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4157// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004158TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004159 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004160 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004161 VerifyMultipleAsyncCreateDescription(GetParam(),
4162 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004163}
4164
4165// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4166// before async identity generation fails.
4167TEST_F(WebRtcSessionTest,
4168 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004169 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004170 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4171 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004172}
4173
4174// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4175// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004176TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004177 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004178 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004179 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004180 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004181}
4182
4183// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4184// before async identity generation fails.
4185TEST_F(WebRtcSessionTest,
4186 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004187 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004188 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4189 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004190}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004191
4192// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4193// offer has no SDES crypto but only DTLS fingerprint.
4194TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4195 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004196 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004197 // Create a remote offer with secured transport disabled.
4198 cricket::MediaSessionOptions options;
4199 JsepSessionDescription* offer(CreateRemoteOffer(
4200 options, cricket::SEC_DISABLED));
4201 // Adds a DTLS fingerprint to the remote offer.
4202 cricket::SessionDescription* sdp = offer->description();
4203 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4204 ASSERT_TRUE(audio != NULL);
4205 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4206 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004207 rtc::SSLFingerprint::CreateFromRfc4572(
4208 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004209 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004210 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004211}
4212
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004213TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004214 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004215 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004216 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004217 SessionDescriptionInterface* offer = CreateOffer();
4218
4219 SetLocalDescriptionWithoutError(offer);
4220
4221 voice_channel_ = media_engine_->GetVoiceChannel(0);
4222
4223 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004224 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004225 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004226}
4227
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004228// Tests that we can renegotiate new media content with ICE candidates in the
4229// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004230TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004231 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004232 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004233 SetFactoryDtlsSrtp();
4234
deadbeefab9b2d12015-10-14 11:33:11 -07004235 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004236 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004237 SetLocalDescriptionWithoutError(offer);
4238
4239 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4240 SetRemoteDescriptionWithoutError(answer);
4241
4242 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004243 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004244 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4245
4246 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004247 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004248 candidate1.set_component(1);
4249 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4250 candidate1);
4251 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4252 SetRemoteDescriptionWithoutError(offer);
4253
htaa2a49d92016-03-04 02:51:39 -08004254 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004255 SetLocalDescriptionWithoutError(answer);
4256}
4257
4258// Tests that we can renegotiate new media content with ICE candidates separated
4259// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004260TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004261 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004262 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004263 SetFactoryDtlsSrtp();
4264
deadbeefab9b2d12015-10-14 11:33:11 -07004265 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004266 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267 SetLocalDescriptionWithoutError(offer);
4268
4269 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4270 SetRemoteDescriptionWithoutError(answer);
4271
4272 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004273 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004274 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4275 SetRemoteDescriptionWithoutError(offer);
4276
4277 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004278 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004279 candidate1.set_component(1);
4280 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4281 candidate1);
4282 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4283
htaa2a49d92016-03-04 02:51:39 -08004284 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004285 SetLocalDescriptionWithoutError(answer);
4286}
honghaiz7f777492016-02-02 21:54:01 -08004287
4288// Flaky on Win and Mac only. See webrtc:4943
4289#if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
4290#define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer
4291#else
4292#define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer
4293#endif
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004294// Tests that RTX codec is removed from the answer when it isn't supported
4295// by local side.
honghaiz7f777492016-02-02 21:54:01 -08004296TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004297 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004298 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004299 std::string offer_sdp(kSdpWithRtx);
4300
4301 SessionDescriptionInterface* offer =
4302 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4303 EXPECT_TRUE(offer->ToString(&offer_sdp));
4304
4305 // Offer SDP contains the RTX codec.
4306 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4307 SetRemoteDescriptionWithoutError(offer);
4308
htaa2a49d92016-03-04 02:51:39 -08004309 SessionDescriptionInterface* answer = CreateAnswer();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004310 std::string answer_sdp;
4311 answer->ToString(&answer_sdp);
4312 // Answer SDP removes the unsupported RTX codec.
4313 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4314 SetLocalDescriptionWithoutError(answer);
4315}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004316
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004317// This verifies that the voice channel after bundle has both options from video
4318// and voice channels.
4319TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4320 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004321 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004322
4323 PeerConnectionInterface::RTCOfferAnswerOptions options;
4324 options.use_rtp_mux = true;
4325
4326 SessionDescriptionInterface* offer = CreateOffer(options);
4327 SetLocalDescriptionWithoutError(offer);
4328
4329 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4330 rtc::Socket::Option::OPT_SNDBUF, 4000);
4331
4332 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4333 rtc::Socket::Option::OPT_RCVBUF, 8000);
4334
4335 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004336 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004337 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4338 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004339 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004340 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4341
deadbeefcbecd352015-09-23 11:50:27 -07004342 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004343 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4344 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004345 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004346 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4347
deadbeefcbecd352015-09-23 11:50:27 -07004348 EXPECT_NE(session_->voice_rtp_transport_channel(),
4349 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004350
deadbeefab9b2d12015-10-14 11:33:11 -07004351 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004352 SessionDescriptionInterface* answer =
4353 CreateRemoteAnswer(session_->local_description());
4354 SetRemoteDescriptionWithoutError(answer);
4355
deadbeefcbecd352015-09-23 11:50:27 -07004356 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004357 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4358 EXPECT_EQ(4000, option_val);
4359
deadbeefcbecd352015-09-23 11:50:27 -07004360 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004361 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4362 EXPECT_EQ(8000, option_val);
4363}
4364
tommi0f620f42015-07-09 03:25:02 -07004365// Test creating a session, request multiple offers, destroy the session
4366// and make sure we got success/failure callbacks for all of the requests.
4367// Background: crbug.com/507307
4368TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4369 Init();
4370
4371 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4372 PeerConnectionInterface::RTCOfferAnswerOptions options;
4373 options.offer_to_receive_audio =
4374 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004375 cricket::MediaSessionOptions session_options;
4376 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004377
4378 for (auto& o : observers) {
4379 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004380 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004381 }
4382
4383 session_.reset();
4384
tommi0f620f42015-07-09 03:25:02 -07004385 for (auto& o : observers) {
4386 // We expect to have received a notification now even if the session was
4387 // terminated. The offer creation may or may not have succeeded, but we
4388 // must have received a notification which, so the only invalid state
4389 // is kInit.
4390 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4391 }
4392}
4393
stefanc1aeaf02015-10-15 07:26:07 -07004394TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4395 TestPacketOptions();
4396}
4397
deadbeef057ecf02016-01-20 14:30:43 -08004398// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4399// is destroyed.
4400TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4401 Init();
4402 session_.reset();
4403 EXPECT_TRUE(session_destroyed_);
4404}
4405
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004406// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4407// currently fails because upon disconnection and reconnection OnIceComplete is
4408// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004409
deadbeefcbecd352015-09-23 11:50:27 -07004410INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4411 WebRtcSessionTest,
4412 testing::Values(ALREADY_GENERATED,
4413 DTLS_IDENTITY_STORE));