blob: cd5e784594f1bbc46f5a5a08f31d2845e6446ad7 [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;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
112
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000113static const char kFakeDtlsFingerprint[] =
114 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
115 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
116
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000117static const char kTooLongIceUfragPwd[] =
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
122
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000123static const char kSdpWithRtx[] =
124 "v=0\r\n"
125 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
128 "a=msid-semantic: WMS stream1\r\n"
129 "m=video 9 RTP/SAVPF 0 96\r\n"
130 "c=IN IP4 0.0.0.0\r\n"
131 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
132 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
133 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
134 "a=mid:video\r\n"
135 "a=sendrecv\r\n"
136 "a=rtcp-mux\r\n"
137 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
138 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
139 "a=rtpmap:0 fake_video_codec/90000\r\n"
140 "a=rtpmap:96 rtx/90000\r\n"
141 "a=fmtp:96 apt=0\r\n";
142
deadbeefab9b2d12015-10-14 11:33:11 -0700143static const char kStream1[] = "stream1";
144static const char kVideoTrack1[] = "video1";
145static const char kAudioTrack1[] = "audio1";
146
147static const char kStream2[] = "stream2";
148static const char kVideoTrack2[] = "video2";
149static const char kAudioTrack2[] = "audio2";
150
Henrik Boström87713d02015-08-25 09:53:21 +0200151enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
152
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153class MockIceObserver : public webrtc::IceObserver {
154 public:
155 MockIceObserver()
156 : oncandidatesready_(false),
157 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
158 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
159 }
160
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200161 virtual ~MockIceObserver() = default;
162
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceConnectionChange(
164 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 ice_connection_state_ = new_state;
166 }
perkjdfb769d2016-02-09 03:09:43 -0800167 void OnIceGatheringChange(
168 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // We can never transition back to "new".
170 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
171 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800172 oncandidatesready_ =
173 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
176 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800177 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 switch (candidate->sdp_mline_index()) {
179 case kMediaContentIndex0:
180 mline_0_candidates_.push_back(candidate->candidate());
181 break;
182 case kMediaContentIndex1:
183 mline_1_candidates_.push_back(candidate->candidate());
184 break;
185 default:
186 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // The ICE gathering state should always be Gathering when a candidate is
190 // received (or possibly Completed in the case of the final candidate).
191 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
192 }
193
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 // Some local candidates are removed.
195 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700196 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 num_candidates_removed_ += candidates.size();
198 }
199
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 bool oncandidatesready_;
201 std::vector<cricket::Candidate> mline_0_candidates_;
202 std::vector<cricket::Candidate> mline_1_candidates_;
203 PeerConnectionInterface::IceConnectionState ice_connection_state_;
204 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700205 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206};
207
208class WebRtcSessionForTest : public webrtc::WebRtcSession {
209 public:
stefanc1aeaf02015-10-15 07:26:07 -0700210 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000211 rtc::Thread* signaling_thread,
212 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700214 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700215 : WebRtcSession(media_controller,
216 signaling_thread,
217 worker_thread,
218 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 RegisterIceObserver(ice_observer);
220 }
221 virtual ~WebRtcSessionForTest() {}
222
deadbeefcbecd352015-09-23 11:50:27 -0700223 // Note that these methods are only safe to use if the signaling thread
224 // is the same as the worker thread
225 cricket::TransportChannel* voice_rtp_transport_channel() {
226 return rtp_transport_channel(voice_channel());
227 }
228
229 cricket::TransportChannel* voice_rtcp_transport_channel() {
230 return rtcp_transport_channel(voice_channel());
231 }
232
233 cricket::TransportChannel* video_rtp_transport_channel() {
234 return rtp_transport_channel(video_channel());
235 }
236
237 cricket::TransportChannel* video_rtcp_transport_channel() {
238 return rtcp_transport_channel(video_channel());
239 }
240
241 cricket::TransportChannel* data_rtp_transport_channel() {
242 return rtp_transport_channel(data_channel());
243 }
244
245 cricket::TransportChannel* data_rtcp_transport_channel() {
246 return rtcp_transport_channel(data_channel());
247 }
248
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 using webrtc::WebRtcSession::SetAudioPlayout;
250 using webrtc::WebRtcSession::SetAudioSend;
nisse2ded9b12016-04-08 02:23:55 -0700251 using webrtc::WebRtcSession::SetSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 using webrtc::WebRtcSession::SetVideoPlayout;
253 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700254
255 private:
256 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
257 if (!ch) {
258 return nullptr;
259 }
260 return ch->transport_channel();
261 }
262
263 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
264 if (!ch) {
265 return nullptr;
266 }
267 return ch->rtcp_transport_channel();
268 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269};
270
wu@webrtc.org91053e72013-08-10 07:18:04 +0000271class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000272 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000274 enum State {
275 kInit,
276 kFailed,
277 kSucceeded,
278 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000279 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280
281 // CreateSessionDescriptionObserver implementation.
282 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000283 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284 state_ = kSucceeded;
285 }
286 virtual void OnFailure(const std::string& error) {
287 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 }
289
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000290 SessionDescriptionInterface* description() { return description_.get(); }
291
292 SessionDescriptionInterface* ReleaseDescription() {
293 return description_.release();
294 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295
wu@webrtc.org91053e72013-08-10 07:18:04 +0000296 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
wu@webrtc.org91053e72013-08-10 07:18:04 +0000298 protected:
299 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
301 private:
kwibergd1fe2812016-04-27 06:47:29 -0700302 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304};
305
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800306class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800308 FakeAudioSource() : sink_(NULL) {}
309 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000310 if (sink_)
311 sink_->OnClose();
312 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000314 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800316 const cricket::AudioSource::Sink* sink() const { return sink_; }
317
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800319 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320};
321
Henrik Boström87713d02015-08-25 09:53:21 +0200322class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700323 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
324 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 protected:
326 // TODO Investigate why ChannelManager crashes, if it's created
327 // after stun_server.
328 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700329 : media_engine_(new cricket::FakeMediaEngine()),
330 data_engine_(new cricket::FakeDataEngine()),
331 channel_manager_(
332 new cricket::ChannelManager(media_engine_,
333 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700334 rtc::Thread::Current())),
335 fake_call_(webrtc::Call::Config()),
336 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800337 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
338 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700339 channel_manager_.get())),
340 tdesc_factory_(new cricket::TransportDescriptionFactory()),
341 desc_factory_(
342 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
343 tdesc_factory_.get())),
344 pss_(new rtc::PhysicalSocketServer),
345 vss_(new rtc::VirtualSocketServer(pss_.get())),
346 fss_(new rtc::FirewallSocketServer(vss_.get())),
347 ss_scope_(fss_.get()),
348 stun_socket_addr_(
349 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
350 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
351 stun_socket_addr_)),
352 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
353 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000354 cricket::ServerAddresses stun_servers;
355 stun_servers.insert(stun_socket_addr_);
356 allocator_.reset(new cricket::BasicPortAllocator(
357 &network_manager_,
358 stun_servers,
359 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000360 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700361 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 EXPECT_TRUE(channel_manager_->Init());
363 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
366
367 void AddInterface(const SocketAddress& addr) {
368 network_manager_.AddInterface(addr);
369 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700370 void RemoveInterface(const SocketAddress& addr) {
371 network_manager_.RemoveInterface(addr);
372 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373
Henrik Boström87713d02015-08-25 09:53:21 +0200374 // If |dtls_identity_store| != null or |rtc_configuration| contains
375 // |certificates| then DTLS will be enabled unless explicitly disabled by
376 // |rtc_configuration| options. When DTLS is enabled a certificate will be
377 // used if provided, otherwise one will be generated using the
378 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000379 void Init(
kwibergd1fe2812016-04-27 06:47:29 -0700380 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 ASSERT_TRUE(session_.get() == NULL);
382 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700383 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700384 allocator_.get(), &observer_));
385 session_->SignalDataChannelOpenMessage.connect(
386 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800387 session_->GetOnDestroyedSignal()->connect(
388 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389
390 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
391 observer_.ice_connection_state_);
392 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
393 observer_.ice_gathering_state_);
394
htaa2a49d92016-03-04 02:51:39 -0800395 EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store),
396 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700397 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 }
399
deadbeefab9b2d12015-10-14 11:33:11 -0700400 void OnDataChannelOpenMessage(const std::string& label,
401 const InternalDataChannelInit& config) {
402 last_data_channel_label_ = label;
403 last_data_channel_config_ = config;
404 }
405
deadbeef057ecf02016-01-20 14:30:43 -0800406 void OnSessionDestroyed() { session_destroyed_ = true; }
407
htaa2a49d92016-03-04 02:51:39 -0800408 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000409
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000410 void InitWithBundlePolicy(
411 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800412 configuration_.bundle_policy = bundle_policy;
413 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700414 }
415
416 void InitWithRtcpMuxPolicy(
417 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
418 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800419 configuration_.rtcp_mux_policy = rtcp_mux_policy;
420 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000421 }
422
Henrik Boström87713d02015-08-25 09:53:21 +0200423 // Successfully init with DTLS; with a certificate generated and supplied or
424 // with a store that generates it for us.
425 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
kwibergd1fe2812016-04-27 06:47:29 -0700426 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store;
Henrik Boström87713d02015-08-25 09:53:21 +0200427 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800428 configuration_.certificates.push_back(
Henrik Boström87713d02015-08-25 09:53:21 +0200429 FakeDtlsIdentityStore::GenerateCertificate());
430 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
431 dtls_identity_store.reset(new FakeDtlsIdentityStore());
432 dtls_identity_store->set_should_fail(false);
433 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700434 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200435 }
htaa2a49d92016-03-04 02:51:39 -0800436 Init(std::move(dtls_identity_store));
Henrik Boström87713d02015-08-25 09:53:21 +0200437 }
438
439 // Init with DTLS with a store that will fail to generate a certificate.
440 void InitWithDtlsIdentityGenFail() {
kwibergd1fe2812016-04-27 06:47:29 -0700441 std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
Henrik Boström5e56c592015-08-11 10:33:13 +0200442 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200443 dtls_identity_store->set_should_fail(true);
htaa2a49d92016-03-04 02:51:39 -0800444 Init(std::move(dtls_identity_store));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000445 }
446
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 void InitWithDtmfCodec() {
448 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700449 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
450 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 std::vector<cricket::AudioCodec> codecs;
452 codecs.push_back(kTelephoneEventCodec);
453 media_engine_->SetAudioCodecs(codecs);
454 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000455 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 }
457
deadbeefab9b2d12015-10-14 11:33:11 -0700458 void SendAudioVideoStream1() {
459 send_stream_1_ = true;
460 send_stream_2_ = false;
461 send_audio_ = true;
462 send_video_ = true;
463 }
464
465 void SendAudioVideoStream2() {
466 send_stream_1_ = false;
467 send_stream_2_ = true;
468 send_audio_ = true;
469 send_video_ = true;
470 }
471
472 void SendAudioVideoStream1And2() {
473 send_stream_1_ = true;
474 send_stream_2_ = true;
475 send_audio_ = true;
476 send_video_ = true;
477 }
478
479 void SendNothing() {
480 send_stream_1_ = false;
481 send_stream_2_ = false;
482 send_audio_ = false;
483 send_video_ = false;
484 }
485
486 void SendAudioOnlyStream2() {
487 send_stream_1_ = false;
488 send_stream_2_ = true;
489 send_audio_ = true;
490 send_video_ = false;
491 }
492
493 void SendVideoOnlyStream2() {
494 send_stream_1_ = false;
495 send_stream_2_ = true;
496 send_audio_ = false;
497 send_video_ = true;
498 }
499
500 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
501 if (send_stream_1_ && send_audio_) {
502 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
503 kStream1);
504 }
505 if (send_stream_1_ && send_video_) {
506 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
507 kStream1);
508 }
509 if (send_stream_2_ && send_audio_) {
510 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
511 kStream2);
512 }
513 if (send_stream_2_ && send_video_) {
514 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
515 kStream2);
516 }
517 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
518 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
519 data_channel_->label(),
520 data_channel_->label());
521 }
522 }
523
524 void GetOptionsForOffer(
525 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
526 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800527 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700528
deadbeefc80741f2015-10-22 13:14:45 -0700529 AddStreamsToOptions(session_options);
530 if (rtc_options.offer_to_receive_audio ==
531 RTCOfferAnswerOptions::kUndefined) {
532 session_options->recv_audio =
533 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
534 }
535 if (rtc_options.offer_to_receive_video ==
536 RTCOfferAnswerOptions::kUndefined) {
537 session_options->recv_video =
538 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
539 }
540 session_options->bundle_enabled =
541 session_options->bundle_enabled &&
542 (session_options->has_audio() || session_options->has_video() ||
543 session_options->has_data());
544
deadbeefab9b2d12015-10-14 11:33:11 -0700545 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
546 session_options->data_channel_type = cricket::DCT_SCTP;
547 }
548 }
549
htaa2a49d92016-03-04 02:51:39 -0800550 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
551 // ParseConstraintsForAnswer is used to set some defaults.
552 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700553
deadbeefc80741f2015-10-22 13:14:45 -0700554 AddStreamsToOptions(session_options);
555 session_options->bundle_enabled =
556 session_options->bundle_enabled &&
557 (session_options->has_audio() || session_options->has_video() ||
558 session_options->has_data());
559
deadbeefab9b2d12015-10-14 11:33:11 -0700560 if (session_->data_channel_type() == cricket::DCT_SCTP) {
561 session_options->data_channel_type = cricket::DCT_SCTP;
562 }
563 }
564
565 // Creates a local offer and applies it. Starts ICE.
566 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 // to decide which streams to create.
568 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000569 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 SetLocalDescriptionWithoutError(offer);
571 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
572 observer_.ice_gathering_state_,
573 kIceCandidatesTimeout);
574 }
575
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000576 SessionDescriptionInterface* CreateOffer() {
577 PeerConnectionInterface::RTCOfferAnswerOptions options;
578 options.offer_to_receive_audio =
579 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
580
581 return CreateOffer(options);
582 }
583
wu@webrtc.org91053e72013-08-10 07:18:04 +0000584 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800585 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000586 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000587 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700588 cricket::MediaSessionOptions session_options;
589 GetOptionsForOffer(options, &session_options);
590 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 EXPECT_TRUE_WAIT(
592 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000593 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000594 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000595 }
596
597 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800598 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000599 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000600 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800601 cricket::MediaSessionOptions session_options = options;
602 GetOptionsForAnswer(&session_options);
603 // Overwrite recv_audio and recv_video with passed-in values.
604 session_options.recv_video = options.recv_video;
605 session_options.recv_audio = options.recv_audio;
606 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000607 EXPECT_TRUE_WAIT(
608 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000609 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000610 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000611 }
612
htaa2a49d92016-03-04 02:51:39 -0800613 SessionDescriptionInterface* CreateAnswer() {
614 cricket::MediaSessionOptions options;
615 options.recv_video = true;
616 options.recv_audio = true;
617 return CreateAnswer(options);
618 }
619
wu@webrtc.org364f2042013-11-20 21:49:41 +0000620 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 return (session_->voice_channel() != NULL &&
622 session_->video_channel() != NULL);
623 }
624
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
626 ASSERT_TRUE(session_.get() != NULL);
627 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
628 ASSERT_TRUE(content != NULL);
629 const cricket::AudioContentDescription* audio_content =
630 static_cast<const cricket::AudioContentDescription*>(
631 content->description);
632 ASSERT_TRUE(audio_content != NULL);
633 ASSERT_EQ(1U, audio_content->cryptos().size());
634 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
635 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
636 audio_content->cryptos()[0].cipher_suite);
637 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
638 audio_content->protocol());
639
640 content = cricket::GetFirstVideoContent(sdp);
641 ASSERT_TRUE(content != NULL);
642 const cricket::VideoContentDescription* video_content =
643 static_cast<const cricket::VideoContentDescription*>(
644 content->description);
645 ASSERT_TRUE(video_content != NULL);
646 ASSERT_EQ(1U, video_content->cryptos().size());
647 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
648 video_content->cryptos()[0].cipher_suite);
649 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
650 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
651 video_content->protocol());
652 }
653
654 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
655 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
656 ASSERT_TRUE(content != NULL);
657 const cricket::AudioContentDescription* audio_content =
658 static_cast<const cricket::AudioContentDescription*>(
659 content->description);
660 ASSERT_TRUE(audio_content != NULL);
661 ASSERT_EQ(0U, audio_content->cryptos().size());
662
663 content = cricket::GetFirstVideoContent(sdp);
664 ASSERT_TRUE(content != NULL);
665 const cricket::VideoContentDescription* video_content =
666 static_cast<const cricket::VideoContentDescription*>(
667 content->description);
668 ASSERT_TRUE(video_content != NULL);
669 ASSERT_EQ(0U, video_content->cryptos().size());
670
671 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700672 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700674 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 video_content->protocol());
676 } else {
677 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
678 audio_content->protocol());
679 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
680 video_content->protocol());
681 }
682 }
683
684 // Set the internal fake description factories to do DTLS-SRTP.
685 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000686 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000688 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200689 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800690 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700691 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800692 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
694 }
695
696 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
697 bool expected) {
698 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
699 ASSERT_TRUE(audio != NULL);
700 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 const TransportInfo* video = sdp->GetTransportInfoByName("video");
702 ASSERT_TRUE(video != NULL);
703 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
706 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000707 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000709 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000710 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000712 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000714 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
715 offer);
htaa2a49d92016-03-04 02:51:39 -0800716 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 // Answer should be NULL as no crypto params in offer.
718 ASSERT_TRUE(answer == NULL);
719 }
720
721 void VerifyAnswerFromCryptoOffer() {
722 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000723 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700725 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
727 ASSERT_TRUE(offer.get() != NULL);
728 VerifyCryptoParams(offer->description());
729 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700730 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 ASSERT_TRUE(answer.get() != NULL);
732 VerifyCryptoParams(answer->description());
733 }
734
deadbeef0ed85b22016-02-23 17:24:52 -0800735 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
736 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800738 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 }
740
741 const cricket::ContentInfos& contents = desc1->contents();
742 cricket::ContentInfos::const_iterator it = contents.begin();
743
744 for (; it != contents.end(); ++it) {
745 const cricket::TransportDescription* transport_desc1 =
746 desc1->GetTransportDescriptionByName(it->name);
747 const cricket::TransportDescription* transport_desc2 =
748 desc2->GetTransportDescriptionByName(it->name);
749 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800750 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 }
752 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
753 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800754 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 }
756 }
deadbeef0ed85b22016-02-23 17:24:52 -0800757 return true;
758 }
759
760 // Compares ufrag/password only for the specified |media_type|.
761 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
762 const cricket::SessionDescription* desc2,
763 cricket::MediaType media_type) {
764 if (desc1->contents().size() != desc2->contents().size()) {
765 return false;
766 }
767
768 const cricket::ContentInfo* cinfo =
769 cricket::GetFirstMediaContent(desc1->contents(), media_type);
770 const cricket::TransportDescription* transport_desc1 =
771 desc1->GetTransportDescriptionByName(cinfo->name);
772 const cricket::TransportDescription* transport_desc2 =
773 desc2->GetTransportDescriptionByName(cinfo->name);
774 if (!transport_desc1 || !transport_desc2) {
775 return false;
776 }
777 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
778 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
779 return false;
780 }
781 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000783
784 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
785 std::string *sdp) {
786 const cricket::SessionDescription* desc = current_desc->description();
787 EXPECT_TRUE(current_desc->ToString(sdp));
788
789 const cricket::ContentInfos& contents = desc->contents();
790 cricket::ContentInfos::const_iterator it = contents.begin();
791 // Replace ufrag and pwd lines with empty strings.
792 for (; it != contents.end(); ++it) {
793 const cricket::TransportDescription* transport_desc =
794 desc->GetTransportDescriptionByName(it->name);
795 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
796 + "\r\n";
797 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
798 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000799 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000800 "", 0,
801 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000802 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000803 "", 0,
804 sdp);
805 }
806 }
807
deadbeef0ed85b22016-02-23 17:24:52 -0800808 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
809 const std::string& ufrag,
810 const std::string& pwd) {
811 cricket::SessionDescription* desc = current_desc->description();
812 for (TransportInfo& transport_info : desc->transport_infos()) {
813 cricket::TransportDescription& transport_desc =
814 transport_info.description;
815 transport_desc.ice_ufrag = ufrag;
816 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000817 }
818 }
819
deadbeef0ed85b22016-02-23 17:24:52 -0800820 // Sets ufrag/pwd for specified |media_type|.
821 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
822 cricket::MediaType media_type,
823 const std::string& ufrag,
824 const std::string& pwd) {
825 cricket::SessionDescription* desc = current_desc->description();
826 const cricket::ContentInfo* cinfo =
827 cricket::GetFirstMediaContent(desc->contents(), media_type);
828 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
829 cricket::TransportDescription* transport_desc =
830 &transport_info->description;
831 transport_desc->ice_ufrag = ufrag;
832 transport_desc->ice_pwd = pwd;
833 }
834
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 // Creates a remote offer and and applies it as a remote description,
836 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700837 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 // to decide which local and remote streams to create.
839 void CreateAndSetRemoteOfferAndLocalAnswer() {
840 SessionDescriptionInterface* offer = CreateRemoteOffer();
841 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800842 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 SetLocalDescriptionWithoutError(answer);
844 }
845 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
846 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700847 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 }
849 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700850 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 SetLocalDescriptionWithoutError(desc);
852 EXPECT_EQ(expected_state, session_->state());
853 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000854 void SetLocalDescriptionExpectError(const std::string& action,
855 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 SessionDescriptionInterface* desc) {
857 std::string error;
858 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 std::string sdp_type = "local ";
860 sdp_type.append(action);
861 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_NE(std::string::npos, error.find(expected_error));
863 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000864 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
865 SessionDescriptionInterface* desc) {
866 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
867 expected_error, desc);
868 }
869 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
870 SessionDescriptionInterface* desc) {
871 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
872 expected_error, desc);
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
875 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
876 }
877 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700878 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 SetRemoteDescriptionWithoutError(desc);
880 EXPECT_EQ(expected_state, session_->state());
881 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000882 void SetRemoteDescriptionExpectError(const std::string& action,
883 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 SessionDescriptionInterface* desc) {
885 std::string error;
886 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000887 std::string sdp_type = "remote ";
888 sdp_type.append(action);
889 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 EXPECT_NE(std::string::npos, error.find(expected_error));
891 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000892 void SetRemoteDescriptionOfferExpectError(
893 const std::string& expected_error, SessionDescriptionInterface* desc) {
894 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
895 expected_error, desc);
896 }
897 void SetRemoteDescriptionPranswerExpectError(
898 const std::string& expected_error, SessionDescriptionInterface* desc) {
899 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
900 expected_error, desc);
901 }
902 void SetRemoteDescriptionAnswerExpectError(
903 const std::string& expected_error, SessionDescriptionInterface* desc) {
904 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
905 expected_error, desc);
906 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907
908 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
909 SessionDescriptionInterface** nocrypto_answer) {
910 // Create a SDP without Crypto.
911 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000912 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 options.bundle_enabled = true;
914 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
915 ASSERT_TRUE(*offer != NULL);
916 VerifyCryptoParams((*offer)->description());
917
918 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
919 cricket::SEC_DISABLED);
920 EXPECT_TRUE(*nocrypto_answer != NULL);
921 }
922
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000923 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
924 SessionDescriptionInterface** nodtls_answer) {
925 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000926 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000927 options.bundle_enabled = true;
928
kwibergd1fe2812016-04-27 06:47:29 -0700929 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000930 CreateRemoteOffer(options, cricket::SEC_ENABLED));
931
932 *nodtls_answer =
933 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
934 EXPECT_TRUE(*nodtls_answer != NULL);
935 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
936 VerifyCryptoParams((*nodtls_answer)->description());
937
938 SetFactoryDtlsSrtp();
939 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
940 ASSERT_TRUE(*offer != NULL);
941 VerifyFingerprintStatus((*offer)->description(), true);
942 VerifyCryptoParams((*offer)->description());
943 }
944
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 JsepSessionDescription* CreateRemoteOfferWithVersion(
946 cricket::MediaSessionOptions options,
947 cricket::SecurePolicy secure_policy,
948 const std::string& session_version,
949 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000950 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 const cricket::SessionDescription* cricket_desc = NULL;
952 if (current_desc) {
953 cricket_desc = current_desc->description();
954 session_id = current_desc->session_id();
955 }
956
957 desc_factory_->set_secure(secure_policy);
958 JsepSessionDescription* offer(
959 new JsepSessionDescription(JsepSessionDescription::kOffer));
960 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
961 session_id, session_version)) {
962 delete offer;
963 offer = NULL;
964 }
965 return offer;
966 }
967 JsepSessionDescription* CreateRemoteOffer(
968 cricket::MediaSessionOptions options) {
969 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
970 kSessionVersion, NULL);
971 }
972 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000973 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
974 return CreateRemoteOfferWithVersion(
975 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 }
977 JsepSessionDescription* CreateRemoteOffer(
978 cricket::MediaSessionOptions options,
979 const SessionDescriptionInterface* current_desc) {
980 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
981 kSessionVersion, current_desc);
982 }
983
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000984 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
985 const char* sctp_stream_name, int new_port,
986 cricket::MediaSessionOptions options) {
987 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000988 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
989 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000990 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
991 }
992
993 // Takes ownership of offer_basis (and deletes it).
994 JsepSessionDescription* ChangeSDPSctpPort(
995 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
996 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
997 // SessionDescription from the mutated string.
998 const char* default_port_str = "5000";
999 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001000 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001001 std::string offer_str;
1002 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001003 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001004 new_port_str, strlen(new_port_str),
1005 &offer_str);
1006 JsepSessionDescription* offer = new JsepSessionDescription(
1007 offer_basis->type());
1008 delete offer_basis;
1009 offer->Initialize(offer_str, NULL);
1010 return offer;
1011 }
1012
deadbeefab9b2d12015-10-14 11:33:11 -07001013 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 // before this function to decide which streams to create.
1015 JsepSessionDescription* CreateRemoteOffer() {
1016 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001017 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 return CreateRemoteOffer(options, session_->remote_description());
1019 }
1020
1021 JsepSessionDescription* CreateRemoteAnswer(
1022 const SessionDescriptionInterface* offer,
1023 cricket::MediaSessionOptions options,
1024 cricket::SecurePolicy policy) {
1025 desc_factory_->set_secure(policy);
1026 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001027 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 JsepSessionDescription* answer(
1029 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1030 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1031 options, NULL),
1032 session_id, kSessionVersion)) {
1033 delete answer;
1034 answer = NULL;
1035 }
1036 return answer;
1037 }
1038
1039 JsepSessionDescription* CreateRemoteAnswer(
1040 const SessionDescriptionInterface* offer,
1041 cricket::MediaSessionOptions options) {
1042 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1043 }
1044
deadbeefab9b2d12015-10-14 11:33:11 -07001045 // Creates an answer session description.
1046 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 // to decide which streams to create.
1048 JsepSessionDescription* CreateRemoteAnswer(
1049 const SessionDescriptionInterface* offer) {
1050 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001051 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1053 }
1054
1055 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001056 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001057 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001058 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001059
1060 PeerConnectionInterface::RTCOfferAnswerOptions options;
1061 options.use_rtp_mux = bundle;
1062
1063 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1065 // and answer.
1066 SetLocalDescriptionWithoutError(offer);
1067
kwibergd1fe2812016-04-27 06:47:29 -07001068 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001069 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 std::string sdp;
1071 EXPECT_TRUE(answer->ToString(&sdp));
1072
1073 size_t expected_candidate_num = 2;
1074 if (!rtcp_mux) {
1075 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1076 // for rtp and rtcp.
1077 expected_candidate_num = 4;
1078 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 const std::string kRtcpMux = "a=rtcp-mux";
1080 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001081 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 kXRtcpMux.c_str(), kXRtcpMux.length(),
1083 &sdp);
1084 }
1085
1086 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1087 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088
1089 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001090 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1092 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001093 if (bundle) {
1094 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1095 } else {
1096 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 }
1098 }
1099 // Tests that we can only send DTMF when the dtmf codec is supported.
1100 void TestCanInsertDtmf(bool can) {
1101 if (can) {
1102 InitWithDtmfCodec();
1103 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001104 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 }
deadbeefab9b2d12015-10-14 11:33:11 -07001106 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 CreateAndSetRemoteOfferAndLocalAnswer();
1108 EXPECT_FALSE(session_->CanInsertDtmf(""));
1109 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1110 }
1111
zhihuang3a334652016-05-05 18:37:49 -07001112 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1113 const std::string& codec_name) {
1114 for (const auto& content : desc->description()->contents()) {
1115 if (static_cast<cricket::MediaContentDescription*>(content.description)
1116 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1117 const auto* mdesc =
1118 static_cast<cricket::VideoContentDescription*>(content.description);
1119 for (const auto& codec : mdesc->codecs()) {
1120 if (codec.name == codec_name) {
1121 return true;
1122 }
1123 }
1124 }
1125 }
1126 return false;
1127 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001128 // Helper class to configure loopback network and verify Best
1129 // Connection using right IP protocol for TestLoopbackCall
1130 // method. LoopbackNetworkManager applies firewall rules to block
1131 // all ping traffic once ICE completed, and remove them to observe
1132 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1133 // verifies the best connection is using the right IP protocol after
1134 // initial ICE convergences.
1135
1136 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001137 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001138 LoopbackNetworkConfiguration()
1139 : test_ipv6_network_(false),
1140 test_extra_ipv4_network_(false),
1141 best_connection_after_initial_ice_converged_(1, 0) {}
1142
1143 // Used to track the expected best connection count in each IP protocol.
1144 struct ExpectedBestConnection {
1145 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1146 : ipv4_count_(ipv4_count),
1147 ipv6_count_(ipv6_count) {}
1148
1149 int ipv4_count_;
1150 int ipv6_count_;
1151 };
1152
1153 bool test_ipv6_network_;
1154 bool test_extra_ipv4_network_;
1155 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1156
1157 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001158 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001159 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1160 }
1161
1162 private:
jbauchac8869e2015-07-03 01:36:14 -07001163 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001164 const ExpectedBestConnection& expected) const {
1165 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001166 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1167 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001168 expected.ipv4_count_);
1169 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001170 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1171 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001173 // This is used in the loopback call so there is only single host to host
1174 // candidate pair.
1175 EXPECT_EQ(metrics_observer->GetEnumCounter(
1176 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1177 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001178 0);
1179 EXPECT_EQ(metrics_observer->GetEnumCounter(
1180 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1181 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001182 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 }
1184 };
1185
1186 class LoopbackNetworkManager {
1187 public:
1188 LoopbackNetworkManager(WebRtcSessionTest* session,
1189 const LoopbackNetworkConfiguration& config)
1190 : config_(config) {
1191 session->AddInterface(
1192 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1193 if (config_.test_extra_ipv4_network_) {
1194 session->AddInterface(
1195 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1196 }
1197 if (config_.test_ipv6_network_) {
1198 session->AddInterface(
1199 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1200 }
1201 }
1202
1203 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1204 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1205 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1206 if (config_.test_extra_ipv4_network_) {
1207 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1208 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1209 }
1210 if (config_.test_ipv6_network_) {
1211 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1212 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1213 }
1214 }
1215
1216 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1217
1218 private:
1219 LoopbackNetworkConfiguration config_;
1220 };
1221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 // The method sets up a call from the session to itself, in a loopback
1223 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001224 // disconnection, and then a permanent disconnection.
1225 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1227 // While running the call, this method also checks if the session goes through
1228 // the correct sequence of ICE states when a connection is established,
1229 // broken, and re-established.
1230 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001231 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1232 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001234
stefanc1aeaf02015-10-15 07:26:07 -07001235 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001236 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001237 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001238 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239
1240 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1241 observer_.ice_gathering_state_);
1242 SetLocalDescriptionWithoutError(offer);
1243 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1244 observer_.ice_connection_state_);
1245 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001246 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1248 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001249 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250
1251 std::string sdp;
1252 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001253 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1254 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 ASSERT_TRUE(desc != NULL);
1256 SetRemoteDescriptionWithoutError(desc);
1257
1258 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001259 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001260
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001261 // The ice connection state is "Connected" too briefly to catch in a test.
1262 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001263 observer_.ice_connection_state_, kIceCandidatesTimeout);
1264 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265
stefanc1aeaf02015-10-15 07:26:07 -07001266 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1267 LoopbackNetworkManager loopback_network_manager(this, config);
1268 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001269 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 // Adding firewall rule to block ping requests, which should cause
1271 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001272
1273 loopback_network_manager.ApplyFirewallRules(fss_.get());
1274
1275 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1277 observer_.ice_connection_state_,
1278 kIceCandidatesTimeout);
1279
jbauchac8869e2015-07-03 01:36:14 -07001280 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001283 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001285 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001286 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 observer_.ice_connection_state_,
1288 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001289
1290 // Now we block ping requests and wait until the ICE connection transitions
1291 // to the Failed state. This will take at least 30 seconds because it must
1292 // wait for the Port to timeout.
1293 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001294
1295 loopback_network_manager.ApplyFirewallRules(fss_.get());
1296 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001297 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001298 observer_.ice_connection_state_,
1299 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 }
1301
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001302 void TestLoopbackCall() {
1303 LoopbackNetworkConfiguration config;
1304 TestLoopbackCall(config);
1305 }
1306
stefanc1aeaf02015-10-15 07:26:07 -07001307 void TestPacketOptions() {
1308 media_controller_.reset(
1309 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1310 LoopbackNetworkConfiguration config;
1311 LoopbackNetworkManager loopback_network_manager(this, config);
1312
1313 SetupLoopbackCall();
1314
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001315 // Wait for channel to be ready for sending.
1316 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001317 uint8_t test_packet[15] = {0};
1318 rtc::PacketOptions options;
1319 options.packet_id = 10;
1320 media_engine_->GetVideoChannel(0)
1321 ->SendRtp(test_packet, sizeof(test_packet), options);
1322
1323 const int kPacketTimeout = 2000;
1324 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1325 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1326 }
1327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1329 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001330 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1331 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001332
1333 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1335 codecs.push_back(kCNCodec1);
1336 codecs.push_back(kCNCodec2);
1337 media_engine_->SetAudioCodecs(codecs);
1338 desc_factory_->set_audio_codecs(codecs);
1339 }
1340
1341 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1342 const cricket::ContentDescription* description = content->description;
1343 ASSERT(description != NULL);
1344 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001345 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 ASSERT(audio_content_desc != NULL);
1347 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1348 if (audio_content_desc->codecs()[i].name == "CN")
1349 return false;
1350 }
1351 return true;
1352 }
1353
deadbeefab9b2d12015-10-14 11:33:11 -07001354 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001355 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001356 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001357 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1358 data_channel_ = DataChannel::Create(
1359 session_.get(), session_->data_channel_type(), "datachannel", dci);
1360 }
1361
1362 void SetLocalDescriptionWithDataChannel() {
1363 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001364 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 SetLocalDescriptionWithoutError(offer);
1366 }
1367
wu@webrtc.org91053e72013-08-10 07:18:04 +00001368 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001369 RTCCertificateGenerationMethod cert_gen_method,
1370 CreateSessionDescriptionRequest::Type type) {
1371 InitWithDtls(cert_gen_method);
1372 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1373 }
1374
1375 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1376 CreateSessionDescriptionRequest::Type type) {
1377 InitWithDtlsIdentityGenFail();
1378 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1379 }
1380
1381 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001382 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001383 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001384 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001385 if (type == CreateSessionDescriptionRequest::kAnswer) {
1386 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001387 std::unique_ptr<JsepSessionDescription> offer(
1388 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 ASSERT_TRUE(offer.get() != NULL);
1390 SetRemoteDescriptionWithoutError(offer.release());
1391 }
1392
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001393 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001394 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001395 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001396 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 observers[kNumber];
1398 for (int i = 0; i < kNumber; ++i) {
1399 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1400 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001401 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001402 } else {
htaa2a49d92016-03-04 02:51:39 -08001403 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404 }
1405 }
1406
1407 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1408 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1409 WebRtcSessionCreateSDPObserverForTest::kFailed;
1410
1411 for (int i = 0; i < kNumber; ++i) {
1412 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1413 if (success) {
1414 EXPECT_TRUE(observers[i]->description() != NULL);
1415 } else {
1416 EXPECT_TRUE(observers[i]->description() == NULL);
1417 }
1418 }
1419 }
1420
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001421 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001422 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001423 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001424 turn_server.credentials = credentials;
1425 turn_server.ports.push_back(
1426 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1427 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001428 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001429 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001430 }
1431
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 cricket::FakeMediaEngine* media_engine_;
1433 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001434 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001435 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001436 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1437 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1438 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1439 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1440 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1441 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001442 rtc::SocketServerScope ss_scope_;
1443 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001444 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001445 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001446 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001447 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001448 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001449 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001450 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 MockIceObserver observer_;
1452 cricket::FakeVideoMediaChannel* video_channel_;
1453 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001454 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001455 // The following flags affect options created for CreateOffer/CreateAnswer.
1456 bool send_stream_1_ = false;
1457 bool send_stream_2_ = false;
1458 bool send_audio_ = false;
1459 bool send_video_ = false;
1460 rtc::scoped_refptr<DataChannel> data_channel_;
1461 // Last values received from data channel creation signal.
1462 std::string last_data_channel_label_;
1463 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001464 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465};
1466
Henrik Boström87713d02015-08-25 09:53:21 +02001467TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1468 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001469 // SDES is disabled when DTLS is on.
1470 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471}
1472
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001473TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001474 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475 // SDES is required if DTLS is off.
1476 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001477}
1478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1480 TestSessionCandidatesWithBundleRtcpMux(false, false);
1481}
1482
1483// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1484// with rtcp-mux and/or bundle.
1485TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1486 TestSessionCandidatesWithBundleRtcpMux(false, true);
1487}
1488
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1490 TestSessionCandidatesWithBundleRtcpMux(true, true);
1491}
1492
1493TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001494 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1495 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001496 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001497 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 InitiateCall();
1499 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1500 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1501 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1502}
1503
minyuec8930ba2016-01-22 06:17:46 -08001504// Crashes on Win only. See webrtc:5411.
1505#if defined(WEBRTC_WIN)
1506#define MAYBE_TestStunError DISABLED_TestStunError
1507#else
1508#define MAYBE_TestStunError TestStunError
1509#endif
1510TEST_F(WebRtcSessionTest, MAYBE_TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001511 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1512 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001513 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001514 rtc::FP_UDP,
1515 rtc::FD_ANY,
1516 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001517 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001518 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001520 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1522 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1523 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1524}
1525
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001526TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001527 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001528 SessionDescriptionInterface* offer = NULL;
1529 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1530 std::string unknown_action;
1531 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1532 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1533}
1534
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535// Test creating offers and receive answers and make sure the
1536// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001537TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001538 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001539 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001540 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541 const std::string session_id_orig = offer->session_id();
1542 const std::string session_version_orig = offer->session_version();
1543 SetLocalDescriptionWithoutError(offer);
1544
deadbeefab9b2d12015-10-14 11:33:11 -07001545 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 SessionDescriptionInterface* answer =
1547 CreateRemoteAnswer(session_->local_description());
1548 SetRemoteDescriptionWithoutError(answer);
1549
1550 video_channel_ = media_engine_->GetVideoChannel(0);
1551 voice_channel_ = media_engine_->GetVoiceChannel(0);
1552
1553 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1554 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1555
1556 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1557 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1558
1559 ASSERT_EQ(1u, video_channel_->send_streams().size());
1560 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1561 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1562 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1563
1564 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001565 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001566 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567
1568 // Verify the session id is the same and the session version is
1569 // increased.
1570 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001571 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1572 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573
1574 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001575 EXPECT_EQ(0u, video_channel_->send_streams().size());
1576 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577
deadbeefab9b2d12015-10-14 11:33:11 -07001578 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 answer = CreateRemoteAnswer(session_->local_description());
1580 SetRemoteDescriptionWithoutError(answer);
1581
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 // Make sure the receive streams have not changed.
1583 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1584 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1585 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1586 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1587}
1588
1589// Test receiving offers and creating answers and make sure the
1590// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001592 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001593 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001594 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 SetRemoteDescriptionWithoutError(offer);
1597
deadbeefab9b2d12015-10-14 11:33:11 -07001598 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001599 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001600 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 SetLocalDescriptionWithoutError(answer);
1602
1603 const std::string session_id_orig = answer->session_id();
1604 const std::string session_version_orig = answer->session_version();
1605
1606 video_channel_ = media_engine_->GetVideoChannel(0);
1607 voice_channel_ = media_engine_->GetVoiceChannel(0);
1608
htaa2a49d92016-03-04 02:51:39 -08001609 ASSERT_TRUE(video_channel_);
1610 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1612 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1613
1614 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1615 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1616
1617 ASSERT_EQ(1u, video_channel_->send_streams().size());
1618 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1619 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1620 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1621
deadbeefab9b2d12015-10-14 11:33:11 -07001622 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001623 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 SetRemoteDescriptionWithoutError(offer);
1625
1626 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001627 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001628 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629
1630 // Verify the session id is the same and the session version is
1631 // increased.
1632 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001633 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1634 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 SetLocalDescriptionWithoutError(answer);
1636
1637 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1638 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1639 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1640 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1641 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1642 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1643
1644 // Make sure we have no send streams.
1645 EXPECT_EQ(0u, video_channel_->send_streams().size());
1646 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1647}
1648
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001649TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001650 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001651 media_engine_->set_fail_create_channel(true);
1652
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001654 ASSERT_TRUE(offer != NULL);
1655 // SetRemoteDescription and SetLocalDescription will take the ownership of
1656 // the offer.
1657 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001658 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001659 ASSERT_TRUE(offer != NULL);
1660 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1661}
1662
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001663//
1664// Tests for creating/setting SDP under different SDES/DTLS polices:
1665//
1666// --DTLS off and SDES on
1667// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1668// set local/remote offer/answer with crypto --> success
1669// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1670// failure
1671// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1672// failure
1673// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1674// failure
1675//
1676// --DTLS on and SDES off
1677// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1678// set local/remote offer/answer with DTLS fingerprint --> success
1679// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1680// fingerprint --> failure
1681// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1682// --> failure
1683// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1684// --> failure
1685//
1686// --Encryption disabled: DTLS off and SDES off
1687// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1688// answer without SDES or DTLS --> success
1689// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1690// answer without SDES or DTLS --> success
1691//
1692
1693// Test that we return a failure when applying a remote/local offer that doesn't
1694// have cryptos enabled when DTLS is off.
1695TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001696 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001698 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 JsepSessionDescription* offer = CreateRemoteOffer(
1700 options, cricket::SEC_DISABLED);
1701 ASSERT_TRUE(offer != NULL);
1702 VerifyNoCryptoParams(offer->description(), false);
1703 // SetRemoteDescription and SetLocalDescription will take the ownership of
1704 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001705 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1707 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709}
1710
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711// Test that we return a failure when applying a local answer that doesn't have
1712// cryptos enabled when DTLS is off.
1713TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001714 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 SessionDescriptionInterface* offer = NULL;
1716 SessionDescriptionInterface* answer = NULL;
1717 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1718 // SetRemoteDescription and SetLocalDescription will take the ownership of
1719 // the offer.
1720 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001721 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722}
1723
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001724// Test we will return fail when apply an remote answer that doesn't have
1725// crypto enabled when DTLS is off.
1726TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001727 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 SessionDescriptionInterface* offer = NULL;
1729 SessionDescriptionInterface* answer = NULL;
1730 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1731 // SetRemoteDescription and SetLocalDescription will take the ownership of
1732 // the offer.
1733 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001734 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735}
1736
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1738// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001739TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001740 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001741 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001742 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 SetFactoryDtlsSrtp();
1744 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001745 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746 JsepSessionDescription* offer =
1747 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 ASSERT_TRUE(offer != NULL);
1749 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001750 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // SetRemoteDescription will take the ownership of the offer.
1753 SetRemoteDescriptionWithoutError(offer);
1754
1755 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001756 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 ASSERT_TRUE(answer != NULL);
1758 VerifyFingerprintStatus(answer->description(), true);
1759 // Check that we don't have an a=crypto line in the answer.
1760 VerifyNoCryptoParams(answer->description(), true);
1761
1762 // Now set the local description, which should work, even without a=crypto.
1763 SetLocalDescriptionWithoutError(answer);
1764}
1765
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001766// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1767// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001768TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001769 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001770 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001771 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001772 SetFactoryDtlsSrtp();
1773
1774 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001775 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776 ASSERT_TRUE(offer != NULL);
1777 VerifyFingerprintStatus(offer->description(), true);
1778 // Check that we don't have an a=crypto line in the offer.
1779 VerifyNoCryptoParams(offer->description(), true);
1780
1781 // Now set the local description, which should work, even without a=crypto.
1782 SetLocalDescriptionWithoutError(offer);
1783
1784 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001785 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 JsepSessionDescription* answer =
1787 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1788 ASSERT_TRUE(answer != NULL);
1789 VerifyFingerprintStatus(answer->description(), true);
1790 VerifyNoCryptoParams(answer->description(), true);
1791
1792 // SetRemoteDescription will take the ownership of the answer.
1793 SetRemoteDescriptionWithoutError(answer);
1794}
1795
1796// Test that if we support DTLS and the other side didn't offer a fingerprint,
1797// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001798TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001799 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001800 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001802 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 JsepSessionDescription* offer = CreateRemoteOffer(
1805 options, cricket::SEC_REQUIRED);
1806 ASSERT_TRUE(offer != NULL);
1807 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001808 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001810 // SetRemoteDescription will take the ownership of the offer.
1811 SetRemoteDescriptionOfferExpectError(
1812 kSdpWithoutDtlsFingerprint, offer);
1813
1814 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1815 // SetLocalDescription will take the ownership of the offer.
1816 SetLocalDescriptionOfferExpectError(
1817 kSdpWithoutDtlsFingerprint, offer);
1818}
1819
1820// Test that we return a failure when applying a local answer that doesn't have
1821// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001822TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001823 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001824 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001825 SessionDescriptionInterface* offer = NULL;
1826 SessionDescriptionInterface* answer = NULL;
1827 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1828
1829 // SetRemoteDescription and SetLocalDescription will take the ownership of
1830 // the offer and answer.
1831 SetRemoteDescriptionWithoutError(offer);
1832 SetLocalDescriptionAnswerExpectError(
1833 kSdpWithoutDtlsFingerprint, answer);
1834}
1835
1836// Test that we return a failure when applying a remote answer that doesn't have
1837// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001838TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001839 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001840 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001841 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001842 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001843 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001844 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001845 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001846 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001847 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848
1849 // SetRemoteDescription and SetLocalDescription will take the ownership of
1850 // the offer and answer.
1851 SetLocalDescriptionWithoutError(offer);
1852 SetRemoteDescriptionAnswerExpectError(
1853 kSdpWithoutDtlsFingerprint, answer);
1854}
1855
1856// Test that we create a local offer without SDES or DTLS and accept a remote
1857// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001858TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001859 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001861 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862
1863 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001864 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 ASSERT_TRUE(offer != NULL);
1866 VerifyFingerprintStatus(offer->description(), false);
1867 // Check that we don't have an a=crypto line in the offer.
1868 VerifyNoCryptoParams(offer->description(), false);
1869
1870 // Now set the local description, which should work, even without a=crypto.
1871 SetLocalDescriptionWithoutError(offer);
1872
1873 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001874 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001875 JsepSessionDescription* answer =
1876 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1877 ASSERT_TRUE(answer != NULL);
1878 VerifyFingerprintStatus(answer->description(), false);
1879 VerifyNoCryptoParams(answer->description(), false);
1880
1881 // SetRemoteDescription will take the ownership of the answer.
1882 SetRemoteDescriptionWithoutError(answer);
1883}
1884
1885// Test that we create a local answer without SDES or DTLS and accept a remote
1886// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001887TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001888 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001889 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890
1891 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001892 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001893 JsepSessionDescription* offer =
1894 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1895 ASSERT_TRUE(offer != NULL);
1896 VerifyFingerprintStatus(offer->description(), false);
1897 VerifyNoCryptoParams(offer->description(), false);
1898
1899 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 SetRemoteDescriptionWithoutError(offer);
1901
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001902 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001903 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 ASSERT_TRUE(answer != NULL);
1905 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001906 // Check that we don't have an a=crypto line in the answer.
1907 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 SetLocalDescriptionWithoutError(answer);
1911}
1912
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001913// Test that we can create and set an answer correctly when different
1914// SSL roles have been negotiated for different transports.
1915// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1916TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1917 SendAudioVideoStream1();
1918 InitWithDtls(GetParam());
1919 SetFactoryDtlsSrtp();
1920
1921 SessionDescriptionInterface* offer = CreateOffer();
1922 SetLocalDescriptionWithoutError(offer);
1923
1924 cricket::MediaSessionOptions options;
1925 options.recv_video = true;
1926
1927 // First, negotiate different SSL roles.
1928 SessionDescriptionInterface* answer =
1929 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1930 TransportInfo* audio_transport_info =
1931 answer->description()->GetTransportInfoByName("audio");
1932 audio_transport_info->description.connection_role =
1933 cricket::CONNECTIONROLE_ACTIVE;
1934 TransportInfo* video_transport_info =
1935 answer->description()->GetTransportInfoByName("video");
1936 video_transport_info->description.connection_role =
1937 cricket::CONNECTIONROLE_PASSIVE;
1938 SetRemoteDescriptionWithoutError(answer);
1939
1940 // Now create an offer in the reverse direction, and ensure the initial
1941 // offerer responds with an answer with correct SSL roles.
1942 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1943 kSessionVersion,
1944 session_->remote_description());
1945 SetRemoteDescriptionWithoutError(offer);
1946
htaa2a49d92016-03-04 02:51:39 -08001947 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001948 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1949 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1950 audio_transport_info->description.connection_role);
1951 video_transport_info = answer->description()->GetTransportInfoByName("video");
1952 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1953 video_transport_info->description.connection_role);
1954 SetLocalDescriptionWithoutError(answer);
1955
1956 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1957 // audio is transferred over to video in the answer that completes the BUNDLE
1958 // negotiation.
1959 options.bundle_enabled = true;
1960 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1961 kSessionVersion,
1962 session_->remote_description());
1963 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001964 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001965 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1966 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1967 audio_transport_info->description.connection_role);
1968 video_transport_info = answer->description()->GetTransportInfoByName("video");
1969 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1970 video_transport_info->description.connection_role);
1971 SetLocalDescriptionWithoutError(answer);
1972}
1973
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001975 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001976 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001978 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 SetLocalDescriptionWithoutError(offer);
1980
1981 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001982 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 SetLocalDescriptionWithoutError(offer2);
1984}
1985
1986TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001987 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001988 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 SetRemoteDescriptionWithoutError(offer);
1992
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001993 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 SetRemoteDescriptionWithoutError(offer2);
1995}
1996
1997TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001998 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001999 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002002 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002003 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2004 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005}
2006
2007TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002008 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002009 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002010 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002013 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002014 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015}
2016
2017TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
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 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002021 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
htaa2a49d92016-03-04 02:51:39 -08002023 JsepSessionDescription* pranswer =
2024 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002026 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027
deadbeefab9b2d12015-10-14 11:33:11 -07002028 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002029 JsepSessionDescription* pranswer2 =
2030 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2032
deadbeefd59daf82015-10-14 15:02:44 -07002033 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034
deadbeefab9b2d12015-10-14 11:33:11 -07002035 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002036 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002037 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038}
2039
2040TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002041 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002042 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002043 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002044 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045
2046 JsepSessionDescription* pranswer =
2047 CreateRemoteAnswer(session_->local_description());
2048 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2049
2050 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002051 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
deadbeefab9b2d12015-10-14 11:33:11 -07002053 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054 JsepSessionDescription* pranswer2 =
2055 CreateRemoteAnswer(session_->local_description());
2056 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2057
2058 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002059 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 SessionDescriptionInterface* answer =
2063 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002064 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065}
2066
2067TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002068 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002069 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002070 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002071
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 SessionDescriptionInterface* answer =
2073 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002074 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2075 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076}
2077
2078TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002079 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002080 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002081 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002082
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 SessionDescriptionInterface* answer =
2084 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002085 SetRemoteDescriptionAnswerExpectError(
2086 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087}
2088
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002089// Tests that the remote candidates are added and removed successfully.
2090TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002094 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2095 "", "", "host", 0, "");
2096 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2098
deadbeefd59daf82015-10-14 15:02:44 -07002099 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2101
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002102 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002104
2105 // Fail since we have not set a remote description.
2106 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
2108 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2109 session_->local_description());
2110 SetRemoteDescriptionWithoutError(answer);
2111
deadbeefd59daf82015-10-14 15:02:44 -07002112 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2113 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002114 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002115 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2116 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 // Verifying the candidates are copied properly from internal vector.
2119 const SessionDescriptionInterface* remote_desc =
2120 session_->remote_description();
2121 ASSERT_TRUE(remote_desc != NULL);
2122 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2123 const IceCandidateCollection* candidates =
2124 remote_desc->candidates(kMediaContentIndex0);
2125 ASSERT_EQ(2u, candidates->count());
2126 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2127 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2128 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2129 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2130
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002131 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2132 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 candidate.set_component(2);
2134 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2135 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002136 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137
2138 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2139 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002140
2141 // Remove candidate1 and candidate2
2142 std::vector<cricket::Candidate> remote_candidates;
2143 remote_candidates.push_back(ice_candidate1.candidate());
2144 remote_candidates.push_back(ice_candidate2.candidate());
2145 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2146 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147}
2148
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002149// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150// that it is retained if the remote session description is changed.
2151TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002152 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 cricket::Candidate candidate1;
2154 candidate1.set_component(1);
2155 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2156 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002157 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 CreateAndSetRemoteOfferAndLocalAnswer();
2159
2160 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2161 const SessionDescriptionInterface* remote_desc =
2162 session_->remote_description();
2163 ASSERT_TRUE(remote_desc != NULL);
2164 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2165 const IceCandidateCollection* candidates =
2166 remote_desc->candidates(kMediaContentIndex0);
2167 ASSERT_EQ(1u, candidates->count());
2168 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2169
2170 // Update the RemoteSessionDescription with a new session description and
2171 // a candidate and check that the new remote session description contains both
2172 // candidates.
2173 SessionDescriptionInterface* offer = CreateRemoteOffer();
2174 cricket::Candidate candidate2;
2175 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2176 candidate2);
2177 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2178 SetRemoteDescriptionWithoutError(offer);
2179
2180 remote_desc = session_->remote_description();
2181 ASSERT_TRUE(remote_desc != NULL);
2182 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2183 candidates = remote_desc->candidates(kMediaContentIndex0);
2184 ASSERT_EQ(2u, candidates->count());
2185 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2186 // Username and password have be updated with the TransportInfo of the
2187 // SessionDescription, won't be equal to the original one.
2188 candidate2.set_username(candidates->at(0)->candidate().username());
2189 candidate2.set_password(candidates->at(0)->candidate().password());
2190 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2191 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2192 // No need to verify the username and password.
2193 candidate1.set_username(candidates->at(1)->candidate().username());
2194 candidate1.set_password(candidates->at(1)->candidate().password());
2195 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2196
2197 // Test that the candidate is ignored if we can add the same candidate again.
2198 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2199}
2200
2201// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002202// that they are retained if the local session description is changed. And if
2203// continual gathering is enabled, they are removed from the local session
2204// description when the network is down.
2205TEST_F(WebRtcSessionTest,
2206 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002207 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002208 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002209 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 CreateAndSetRemoteOfferAndLocalAnswer();
2211
2212 const SessionDescriptionInterface* local_desc = session_->local_description();
2213 const IceCandidateCollection* candidates =
2214 local_desc->candidates(kMediaContentIndex0);
2215 ASSERT_TRUE(candidates != NULL);
2216 EXPECT_EQ(0u, candidates->count());
2217
2218 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2219
2220 local_desc = session_->local_description();
2221 candidates = local_desc->candidates(kMediaContentIndex0);
2222 ASSERT_TRUE(candidates != NULL);
2223 EXPECT_LT(0u, candidates->count());
2224 candidates = local_desc->candidates(1);
2225 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002226 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227
2228 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002229 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 CreateAndSetRemoteOfferAndLocalAnswer();
2231
2232 local_desc = session_->local_description();
2233 candidates = local_desc->candidates(kMediaContentIndex0);
2234 ASSERT_TRUE(candidates != NULL);
2235 EXPECT_LT(0u, candidates->count());
2236 candidates = local_desc->candidates(1);
2237 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002238 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002239
2240 candidates = local_desc->candidates(kMediaContentIndex0);
2241 size_t num_local_candidates = candidates->count();
2242 // Enable Continual Gathering
2243 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2244 // Bring down the network interface to trigger candidate removals.
2245 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2246 // Verify that all local candidates are removed.
2247 EXPECT_EQ(0, observer_.num_candidates_removed_);
2248 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2249 kIceCandidatesTimeout);
2250 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2251}
2252
2253// Tests that if continual gathering is disabled, local candidates won't be
2254// removed when the interface is turned down.
2255TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2256 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2257 Init();
2258 SendAudioVideoStream1();
2259 CreateAndSetRemoteOfferAndLocalAnswer();
2260
2261 const SessionDescriptionInterface* local_desc = session_->local_description();
2262 const IceCandidateCollection* candidates =
2263 local_desc->candidates(kMediaContentIndex0);
2264 ASSERT_TRUE(candidates != NULL);
2265 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2266
2267 size_t num_local_candidates = candidates->count();
2268 EXPECT_LT(0u, num_local_candidates);
2269 // By default, Continual Gathering is disabled.
2270 // Bring down the network interface.
2271 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2272 // Verify that the local candidates are not removed.
2273 rtc::Thread::Current()->ProcessMessages(1000);
2274 EXPECT_EQ(0, observer_.num_candidates_removed_);
2275 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276}
2277
2278// Test that we can set a remote session description with remote candidates.
2279TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002280 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281
2282 cricket::Candidate candidate1;
2283 candidate1.set_component(1);
2284 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2285 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002286 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002287 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288
2289 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2290 SetRemoteDescriptionWithoutError(offer);
2291
2292 const SessionDescriptionInterface* remote_desc =
2293 session_->remote_description();
2294 ASSERT_TRUE(remote_desc != NULL);
2295 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2296 const IceCandidateCollection* candidates =
2297 remote_desc->candidates(kMediaContentIndex0);
2298 ASSERT_EQ(1u, candidates->count());
2299 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2300
htaa2a49d92016-03-04 02:51:39 -08002301 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 SetLocalDescriptionWithoutError(answer);
2303}
2304
2305// Test that offers and answers contains ice candidates when Ice candidates have
2306// been gathered.
2307TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002308 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002309 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002310 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 // Ice is started but candidates are not provided until SetLocalDescription
2312 // is called.
2313 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2314 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2315 CreateAndSetRemoteOfferAndLocalAnswer();
2316 // Wait until at least one local candidate has been collected.
2317 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2318 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319
kwibergd1fe2812016-04-27 06:47:29 -07002320 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002321
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2323 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324
2325 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2326 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002327 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2329 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 SetLocalDescriptionWithoutError(answer);
2331}
2332
2333// Verifies TransportProxy and media channels are created with content names
2334// present in the SessionDescription.
2335TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002336 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002337 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002338 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339
2340 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002341 // "video". Goal is to modify these content names and verify transport
2342 // channels
2343 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 // present in SDP.
2345 std::string sdp;
2346 EXPECT_TRUE(offer->ToString(&sdp));
2347 const std::string kAudioMid = "a=mid:audio";
2348 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2349 const std::string kVideoMid = "a=mid:video";
2350 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2351
2352 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002353 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 kAudioMidReplaceStr.c_str(),
2355 kAudioMidReplaceStr.length(),
2356 &sdp);
2357 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002358 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 kVideoMidReplaceStr.c_str(),
2360 kVideoMidReplaceStr.length(),
2361 &sdp);
2362
2363 SessionDescriptionInterface* modified_offer =
2364 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2365
2366 SetRemoteDescriptionWithoutError(modified_offer);
2367
htaa2a49d92016-03-04 02:51:39 -08002368 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 SetLocalDescriptionWithoutError(answer);
2370
deadbeefcbecd352015-09-23 11:50:27 -07002371 cricket::TransportChannel* voice_transport_channel =
2372 session_->voice_rtp_transport_channel();
2373 EXPECT_TRUE(voice_transport_channel != NULL);
2374 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2375 cricket::TransportChannel* video_transport_channel =
2376 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002377 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002378 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2380 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2381}
2382
2383// Test that an offer contains the correct media content descriptions based on
2384// the send streams when no constraints have been set.
2385TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002386 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002387 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002388
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 ASSERT_TRUE(offer != NULL);
2390 const cricket::ContentInfo* content =
2391 cricket::GetFirstAudioContent(offer->description());
2392 EXPECT_TRUE(content != NULL);
2393 content = cricket::GetFirstVideoContent(offer->description());
2394 EXPECT_TRUE(content == NULL);
2395}
2396
2397// Test that an offer contains the correct media content descriptions based on
2398// the send streams when no constraints have been set.
2399TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002400 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002402 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002403 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002404
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 const cricket::ContentInfo* content =
2406 cricket::GetFirstAudioContent(offer->description());
2407 EXPECT_TRUE(content != NULL);
2408 content = cricket::GetFirstVideoContent(offer->description());
2409 EXPECT_TRUE(content == NULL);
2410
2411 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002412 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002413 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 content = cricket::GetFirstAudioContent(offer->description());
2415 EXPECT_TRUE(content != NULL);
2416 content = cricket::GetFirstVideoContent(offer->description());
2417 EXPECT_TRUE(content != NULL);
2418}
2419
2420// Test that an offer contains no media content descriptions if
2421// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2422TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002423 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002424 PeerConnectionInterface::RTCOfferAnswerOptions options;
2425 options.offer_to_receive_audio = 0;
2426 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427
kwibergd1fe2812016-04-27 06:47:29 -07002428 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 ASSERT_TRUE(offer != NULL);
2431 const cricket::ContentInfo* content =
2432 cricket::GetFirstAudioContent(offer->description());
2433 EXPECT_TRUE(content == NULL);
2434 content = cricket::GetFirstVideoContent(offer->description());
2435 EXPECT_TRUE(content == NULL);
2436}
2437
2438// Test that an offer contains only audio media content descriptions if
2439// kOfferToReceiveAudio constraints are set to true.
2440TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002441 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002442 PeerConnectionInterface::RTCOfferAnswerOptions options;
2443 options.offer_to_receive_audio =
2444 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2445
kwibergd1fe2812016-04-27 06:47:29 -07002446 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447
2448 const cricket::ContentInfo* content =
2449 cricket::GetFirstAudioContent(offer->description());
2450 EXPECT_TRUE(content != NULL);
2451 content = cricket::GetFirstVideoContent(offer->description());
2452 EXPECT_TRUE(content == NULL);
2453}
2454
2455// Test that an offer contains audio and video media content descriptions if
2456// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2457TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002458 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002460 PeerConnectionInterface::RTCOfferAnswerOptions options;
2461 options.offer_to_receive_audio =
2462 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2463 options.offer_to_receive_video =
2464 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2465
kwibergd1fe2812016-04-27 06:47:29 -07002466 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002467
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 const cricket::ContentInfo* content =
2469 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002470 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 content = cricket::GetFirstVideoContent(offer->description());
2473 EXPECT_TRUE(content != NULL);
2474
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002475 // Sets constraints to false and verifies that audio/video contents are
2476 // removed.
2477 options.offer_to_receive_audio = 0;
2478 options.offer_to_receive_video = 0;
2479 offer.reset(CreateOffer(options));
2480
2481 content = cricket::GetFirstAudioContent(offer->description());
2482 EXPECT_TRUE(content == NULL);
2483 content = cricket::GetFirstVideoContent(offer->description());
2484 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485}
2486
2487// Test that an answer can not be created if the last remote description is not
2488// an offer.
2489TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002490 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002491 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 SetLocalDescriptionWithoutError(offer);
2493 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2494 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002495 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496}
2497
2498// Test that an answer contains the correct media content descriptions when no
2499// constraints have been set.
2500TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002501 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002503 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002505 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 const cricket::ContentInfo* content =
2507 cricket::GetFirstAudioContent(answer->description());
2508 ASSERT_TRUE(content != NULL);
2509 EXPECT_FALSE(content->rejected);
2510
2511 content = cricket::GetFirstVideoContent(answer->description());
2512 ASSERT_TRUE(content != NULL);
2513 EXPECT_FALSE(content->rejected);
2514}
2515
2516// Test that an answer contains the correct media content descriptions when no
2517// constraints have been set and the offer only contain audio.
2518TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002519 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 // Create a remote offer with audio only.
2521 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002522
kwibergd1fe2812016-04-27 06:47:29 -07002523 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2525 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2526
2527 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002528 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 const cricket::ContentInfo* content =
2530 cricket::GetFirstAudioContent(answer->description());
2531 ASSERT_TRUE(content != NULL);
2532 EXPECT_FALSE(content->rejected);
2533
2534 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2535}
2536
2537// Test that an answer contains the correct media content descriptions when no
2538// constraints have been set.
2539TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002542 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002543 SetRemoteDescriptionWithoutError(offer.release());
2544 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002545 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002546 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 const cricket::ContentInfo* content =
2548 cricket::GetFirstAudioContent(answer->description());
2549 ASSERT_TRUE(content != NULL);
2550 EXPECT_FALSE(content->rejected);
2551
2552 content = cricket::GetFirstVideoContent(answer->description());
2553 ASSERT_TRUE(content != NULL);
2554 EXPECT_FALSE(content->rejected);
2555}
2556
2557// Test that an answer contains the correct media content descriptions when
2558// constraints have been set but no stream is sent.
2559TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002560 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002562 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 SetRemoteDescriptionWithoutError(offer.release());
2564
htaa2a49d92016-03-04 02:51:39 -08002565 cricket::MediaSessionOptions session_options;
2566 session_options.recv_audio = false;
2567 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002568 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002569 CreateAnswer(session_options));
2570
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 const cricket::ContentInfo* content =
2572 cricket::GetFirstAudioContent(answer->description());
2573 ASSERT_TRUE(content != NULL);
2574 EXPECT_TRUE(content->rejected);
2575
2576 content = cricket::GetFirstVideoContent(answer->description());
2577 ASSERT_TRUE(content != NULL);
2578 EXPECT_TRUE(content->rejected);
2579}
2580
2581// Test that an answer contains the correct media content descriptions when
2582// constraints have been set and streams are sent.
2583TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002586 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 SetRemoteDescriptionWithoutError(offer.release());
2588
htaa2a49d92016-03-04 02:51:39 -08002589 cricket::MediaSessionOptions options;
2590 options.recv_audio = false;
2591 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592
2593 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002594 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002595 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596
2597 // TODO(perkj): Should the direction be set to SEND_ONLY?
2598 const cricket::ContentInfo* content =
2599 cricket::GetFirstAudioContent(answer->description());
2600 ASSERT_TRUE(content != NULL);
2601 EXPECT_FALSE(content->rejected);
2602
2603 // TODO(perkj): Should the direction be set to SEND_ONLY?
2604 content = cricket::GetFirstVideoContent(answer->description());
2605 ASSERT_TRUE(content != NULL);
2606 EXPECT_FALSE(content->rejected);
2607}
2608
2609TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2610 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002611 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002612 PeerConnectionInterface::RTCOfferAnswerOptions options;
2613 options.offer_to_receive_audio =
2614 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2615 options.voice_activity_detection = false;
2616
kwibergd1fe2812016-04-27 06:47:29 -07002617 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002618
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 const cricket::ContentInfo* content =
2620 cricket::GetFirstAudioContent(offer->description());
2621 EXPECT_TRUE(content != NULL);
2622 EXPECT_TRUE(VerifyNoCNCodecs(content));
2623}
2624
2625TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2626 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002627 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002629 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 SetRemoteDescriptionWithoutError(offer.release());
2631
htaa2a49d92016-03-04 02:51:39 -08002632 cricket::MediaSessionOptions options;
2633 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002634 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 const cricket::ContentInfo* content =
2636 cricket::GetFirstAudioContent(answer->description());
2637 ASSERT_TRUE(content != NULL);
2638 EXPECT_TRUE(VerifyNoCNCodecs(content));
2639}
2640
2641// This test verifies the call setup when remote answer with audio only and
2642// later updates with video.
2643TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002644 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2646 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2647
deadbeefab9b2d12015-10-14 11:33:11 -07002648 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002649 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650
2651 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2653
2654 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2655 // and answer;
2656 SetLocalDescriptionWithoutError(offer);
2657 SetRemoteDescriptionWithoutError(answer);
2658
2659 video_channel_ = media_engine_->GetVideoChannel(0);
2660 voice_channel_ = media_engine_->GetVoiceChannel(0);
2661
2662 ASSERT_TRUE(video_channel_ == NULL);
2663
2664 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2665 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2666 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2667
2668 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002669 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 CreateAndSetRemoteOfferAndLocalAnswer();
2671
2672 video_channel_ = media_engine_->GetVideoChannel(0);
2673 voice_channel_ = media_engine_->GetVoiceChannel(0);
2674
2675 ASSERT_TRUE(video_channel_ != NULL);
2676 ASSERT_TRUE(voice_channel_ != NULL);
2677
2678 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2679 ASSERT_EQ(1u, video_channel_->send_streams().size());
2680 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2681 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2682 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2683 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2684 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2685 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2686
2687 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002688 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 CreateAndSetRemoteOfferAndLocalAnswer();
2690
2691 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2694 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2695 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2696}
2697
2698// This test verifies the call setup when remote answer with video only and
2699// later updates with audio.
2700TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002701 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2703 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002704 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002705 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706
2707 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002708 options.recv_audio = false;
2709 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2711 offer, options, cricket::SEC_ENABLED);
2712
2713 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2714 // and answer.
2715 SetLocalDescriptionWithoutError(offer);
2716 SetRemoteDescriptionWithoutError(answer);
2717
2718 video_channel_ = media_engine_->GetVideoChannel(0);
2719 voice_channel_ = media_engine_->GetVoiceChannel(0);
2720
2721 ASSERT_TRUE(voice_channel_ == NULL);
2722 ASSERT_TRUE(video_channel_ != NULL);
2723
2724 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2725 ASSERT_EQ(1u, video_channel_->send_streams().size());
2726 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2727
2728 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002729 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 CreateAndSetRemoteOfferAndLocalAnswer();
2731
2732 voice_channel_ = media_engine_->GetVoiceChannel(0);
2733 ASSERT_TRUE(voice_channel_ != NULL);
2734
2735 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2736 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2737 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2738 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2739
2740 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002741 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 CreateAndSetRemoteOfferAndLocalAnswer();
2743
2744 video_channel_ = media_engine_->GetVideoChannel(0);
2745 voice_channel_ = media_engine_->GetVoiceChannel(0);
2746
2747 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2748 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2749 ASSERT_EQ(1u, video_channel_->send_streams().size());
2750 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2751}
2752
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002754 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002755 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002756 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 VerifyCryptoParams(offer->description());
2758 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002759 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760 VerifyCryptoParams(answer->description());
2761}
2762
2763TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002764 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002765 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002766 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002767 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 VerifyNoCryptoParams(offer->description(), false);
2769}
2770
2771TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002772 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773 VerifyAnswerFromNonCryptoOffer();
2774}
2775
2776TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002777 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002778 VerifyAnswerFromCryptoOffer();
2779}
2780
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002781// This test verifies that setLocalDescription fails if
2782// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2783TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002785 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002786 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002787
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002788 std::string sdp;
2789 RemoveIceUfragPwdLines(offer.get(), &sdp);
2790 SessionDescriptionInterface* modified_offer =
2791 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002792 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002793}
2794
2795// This test verifies that setRemoteDescription fails if
2796// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2797TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002798 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002799 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002800 std::string sdp;
2801 RemoveIceUfragPwdLines(offer.get(), &sdp);
2802 SessionDescriptionInterface* modified_offer =
2803 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002804 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002805}
2806
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002807// This test verifies that setLocalDescription fails if local offer has
2808// too short ice ufrag and pwd strings.
2809TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002810 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002811 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002812 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002813 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2814 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002815 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002816 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002817 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002818
2819 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002820 offer.reset(CreateOffer());
2821 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2822 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002823}
2824
2825// This test verifies that setRemoteDescription fails if remote offer has
2826// too short ice ufrag and pwd strings.
2827TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002828 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002829 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002830 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2831 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002832 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002833 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002834 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002835
deadbeef0ed85b22016-02-23 17:24:52 -08002836 offer.reset(CreateRemoteOffer());
2837 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2838 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002839}
2840
Honghai Zhang04e91462015-12-11 14:26:22 -08002841// Test that if the remote offer indicates the peer requested ICE restart (via
2842// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2843TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002844 Init();
honghaiz503726c2015-07-31 12:37:38 -07002845
2846 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002847 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002848 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002849 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2850 0, "", "", "relay", 0, "");
2851 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2852 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002853 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2854 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002855 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2856
2857 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002858 offer.reset(CreateRemoteOffer());
2859 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002860 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2861 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2862 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002863 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2864 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002865 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2866
2867 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002868 offer.reset(CreateRemoteOffer());
2869 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002870 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2871 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2872 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002873 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2874 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002875 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2876
2877 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002878 offer.reset(CreateRemoteOffer());
2879 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2880 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002881 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2882}
2883
Honghai Zhang04e91462015-12-11 14:26:22 -08002884// Test that if the remote answer indicates the peer requested ICE restart (via
2885// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2886TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2887 Init();
2888 SessionDescriptionInterface* offer = CreateOffer();
2889 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002890
2891 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002892 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002893 answer->set_type(JsepSessionDescription::kPrAnswer);
2894 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002895 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2896 0, "", "", "relay", 0, "");
2897 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2898 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002899 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2900 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002901 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2902
2903 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002904 answer.reset(CreateRemoteAnswer(offer));
2905 answer->set_type(JsepSessionDescription::kPrAnswer);
2906 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002907 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2908 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2909 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002910 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2911 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002912 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2913
2914 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002915 answer.reset(CreateRemoteAnswer(offer));
2916 answer->set_type(JsepSessionDescription::kPrAnswer);
2917 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002918 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2919 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2920 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002921 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2922 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002923 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2924
2925 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002926 answer.reset(CreateRemoteAnswer(offer));
2927 answer->set_type(JsepSessionDescription::kPrAnswer);
2928 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2929 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002930 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2931}
2932
Donald Curtisd4f769d2015-05-28 09:48:21 -07002933// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002934// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002935TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2936 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2937
2938 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002939 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002940
2941 PeerConnectionInterface::RTCOfferAnswerOptions options;
2942 options.use_rtp_mux = true;
2943
2944 SessionDescriptionInterface* offer = CreateRemoteOffer();
2945 SetRemoteDescriptionWithoutError(offer);
2946
htaa2a49d92016-03-04 02:51:39 -08002947 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002948 SetLocalDescriptionWithoutError(answer);
2949
deadbeefcbecd352015-09-23 11:50:27 -07002950 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2951 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002952
deadbeefcbecd352015-09-23 11:50:27 -07002953 cricket::BaseChannel* voice_channel = session_->voice_channel();
2954 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002955
2956 // Checks if one of the transport channels contains a connection using a given
2957 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002958 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002959 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002960 session_->GetChannelTransportStats(voice_channel, &stats);
2961 for (auto& kv : stats.transport_stats) {
2962 for (auto& chan_stat : kv.second.channel_stats) {
2963 for (auto& conn_info : chan_stat.connection_infos) {
2964 if (conn_info.remote_candidate.address().port() == port) {
2965 return true;
2966 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002967 }
2968 }
2969 }
2970 return false;
2971 };
2972
2973 EXPECT_FALSE(connection_with_remote_port(5000));
2974 EXPECT_FALSE(connection_with_remote_port(5001));
2975 EXPECT_FALSE(connection_with_remote_port(6000));
2976
2977 // The way the *_WAIT checks work is they only wait if the condition fails,
2978 // which does not help in the case where state is not changing. This is
2979 // problematic in this test since we want to verify that adding a video
2980 // candidate does _not_ change state. So we interleave candidates and assume
2981 // that messages are executed in the order they were posted.
2982
2983 // First audio candidate.
2984 cricket::Candidate candidate0;
2985 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2986 candidate0.set_component(1);
2987 candidate0.set_protocol("udp");
2988 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2989 candidate0);
2990 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2991
2992 // Video candidate.
2993 cricket::Candidate candidate1;
2994 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2995 candidate1.set_component(1);
2996 candidate1.set_protocol("udp");
2997 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2998 candidate1);
2999 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3000
3001 // Second audio candidate.
3002 cricket::Candidate candidate2;
3003 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3004 candidate2.set_component(1);
3005 candidate2.set_protocol("udp");
3006 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3007 candidate2);
3008 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3009
3010 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3011 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3012
3013 // No need here for a _WAIT check since we are checking that state hasn't
3014 // changed: if this is false we would be doing waits for nothing and if this
3015 // is true then there will be no messages processed anyways.
3016 EXPECT_FALSE(connection_with_remote_port(6000));
3017}
3018
deadbeefcbecd352015-09-23 11:50:27 -07003019// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003020TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3021 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003022 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003023
3024 PeerConnectionInterface::RTCOfferAnswerOptions options;
3025 options.use_rtp_mux = true;
3026
3027 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003029
deadbeefcbecd352015-09-23 11:50:27 -07003030 EXPECT_NE(session_->voice_rtp_transport_channel(),
3031 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003032
deadbeefab9b2d12015-10-14 11:33:11 -07003033 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003034 SessionDescriptionInterface* answer =
3035 CreateRemoteAnswer(session_->local_description());
3036 SetRemoteDescriptionWithoutError(answer);
3037
deadbeefcbecd352015-09-23 11:50:27 -07003038 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3039 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003040}
3041
deadbeefcbecd352015-09-23 11:50:27 -07003042// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003043TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3044 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003045 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003046
Donald Curtis0e209b02015-03-24 09:29:54 -07003047 PeerConnectionInterface::RTCOfferAnswerOptions options;
3048 options.use_rtp_mux = true;
3049
3050 SessionDescriptionInterface* offer = CreateOffer(options);
3051 SetLocalDescriptionWithoutError(offer);
3052
deadbeefcbecd352015-09-23 11:50:27 -07003053 EXPECT_NE(session_->voice_rtp_transport_channel(),
3054 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003055
deadbeefab9b2d12015-10-14 11:33:11 -07003056 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003057
3058 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003059 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003060 CreateRemoteAnswer(session_->local_description()));
3061 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3062 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3063 JsepSessionDescription* modified_answer =
3064 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3065 modified_answer->Initialize(answer_copy, "1", "1");
3066 SetRemoteDescriptionWithoutError(modified_answer); //
3067
deadbeefcbecd352015-09-23 11:50:27 -07003068 EXPECT_NE(session_->voice_rtp_transport_channel(),
3069 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003070}
3071
3072// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3073TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3074 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003075 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003076
3077 PeerConnectionInterface::RTCOfferAnswerOptions options;
3078 options.use_rtp_mux = true;
3079
3080 SessionDescriptionInterface* offer = CreateOffer(options);
3081 SetLocalDescriptionWithoutError(offer);
3082
deadbeefcbecd352015-09-23 11:50:27 -07003083 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3084 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003085
deadbeefab9b2d12015-10-14 11:33:11 -07003086 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003087 SessionDescriptionInterface* answer =
3088 CreateRemoteAnswer(session_->local_description());
3089 SetRemoteDescriptionWithoutError(answer);
3090
deadbeefcbecd352015-09-23 11:50:27 -07003091 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3092 session_->video_rtp_transport_channel());
3093}
3094
3095// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3096// audio content in the answer.
3097TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3098 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003099 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003100
3101 PeerConnectionInterface::RTCOfferAnswerOptions options;
3102 options.use_rtp_mux = true;
3103
3104 SessionDescriptionInterface* offer = CreateOffer(options);
3105 SetLocalDescriptionWithoutError(offer);
3106
3107 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3108 session_->video_rtp_transport_channel());
3109
deadbeefab9b2d12015-10-14 11:33:11 -07003110 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003111 cricket::MediaSessionOptions recv_options;
3112 recv_options.recv_audio = false;
3113 recv_options.recv_video = true;
3114 SessionDescriptionInterface* answer =
3115 CreateRemoteAnswer(session_->local_description(), recv_options);
3116 SetRemoteDescriptionWithoutError(answer);
3117
deadbeefd59daf82015-10-14 15:02:44 -07003118 EXPECT_TRUE(nullptr == session_->voice_channel());
3119 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003120
deadbeefd59daf82015-10-14 15:02:44 -07003121 session_->Close();
3122 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3123 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3124 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3125 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003126}
3127
3128// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3129TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3130 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003131 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003132
Donald Curtis0e209b02015-03-24 09:29:54 -07003133 PeerConnectionInterface::RTCOfferAnswerOptions options;
3134 options.use_rtp_mux = true;
3135
3136 SessionDescriptionInterface* offer = CreateOffer(options);
3137 SetLocalDescriptionWithoutError(offer);
3138
deadbeefcbecd352015-09-23 11:50:27 -07003139 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3140 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003141
deadbeefab9b2d12015-10-14 11:33:11 -07003142 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003143
3144 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003145 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 CreateRemoteAnswer(session_->local_description()));
3147 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3148 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3149 JsepSessionDescription* modified_answer =
3150 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3151 modified_answer->Initialize(answer_copy, "1", "1");
3152 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153
deadbeefcbecd352015-09-23 11:50:27 -07003154 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3155 session_->video_rtp_transport_channel());
3156}
3157
3158// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3159TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3160 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003161 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003162
3163 SessionDescriptionInterface* offer = CreateRemoteOffer();
3164 SetRemoteDescriptionWithoutError(offer);
3165
3166 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3167 session_->video_rtp_transport_channel());
3168
deadbeefab9b2d12015-10-14 11:33:11 -07003169 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003170 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003171 SetLocalDescriptionWithoutError(answer);
3172
3173 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3174 session_->video_rtp_transport_channel());
3175}
3176
3177// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3178TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3179 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003180 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003181
3182 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003183 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003184 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3185 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3186 JsepSessionDescription* modified_offer =
3187 new JsepSessionDescription(JsepSessionDescription::kOffer);
3188 modified_offer->Initialize(offer_copy, "1", "1");
3189
3190 // Expect an error when applying the remote description
3191 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3192 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003193}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003194
Peter Thatcher4eddf182015-04-30 10:55:59 -07003195// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003196TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3197 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003198 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199
Donald Curtis0e209b02015-03-24 09:29:54 -07003200 PeerConnectionInterface::RTCOfferAnswerOptions options;
3201 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202
Donald Curtis0e209b02015-03-24 09:29:54 -07003203 SessionDescriptionInterface* offer = CreateOffer(options);
3204 SetLocalDescriptionWithoutError(offer);
3205
deadbeefcbecd352015-09-23 11:50:27 -07003206 EXPECT_NE(session_->voice_rtp_transport_channel(),
3207 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003208
deadbeefab9b2d12015-10-14 11:33:11 -07003209 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003210 SessionDescriptionInterface* answer =
3211 CreateRemoteAnswer(session_->local_description());
3212 SetRemoteDescriptionWithoutError(answer);
3213
3214 // This should lead to an audio-only call but isn't implemented
3215 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003216 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3217 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003218}
3219
deadbeefcbecd352015-09-23 11:50:27 -07003220// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003221TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3222 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003224 PeerConnectionInterface::RTCOfferAnswerOptions options;
3225 options.use_rtp_mux = true;
3226
3227 SessionDescriptionInterface* offer = CreateOffer(options);
3228 SetLocalDescriptionWithoutError(offer);
3229
deadbeefcbecd352015-09-23 11:50:27 -07003230 EXPECT_NE(session_->voice_rtp_transport_channel(),
3231 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003232
deadbeefab9b2d12015-10-14 11:33:11 -07003233 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003234
3235 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003236 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003237 CreateRemoteAnswer(session_->local_description()));
3238 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3239 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3240 JsepSessionDescription* modified_answer =
3241 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3242 modified_answer->Initialize(answer_copy, "1", "1");
3243 SetRemoteDescriptionWithoutError(modified_answer); //
3244
deadbeefcbecd352015-09-23 11:50:27 -07003245 EXPECT_NE(session_->voice_rtp_transport_channel(),
3246 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247}
3248
Peter Thatcher4eddf182015-04-30 10:55:59 -07003249// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3250TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3251 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003253
3254 PeerConnectionInterface::RTCOfferAnswerOptions options;
3255 options.use_rtp_mux = true;
3256
3257 SessionDescriptionInterface* offer = CreateOffer(options);
3258 SetRemoteDescriptionWithoutError(offer);
3259
deadbeefcbecd352015-09-23 11:50:27 -07003260 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3261 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003262}
3263
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003264TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3265 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003267
3268 PeerConnectionInterface::RTCOfferAnswerOptions options;
3269 SessionDescriptionInterface* offer = CreateOffer(options);
3270 SetLocalDescriptionWithoutError(offer);
3271
deadbeefcbecd352015-09-23 11:50:27 -07003272 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3273 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003274
deadbeefab9b2d12015-10-14 11:33:11 -07003275 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003276 SessionDescriptionInterface* answer =
3277 CreateRemoteAnswer(session_->local_description());
3278 SetRemoteDescriptionWithoutError(answer);
3279
deadbeefcbecd352015-09-23 11:50:27 -07003280 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3281 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003282}
3283
3284TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3285 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003286 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003287
3288 PeerConnectionInterface::RTCOfferAnswerOptions options;
3289 SessionDescriptionInterface* offer = CreateOffer(options);
3290 SetLocalDescriptionWithoutError(offer);
3291
deadbeefcbecd352015-09-23 11:50:27 -07003292 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3293 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003294
deadbeefab9b2d12015-10-14 11:33:11 -07003295 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003296 SessionDescriptionInterface* answer =
3297 CreateRemoteAnswer(session_->local_description());
3298 SetRemoteDescriptionWithoutError(answer);
3299
deadbeefcbecd352015-09-23 11:50:27 -07003300 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3301 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003302}
3303
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003304// This test verifies that SetLocalDescription and SetRemoteDescription fails
3305// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3306TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003307 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003308 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003309
3310 PeerConnectionInterface::RTCOfferAnswerOptions options;
3311 options.use_rtp_mux = true;
3312
3313 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003314 std::string offer_str;
3315 offer->ToString(&offer_str);
3316 // Disable rtcp-mux
3317 const std::string rtcp_mux = "rtcp-mux";
3318 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003319 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003320 xrtcp_mux.c_str(), xrtcp_mux.length(),
3321 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003322 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003323 new JsepSessionDescription(JsepSessionDescription::kOffer);
3324 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003325 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003326 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003327 new JsepSessionDescription(JsepSessionDescription::kOffer);
3328 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003329 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003330 // Trying unmodified SDP.
3331 SetLocalDescriptionWithoutError(offer);
3332}
3333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003335 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003336 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337 CreateAndSetRemoteOfferAndLocalAnswer();
3338 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3339 ASSERT_TRUE(channel != NULL);
3340 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003341 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003342 double volume;
3343 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3344 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003345 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003346 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3347 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003348 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003349 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3350 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351}
3352
skvlade0d46372016-04-07 22:59:22 -07003353TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003354 Init();
3355 SendAudioVideoStream1();
3356 CreateAndSetRemoteOfferAndLocalAnswer();
3357 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3358 ASSERT_TRUE(channel != NULL);
3359 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003360 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003361 webrtc::RtpParameters params = session_->GetAudioRtpParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003362 EXPECT_EQ(1, params.encodings.size());
3363 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3364 params.encodings[0].max_bitrate_bps = 1000;
3365 EXPECT_TRUE(session_->SetAudioRtpParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003366
skvlade0d46372016-04-07 22:59:22 -07003367 // Read back the parameters and verify they have been changed.
3368 params = session_->GetAudioRtpParameters(send_ssrc);
3369 EXPECT_EQ(1, params.encodings.size());
3370 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3371
3372 // Verify that the audio channel received the new parameters.
3373 params = channel->GetRtpParameters(send_ssrc);
3374 EXPECT_EQ(1, params.encodings.size());
3375 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3376
3377 // Verify that the global bitrate limit has not been changed.
3378 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003379}
3380
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003382 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003383 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 CreateAndSetRemoteOfferAndLocalAnswer();
3385 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3386 ASSERT_TRUE(channel != NULL);
3387 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003388 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3390
3391 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003392 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003393
kwibergd1fe2812016-04-27 06:47:29 -07003394 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003395 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003397 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003398 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003400 // This will trigger SetSink(nullptr) to the |source|.
3401 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003403 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003404 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003405}
3406
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003407TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003408 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003409 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003410 CreateAndSetRemoteOfferAndLocalAnswer();
3411 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3412 ASSERT_TRUE(channel != NULL);
3413 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003414 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003415
kwibergd1fe2812016-04-27 06:47:29 -07003416 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003417 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003418 session_->SetAudioSend(send_ssrc, true, options, source.get());
3419 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003420
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003421 // Delete the |source| and it will trigger OnClose() to the sink, and this
3422 // will invalidate the |source_| pointer in the sink and prevent getting a
3423 // SetSink(nullptr) callback afterwards.
3424 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003425
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003426 // This will trigger SetSink(nullptr) if no OnClose() callback.
3427 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428}
3429
3430TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003431 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003432 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 CreateAndSetRemoteOfferAndLocalAnswer();
3434 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3435 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003436 ASSERT_LT(0u, channel->sinks().size());
3437 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003439 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 cricket::FakeVideoRenderer renderer;
3441 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003442 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003444 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445}
3446
skvladdc1c62c2016-03-16 19:07:43 -07003447TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3448 Init();
3449 SendAudioVideoStream1();
3450 CreateAndSetRemoteOfferAndLocalAnswer();
3451 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3452 ASSERT_TRUE(channel != NULL);
3453 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3454 EXPECT_EQ(-1, channel->max_bps());
3455 webrtc::RtpParameters params = session_->GetVideoRtpParameters(send_ssrc);
3456 EXPECT_EQ(1, params.encodings.size());
3457 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3458 params.encodings[0].max_bitrate_bps = 1000;
3459 EXPECT_TRUE(session_->SetVideoRtpParameters(send_ssrc, params));
3460
3461 // Read back the parameters and verify they have been changed.
3462 params = session_->GetVideoRtpParameters(send_ssrc);
3463 EXPECT_EQ(1, params.encodings.size());
3464 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3465
3466 // Verify that the video channel received the new parameters.
3467 params = channel->GetRtpParameters(send_ssrc);
3468 EXPECT_EQ(1, params.encodings.size());
3469 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3470
3471 // Verify that the global bitrate limit has not been changed.
3472 EXPECT_EQ(-1, channel->max_bps());
3473}
3474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003476 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003477 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 CreateAndSetRemoteOfferAndLocalAnswer();
3479 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3480 ASSERT_TRUE(channel != NULL);
3481 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003482 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3484 cricket::VideoOptions* options = NULL;
3485 session_->SetVideoSend(send_ssrc, false, options);
3486 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3487 session_->SetVideoSend(send_ssrc, true, options);
3488 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3489}
3490
3491TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3492 TestCanInsertDtmf(false);
3493}
3494
3495TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3496 TestCanInsertDtmf(true);
3497}
3498
3499TEST_F(WebRtcSessionTest, InsertDtmf) {
3500 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003501 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003502 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 CreateAndSetRemoteOfferAndLocalAnswer();
3504 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3505 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3506
3507 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508 const int expected_duration = 90;
3509 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3510 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3511 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3512
3513 // Verify
3514 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003515 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003517 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003519 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003521 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522}
3523
deadbeefd59daf82015-10-14 15:02:44 -07003524// This test verifies the |initial_offerer| flag when session initiates the
3525// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003526TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003527 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003528 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003529 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3531 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003532 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003534 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535}
3536
deadbeefd59daf82015-10-14 15:02:44 -07003537// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003539 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003540 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541 SessionDescriptionInterface* offer = CreateRemoteOffer();
3542 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003543 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544
deadbeefd59daf82015-10-14 15:02:44 -07003545 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003547 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003548}
3549
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3551TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003552 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003553 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003554 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003556 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003557 CreateRemoteAnswer(session_->local_description()));
3558
3559 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3560 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003561 JsepSessionDescription* modified_answer =
3562 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563
3564 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3565 answer->session_id(),
3566 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003567 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568
wu@webrtc.org4e393072014-04-07 17:04:35 +00003569 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570 std::string sdp;
3571 EXPECT_TRUE(answer->ToString(&sdp));
3572 const std::string kAudioMid = "a=mid:audio";
3573 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003574 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 kAudioMidReplaceStr.c_str(),
3576 kAudioMidReplaceStr.length(),
3577 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003578 SessionDescriptionInterface* modified_answer1 =
3579 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003580 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581
wu@webrtc.org4e393072014-04-07 17:04:35 +00003582 // Different media types.
3583 EXPECT_TRUE(answer->ToString(&sdp));
3584 const std::string kAudioMline = "m=audio";
3585 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003586 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003587 kAudioMlineReplaceStr.c_str(),
3588 kAudioMlineReplaceStr.length(),
3589 &sdp);
3590 SessionDescriptionInterface* modified_answer2 =
3591 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3592 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3593
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 SetRemoteDescriptionWithoutError(answer.release());
3595}
3596
3597// Verifying remote offer and local answer have matching m-lines as per
3598// RFC 3264.
3599TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003600 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003601 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 SessionDescriptionInterface* offer = CreateRemoteOffer();
3603 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003604 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605
3606 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3607 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003608 JsepSessionDescription* modified_answer =
3609 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610
3611 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3612 answer->session_id(),
3613 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003614 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003615 SetLocalDescriptionWithoutError(answer);
3616}
3617
3618// This test verifies that WebRtcSession does not start candidate allocation
3619// before SetLocalDescription is called.
3620TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003621 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003622 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 SessionDescriptionInterface* offer = CreateRemoteOffer();
3624 cricket::Candidate candidate;
3625 candidate.set_component(1);
3626 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3627 candidate);
3628 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3629 cricket::Candidate candidate1;
3630 candidate1.set_component(1);
3631 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3632 candidate1);
3633 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3634 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003635 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3636 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637
3638 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003639 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3641 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3642
htaa2a49d92016-03-04 02:51:39 -08003643 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003644 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003645 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3646}
3647
3648// This test verifies that crypto parameter is updated in local session
3649// description as per security policy set in MediaSessionDescriptionFactory.
3650TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003651 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003652 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003653 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003654
3655 // Making sure SetLocalDescription correctly sets crypto value in
3656 // SessionDescription object after de-serialization of sdp string. The value
3657 // will be set as per MediaSessionDescriptionFactory.
3658 std::string offer_str;
3659 offer->ToString(&offer_str);
3660 SessionDescriptionInterface* jsep_offer_str =
3661 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3662 SetLocalDescriptionWithoutError(jsep_offer_str);
3663 EXPECT_TRUE(session_->voice_channel()->secure_required());
3664 EXPECT_TRUE(session_->video_channel()->secure_required());
3665}
3666
3667// This test verifies the crypto parameter when security is disabled.
3668TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003669 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003670 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003671 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003672 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673
3674 // Making sure SetLocalDescription correctly sets crypto value in
3675 // SessionDescription object after de-serialization of sdp string. The value
3676 // will be set as per MediaSessionDescriptionFactory.
3677 std::string offer_str;
3678 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003679 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3681 SetLocalDescriptionWithoutError(jsep_offer_str);
3682 EXPECT_FALSE(session_->voice_channel()->secure_required());
3683 EXPECT_FALSE(session_->video_channel()->secure_required());
3684}
3685
3686// This test verifies that an answer contains new ufrag and password if an offer
3687// with new ufrag and password is received.
3688TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003689 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003691 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003692 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003693 SetRemoteDescriptionWithoutError(offer.release());
3694
deadbeefab9b2d12015-10-14 11:33:11 -07003695 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003696 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003697 SetLocalDescriptionWithoutError(answer.release());
3698
3699 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003700 for (const cricket::ContentInfo& content :
3701 session_->local_description()->description()->contents()) {
3702 options.transport_options[content.name].ice_restart = true;
3703 }
kwibergd1fe2812016-04-27 06:47:29 -07003704 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003705 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706 SetRemoteDescriptionWithoutError(updated_offer1.release());
3707
kwibergd1fe2812016-04-27 06:47:29 -07003708 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709
deadbeef0ed85b22016-02-23 17:24:52 -08003710 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3711 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712
deadbeef0ed85b22016-02-23 17:24:52 -08003713 // Even a second answer (created before the description is set) should have
3714 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003715 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003716
3717 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3718 session_->local_description()->description()));
3719
3720 SetLocalDescriptionWithoutError(updated_answer2.release());
3721}
3722
3723// This test verifies that an answer contains new ufrag and password if an offer
3724// that changes either the ufrag or password (but not both) is received.
3725// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3726// a=ice-pwd attributes compared to the previous SDP from the peer, it
3727// indicates that ICE is restarting for this media stream."
3728TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3729 Init();
3730 cricket::MediaSessionOptions options;
3731 options.recv_audio = true;
3732 options.recv_video = true;
3733 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003735 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3736 SetRemoteDescriptionWithoutError(offer.release());
3737
3738 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003739 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003740 SetLocalDescriptionWithoutError(answer.release());
3741
3742 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003743 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003744 CreateRemoteOffer(options, session_->remote_description()));
3745 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3746 "original_password12345");
3747 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3748
kwibergd1fe2812016-04-27 06:47:29 -07003749 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003750 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3751 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003752 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003753
3754 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003755 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003756 CreateRemoteOffer(options, session_->remote_description()));
3757 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3758 "modified_password12345");
3759 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3760
kwibergd1fe2812016-04-27 06:47:29 -07003761 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003762 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3763 session_->local_description()->description()));
3764 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003765}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766
wu@webrtc.org91053e72013-08-10 07:18:04 +00003767// This test verifies that an answer contains old ufrag and password if an offer
3768// with old ufrag and password is received.
3769TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003770 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003771 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003772 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003773 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003774 SetRemoteDescriptionWithoutError(offer.release());
3775
deadbeefab9b2d12015-10-14 11:33:11 -07003776 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003777 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003778 SetLocalDescriptionWithoutError(answer.release());
3779
3780 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003781 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003782 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003783 SetRemoteDescriptionWithoutError(updated_offer2.release());
3784
kwibergd1fe2812016-04-27 06:47:29 -07003785 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003786
deadbeef0ed85b22016-02-23 17:24:52 -08003787 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3788 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003789
3790 SetLocalDescriptionWithoutError(updated_answer2.release());
3791}
3792
deadbeef0ed85b22016-02-23 17:24:52 -08003793// This test verifies that if an offer does an ICE restart on some, but not all
3794// media sections, the answer will change the ufrag/password in the correct
3795// media sections.
3796TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3797 Init();
3798 cricket::MediaSessionOptions options;
3799 options.recv_video = true;
3800 options.recv_audio = true;
3801 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003802 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003803
3804 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3805 "aaaaaaaaaaaaaaaaaaaaaa");
3806 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3807 "bbbbbbbbbbbbbbbbbbbbbb");
3808 SetRemoteDescriptionWithoutError(offer.release());
3809
3810 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003811 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003812 SetLocalDescriptionWithoutError(answer.release());
3813
3814 // Receive an offer with new ufrag and password, but only for the video media
3815 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003816 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003817 CreateRemoteOffer(options, session_->remote_description()));
3818 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3819 "cccccccccccccccccccccc");
3820 SetRemoteDescriptionWithoutError(updated_offer.release());
3821
kwibergd1fe2812016-04-27 06:47:29 -07003822 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003823
3824 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3825 session_->local_description()->description(),
3826 cricket::MEDIA_TYPE_AUDIO));
3827
3828 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3829 session_->local_description()->description(),
3830 cricket::MEDIA_TYPE_VIDEO));
3831
3832 SetLocalDescriptionWithoutError(updated_answer.release());
3833}
3834
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003835TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003836 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003837 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003838 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003839 const std::string session_id_orig = offer->session_id();
3840 const std::string session_version_orig = offer->session_version();
3841 SetLocalDescriptionWithoutError(offer);
3842
3843 video_channel_ = media_engine_->GetVideoChannel(0);
3844 video_channel_->set_fail_set_send_codecs(true);
3845
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003846 SessionDescriptionInterface* answer =
3847 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003848 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003849
3850 // Test that after a content error, setting any description will
3851 // result in an error.
3852 video_channel_->set_fail_set_send_codecs(false);
3853 answer = CreateRemoteAnswer(session_->local_description());
3854 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3855 offer = CreateRemoteOffer();
3856 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003857}
3858
3859// Runs the loopback call test with BUNDLE and STUN disabled.
3860TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3861 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003862 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003863 cricket::PORTALLOCATOR_DISABLE_STUN |
3864 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003865 TestLoopbackCall();
3866}
3867
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003868TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003869 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003870 cricket::PORTALLOCATOR_DISABLE_STUN |
3871 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3872 cricket::PORTALLOCATOR_DISABLE_RELAY);
3873
3874 // best connection is IPv6 since it has higher network preference.
3875 LoopbackNetworkConfiguration config;
3876 config.test_ipv6_network_ = true;
3877 config.best_connection_after_initial_ice_converged_ =
3878 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3879
3880 TestLoopbackCall(config);
3881}
3882
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003883// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003884TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003885 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3886 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003887 TestLoopbackCall();
3888}
3889
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003890TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003891 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003892 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003893 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003894 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003895 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3896}
3897
Henrik Boström87713d02015-08-25 09:53:21 +02003898TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003899 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003900
htaa2a49d92016-03-04 02:51:39 -08003901 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003902 options_.disable_sctp_data_channels = false;
3903
Henrik Boström87713d02015-08-25 09:53:21 +02003904 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003905
3906 SetLocalDescriptionWithDataChannel();
3907 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3908}
3909
Henrik Boström87713d02015-08-25 09:53:21 +02003910TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003911 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003912
Henrik Boström87713d02015-08-25 09:53:21 +02003913 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003914
kwibergd1fe2812016-04-27 06:47:29 -07003915 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003916 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003917 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3918}
3919
Henrik Boström87713d02015-08-25 09:53:21 +02003920TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003921 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003922 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003923 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003924
3925 // Create remote offer with SCTP.
3926 cricket::MediaSessionOptions options;
3927 options.data_channel_type = cricket::DCT_SCTP;
3928 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003929 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003930 SetRemoteDescriptionWithoutError(offer);
3931
3932 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003933 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003934 EXPECT_TRUE(answer != NULL);
3935 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3936 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003937}
3938
Henrik Boström87713d02015-08-25 09:53:21 +02003939TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003940 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003941 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003942
3943 SetLocalDescriptionWithDataChannel();
3944 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3945}
3946
Henrik Boström87713d02015-08-25 09:53:21 +02003947TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003948 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003949
Henrik Boström87713d02015-08-25 09:53:21 +02003950 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003951
3952 SetLocalDescriptionWithDataChannel();
3953 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3954}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003955
Henrik Boström87713d02015-08-25 09:53:21 +02003956TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003957 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003958 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003959 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003960
3961 SetLocalDescriptionWithDataChannel();
3962 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3963}
3964
Henrik Boström87713d02015-08-25 09:53:21 +02003965TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003966 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003967 const int new_send_port = 9998;
3968 const int new_recv_port = 7775;
3969
Henrik Boström87713d02015-08-25 09:53:21 +02003970 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003971 SetFactoryDtlsSrtp();
3972
3973 // By default, don't actually add the codecs to desc_factory_; they don't
3974 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3975 // let the session description get parsed. That'll get the proper codecs
3976 // into the stream.
3977 cricket::MediaSessionOptions options;
3978 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3979 "stream1", new_send_port, options);
3980
3981 // SetRemoteDescription will take the ownership of the offer.
3982 SetRemoteDescriptionWithoutError(offer);
3983
htaa2a49d92016-03-04 02:51:39 -08003984 SessionDescriptionInterface* answer =
3985 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003986 ASSERT_TRUE(answer != NULL);
3987
3988 // Now set the local description, which'll take ownership of the answer.
3989 SetLocalDescriptionWithoutError(answer);
3990
3991 // TEST PLAN: Set the port number to something new, set it in the SDP,
3992 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003993 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003994 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003995
3996 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3997 int portnum = -1;
3998 ASSERT_TRUE(ch != NULL);
3999 ASSERT_EQ(1UL, ch->send_codecs().size());
4000 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004001 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004002 ch->send_codecs()[0].name.c_str()));
4003 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4004 &portnum));
4005 EXPECT_EQ(new_send_port, portnum);
4006
4007 ASSERT_EQ(1UL, ch->recv_codecs().size());
4008 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004009 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004010 ch->recv_codecs()[0].name.c_str()));
4011 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4012 &portnum));
4013 EXPECT_EQ(new_recv_port, portnum);
4014}
4015
deadbeefab9b2d12015-10-14 11:33:11 -07004016// Verifies that when a session's DataChannel receives an OPEN message,
4017// WebRtcSession signals the DataChannel creation request with the expected
4018// config.
4019TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4021
4022 InitWithDtls(GetParam());
4023
4024 SetLocalDescriptionWithDataChannel();
4025 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4026
4027 webrtc::DataChannelInit config;
4028 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004029 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004030 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4031 cricket::ReceiveDataParams params;
4032 params.ssrc = config.id;
4033 params.type = cricket::DMT_CONTROL;
4034
4035 cricket::DataChannel* data_channel = session_->data_channel();
4036 data_channel->SignalDataReceived(data_channel, params, payload);
4037
4038 EXPECT_EQ("a", last_data_channel_label_);
4039 EXPECT_EQ(config.id, last_data_channel_config_.id);
4040 EXPECT_FALSE(last_data_channel_config_.negotiated);
4041 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4042 last_data_channel_config_.open_handshake_role);
4043}
4044
4045TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004046 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
4047 FakeDtlsIdentityStore::GenerateCertificate();
4048
htaa2a49d92016-03-04 02:51:39 -08004049 configuration_.certificates.push_back(certificate);
4050 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004051 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4052
4053 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4054}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004055
Henrik Boström87713d02015-08-25 09:53:21 +02004056// Verifies that CreateOffer succeeds when CreateOffer is called before async
4057// identity generation is finished (even if a certificate is provided this is
4058// an async op).
4059TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4060 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4061 InitWithDtls(GetParam());
4062
Henrik Boströmd8281982015-08-27 10:12:24 +02004063 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004064 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004065 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004066
wu@webrtc.org91053e72013-08-10 07:18:04 +00004067 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004068 VerifyNoCryptoParams(offer->description(), true);
4069 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004070}
4071
4072// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004073// identity generation is finished (even if a certificate is provided this is
4074// an async op).
4075TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004076 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004077 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004078 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004079
4080 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004081 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004082 std::unique_ptr<JsepSessionDescription> offer(
4083 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004084 ASSERT_TRUE(offer.get() != NULL);
4085 SetRemoteDescriptionWithoutError(offer.release());
4086
kwibergd1fe2812016-04-27 06:47:29 -07004087 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004088 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004089 VerifyNoCryptoParams(answer->description(), true);
4090 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004091}
4092
4093// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004094// identity generation is finished (even if a certificate is provided this is
4095// an async op).
4096TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004097 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004098 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099
Henrik Boströmd8281982015-08-27 10:12:24 +02004100 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004101
kwibergd1fe2812016-04-27 06:47:29 -07004102 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004103 EXPECT_TRUE(offer != NULL);
4104}
4105
4106// Verifies that CreateOffer fails when CreateOffer is called after async
4107// identity generation fails.
4108TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004109 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004110 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004111
Henrik Boströmd8281982015-08-27 10:12:24 +02004112 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004113
kwibergd1fe2812016-04-27 06:47:29 -07004114 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115 EXPECT_TRUE(offer == NULL);
4116}
4117
4118// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4119// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004120TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004121 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004122 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004123 VerifyMultipleAsyncCreateDescription(GetParam(),
4124 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004125}
4126
4127// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4128// before async identity generation fails.
4129TEST_F(WebRtcSessionTest,
4130 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004131 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004132 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4133 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004134}
4135
4136// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4137// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004138TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004139 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004142 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004143}
4144
4145// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4146// before async identity generation fails.
4147TEST_F(WebRtcSessionTest,
4148 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004149 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004150 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4151 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004152}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004153
4154// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4155// offer has no SDES crypto but only DTLS fingerprint.
4156TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4157 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004158 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004159 // Create a remote offer with secured transport disabled.
4160 cricket::MediaSessionOptions options;
4161 JsepSessionDescription* offer(CreateRemoteOffer(
4162 options, cricket::SEC_DISABLED));
4163 // Adds a DTLS fingerprint to the remote offer.
4164 cricket::SessionDescription* sdp = offer->description();
4165 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4166 ASSERT_TRUE(audio != NULL);
4167 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4168 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004169 rtc::SSLFingerprint::CreateFromRfc4572(
4170 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004171 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004172 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004173}
4174
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004175TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004176 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004177 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004178 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004179 SessionDescriptionInterface* offer = CreateOffer();
4180
4181 SetLocalDescriptionWithoutError(offer);
4182
4183 voice_channel_ = media_engine_->GetVoiceChannel(0);
4184
4185 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004186 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004187 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004188}
4189
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004190// Tests that we can renegotiate new media content with ICE candidates in the
4191// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004192TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004193 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004194 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004195 SetFactoryDtlsSrtp();
4196
deadbeefab9b2d12015-10-14 11:33:11 -07004197 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004198 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199 SetLocalDescriptionWithoutError(offer);
4200
4201 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4202 SetRemoteDescriptionWithoutError(answer);
4203
4204 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004205 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4207
4208 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004209 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004210 candidate1.set_component(1);
4211 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4212 candidate1);
4213 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4214 SetRemoteDescriptionWithoutError(offer);
4215
htaa2a49d92016-03-04 02:51:39 -08004216 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004217 SetLocalDescriptionWithoutError(answer);
4218}
4219
4220// Tests that we can renegotiate new media content with ICE candidates separated
4221// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004222TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004223 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004224 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004225 SetFactoryDtlsSrtp();
4226
deadbeefab9b2d12015-10-14 11:33:11 -07004227 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004228 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004229 SetLocalDescriptionWithoutError(offer);
4230
4231 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4232 SetRemoteDescriptionWithoutError(answer);
4233
4234 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004235 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004236 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4237 SetRemoteDescriptionWithoutError(offer);
4238
4239 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004240 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004241 candidate1.set_component(1);
4242 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4243 candidate1);
4244 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4245
htaa2a49d92016-03-04 02:51:39 -08004246 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004247 SetLocalDescriptionWithoutError(answer);
4248}
honghaiz7f777492016-02-02 21:54:01 -08004249
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004250// Tests that RTX codec is removed from the answer when it isn't supported
4251// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004252TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004253 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004254 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004255 std::string offer_sdp(kSdpWithRtx);
4256
4257 SessionDescriptionInterface* offer =
4258 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4259 EXPECT_TRUE(offer->ToString(&offer_sdp));
4260
4261 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004262 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004263 SetRemoteDescriptionWithoutError(offer);
4264
htaa2a49d92016-03-04 02:51:39 -08004265 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004266 // Answer SDP does not contain the RTX codec.
4267 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004268 SetLocalDescriptionWithoutError(answer);
4269}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004270
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004271// This verifies that the voice channel after bundle has both options from video
4272// and voice channels.
4273TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4274 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004275 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004276
4277 PeerConnectionInterface::RTCOfferAnswerOptions options;
4278 options.use_rtp_mux = true;
4279
4280 SessionDescriptionInterface* offer = CreateOffer(options);
4281 SetLocalDescriptionWithoutError(offer);
4282
4283 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4284 rtc::Socket::Option::OPT_SNDBUF, 4000);
4285
4286 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4287 rtc::Socket::Option::OPT_RCVBUF, 8000);
4288
4289 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004290 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004291 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4292 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004293 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4295
deadbeefcbecd352015-09-23 11:50:27 -07004296 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004297 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4298 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004300 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4301
deadbeefcbecd352015-09-23 11:50:27 -07004302 EXPECT_NE(session_->voice_rtp_transport_channel(),
4303 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004304
deadbeefab9b2d12015-10-14 11:33:11 -07004305 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004306 SessionDescriptionInterface* answer =
4307 CreateRemoteAnswer(session_->local_description());
4308 SetRemoteDescriptionWithoutError(answer);
4309
deadbeefcbecd352015-09-23 11:50:27 -07004310 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004311 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4312 EXPECT_EQ(4000, option_val);
4313
deadbeefcbecd352015-09-23 11:50:27 -07004314 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004315 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4316 EXPECT_EQ(8000, option_val);
4317}
4318
tommi0f620f42015-07-09 03:25:02 -07004319// Test creating a session, request multiple offers, destroy the session
4320// and make sure we got success/failure callbacks for all of the requests.
4321// Background: crbug.com/507307
4322TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4323 Init();
4324
4325 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4326 PeerConnectionInterface::RTCOfferAnswerOptions options;
4327 options.offer_to_receive_audio =
4328 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004329 cricket::MediaSessionOptions session_options;
4330 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004331
4332 for (auto& o : observers) {
4333 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004334 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004335 }
4336
4337 session_.reset();
4338
tommi0f620f42015-07-09 03:25:02 -07004339 for (auto& o : observers) {
4340 // We expect to have received a notification now even if the session was
4341 // terminated. The offer creation may or may not have succeeded, but we
4342 // must have received a notification which, so the only invalid state
4343 // is kInit.
4344 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4345 }
4346}
4347
stefanc1aeaf02015-10-15 07:26:07 -07004348TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4349 TestPacketOptions();
4350}
4351
deadbeef057ecf02016-01-20 14:30:43 -08004352// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4353// is destroyed.
4354TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4355 Init();
4356 session_.reset();
4357 EXPECT_TRUE(session_destroyed_);
4358}
4359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004360// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4361// currently fails because upon disconnection and reconnection OnIceComplete is
4362// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004363
deadbeefcbecd352015-09-23 11:50:27 -07004364INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4365 WebRtcSessionTest,
4366 testing::Values(ALREADY_GENERATED,
4367 DTLS_IDENTITY_STORE));