blob: 29f94dedb4782414e9f2dfb9d29eb609f0a09a8d [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 Boströmd79599d2016-06-01 13:58:50 +020022#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#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;
deadbeeff5f03e82016-06-06 11:16:06 -0700112// STUN timeout with all retransmissions is a total of 9500ms.
113static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000115static const char kFakeDtlsFingerprint[] =
116 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
117 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
118
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000119static const char kTooLongIceUfragPwd[] =
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
124
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000125static const char kSdpWithRtx[] =
126 "v=0\r\n"
127 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
128 "s=-\r\n"
129 "t=0 0\r\n"
130 "a=msid-semantic: WMS stream1\r\n"
131 "m=video 9 RTP/SAVPF 0 96\r\n"
132 "c=IN IP4 0.0.0.0\r\n"
133 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
134 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
135 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
136 "a=mid:video\r\n"
137 "a=sendrecv\r\n"
138 "a=rtcp-mux\r\n"
139 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
140 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
141 "a=rtpmap:0 fake_video_codec/90000\r\n"
142 "a=rtpmap:96 rtx/90000\r\n"
143 "a=fmtp:96 apt=0\r\n";
144
deadbeefab9b2d12015-10-14 11:33:11 -0700145static const char kStream1[] = "stream1";
146static const char kVideoTrack1[] = "video1";
147static const char kAudioTrack1[] = "audio1";
148
149static const char kStream2[] = "stream2";
150static const char kVideoTrack2[] = "video2";
151static const char kAudioTrack2[] = "audio2";
152
Henrik Boström87713d02015-08-25 09:53:21 +0200153enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155class MockIceObserver : public webrtc::IceObserver {
156 public:
157 MockIceObserver()
158 : oncandidatesready_(false),
159 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
160 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
161 }
162
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200163 virtual ~MockIceObserver() = default;
164
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceConnectionChange(
166 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700168 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 }
perkjdfb769d2016-02-09 03:09:43 -0800170 void OnIceGatheringChange(
171 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 // We can never transition back to "new".
173 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
174 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800175 oncandidatesready_ =
176 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 }
178
179 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800180 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000181 switch (candidate->sdp_mline_index()) {
182 case kMediaContentIndex0:
183 mline_0_candidates_.push_back(candidate->candidate());
184 break;
185 case kMediaContentIndex1:
186 mline_1_candidates_.push_back(candidate->candidate());
187 break;
188 default:
189 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // The ICE gathering state should always be Gathering when a candidate is
193 // received (or possibly Completed in the case of the final candidate).
194 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
195 }
196
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 // Some local candidates are removed.
198 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700199 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700200 num_candidates_removed_ += candidates.size();
201 }
202
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 bool oncandidatesready_;
204 std::vector<cricket::Candidate> mline_0_candidates_;
205 std::vector<cricket::Candidate> mline_1_candidates_;
206 PeerConnectionInterface::IceConnectionState ice_connection_state_;
207 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700208 std::vector<PeerConnectionInterface::IceConnectionState>
209 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700210 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211};
212
213class WebRtcSessionForTest : public webrtc::WebRtcSession {
214 public:
stefanc1aeaf02015-10-15 07:26:07 -0700215 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
danilchape9021a32016-05-17 01:52:02 -0700216 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000217 rtc::Thread* worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700218 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700220 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700221 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700222 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700223 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700224 signaling_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700225 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 RegisterIceObserver(ice_observer);
227 }
228 virtual ~WebRtcSessionForTest() {}
229
deadbeefcbecd352015-09-23 11:50:27 -0700230 // Note that these methods are only safe to use if the signaling thread
231 // is the same as the worker thread
232 cricket::TransportChannel* voice_rtp_transport_channel() {
233 return rtp_transport_channel(voice_channel());
234 }
235
236 cricket::TransportChannel* voice_rtcp_transport_channel() {
237 return rtcp_transport_channel(voice_channel());
238 }
239
240 cricket::TransportChannel* video_rtp_transport_channel() {
241 return rtp_transport_channel(video_channel());
242 }
243
244 cricket::TransportChannel* video_rtcp_transport_channel() {
245 return rtcp_transport_channel(video_channel());
246 }
247
248 cricket::TransportChannel* data_rtp_transport_channel() {
249 return rtp_transport_channel(data_channel());
250 }
251
252 cricket::TransportChannel* data_rtcp_transport_channel() {
253 return rtcp_transport_channel(data_channel());
254 }
255
deadbeefcbecd352015-09-23 11:50:27 -0700256 private:
257 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
258 if (!ch) {
259 return nullptr;
260 }
261 return ch->transport_channel();
262 }
263
264 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
265 if (!ch) {
266 return nullptr;
267 }
268 return ch->rtcp_transport_channel();
269 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270};
271
wu@webrtc.org91053e72013-08-10 07:18:04 +0000272class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000273 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275 enum State {
276 kInit,
277 kFailed,
278 kSucceeded,
279 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000280 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000281
282 // CreateSessionDescriptionObserver implementation.
283 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000284 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 state_ = kSucceeded;
286 }
287 virtual void OnFailure(const std::string& error) {
288 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 }
290
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000291 SessionDescriptionInterface* description() { return description_.get(); }
292
293 SessionDescriptionInterface* ReleaseDescription() {
294 return description_.release();
295 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296
wu@webrtc.org91053e72013-08-10 07:18:04 +0000297 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298
wu@webrtc.org91053e72013-08-10 07:18:04 +0000299 protected:
300 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
302 private:
kwibergd1fe2812016-04-27 06:47:29 -0700303 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000304 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305};
306
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800307class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800309 FakeAudioSource() : sink_(NULL) {}
310 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000311 if (sink_)
312 sink_->OnClose();
313 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000315 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000316
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800317 const cricket::AudioSource::Sink* sink() const { return sink_; }
318
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800320 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000321};
322
Henrik Boström87713d02015-08-25 09:53:21 +0200323class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700324 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
325 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 protected:
327 // TODO Investigate why ChannelManager crashes, if it's created
328 // after stun_server.
329 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700330 : media_engine_(new cricket::FakeMediaEngine()),
331 data_engine_(new cricket::FakeDataEngine()),
332 channel_manager_(
333 new cricket::ChannelManager(media_engine_,
334 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700335 rtc::Thread::Current())),
336 fake_call_(webrtc::Call::Config()),
337 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800338 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
339 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700340 channel_manager_.get())),
341 tdesc_factory_(new cricket::TransportDescriptionFactory()),
342 desc_factory_(
343 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
344 tdesc_factory_.get())),
345 pss_(new rtc::PhysicalSocketServer),
346 vss_(new rtc::VirtualSocketServer(pss_.get())),
347 fss_(new rtc::FirewallSocketServer(vss_.get())),
348 ss_scope_(fss_.get()),
349 stun_socket_addr_(
350 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
351 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
352 stun_socket_addr_)),
353 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
354 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000355 cricket::ServerAddresses stun_servers;
356 stun_servers.insert(stun_socket_addr_);
357 allocator_.reset(new cricket::BasicPortAllocator(
358 &network_manager_,
359 stun_servers,
360 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000361 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700362 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 EXPECT_TRUE(channel_manager_->Init());
364 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000365 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 }
367
368 void AddInterface(const SocketAddress& addr) {
369 network_manager_.AddInterface(addr);
370 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700371 void RemoveInterface(const SocketAddress& addr) {
372 network_manager_.RemoveInterface(addr);
373 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374
Henrik Boströmd79599d2016-06-01 13:58:50 +0200375 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
376 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
377 // options. When DTLS is enabled a certificate will be used if provided,
378 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000379 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200380 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
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(),
danilchape9021a32016-05-17 01:52:02 -0700384 rtc::Thread::Current(), allocator_.get(), &observer_));
deadbeefab9b2d12015-10-14 11:33:11 -0700385 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
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200395 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800396 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) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200426 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
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ömd79599d2016-06-01 13:58:50 +0200429 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200430 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200431 cert_generator.reset(new FakeRTCCertificateGenerator());
432 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200433 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700434 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200435 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200436 Init(std::move(cert_generator));
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() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200441 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
442 new FakeRTCCertificateGenerator());
443 cert_generator->set_should_fail(true);
444 Init(std::move(cert_generator));
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);
ossu075af922016-06-14 03:29:38 -0700454 desc_factory_->set_audio_codecs(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;
deadbeef14461d42016-06-15 11:06:57 -07001324 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1325 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001326 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1327 }
1328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1330 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001331 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1332 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001333
1334 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001335 std::vector<cricket::AudioCodec> codecs =
1336 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337 codecs.push_back(kCNCodec1);
1338 codecs.push_back(kCNCodec2);
1339 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001340 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 }
1342
1343 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1344 const cricket::ContentDescription* description = content->description;
1345 ASSERT(description != NULL);
1346 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001347 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 ASSERT(audio_content_desc != NULL);
1349 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1350 if (audio_content_desc->codecs()[i].name == "CN")
1351 return false;
1352 }
1353 return true;
1354 }
1355
deadbeefab9b2d12015-10-14 11:33:11 -07001356 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001357 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001358 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001359 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1360 data_channel_ = DataChannel::Create(
1361 session_.get(), session_->data_channel_type(), "datachannel", dci);
1362 }
1363
1364 void SetLocalDescriptionWithDataChannel() {
1365 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001366 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 SetLocalDescriptionWithoutError(offer);
1368 }
1369
wu@webrtc.org91053e72013-08-10 07:18:04 +00001370 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001371 RTCCertificateGenerationMethod cert_gen_method,
1372 CreateSessionDescriptionRequest::Type type) {
1373 InitWithDtls(cert_gen_method);
1374 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1375 }
1376
1377 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1378 CreateSessionDescriptionRequest::Type type) {
1379 InitWithDtlsIdentityGenFail();
1380 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1381 }
1382
1383 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001384 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001385 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001386 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001387 if (type == CreateSessionDescriptionRequest::kAnswer) {
1388 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001389 std::unique_ptr<JsepSessionDescription> offer(
1390 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001391 ASSERT_TRUE(offer.get() != NULL);
1392 SetRemoteDescriptionWithoutError(offer.release());
1393 }
1394
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001395 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001396 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001397 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001398 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001399 observers[kNumber];
1400 for (int i = 0; i < kNumber; ++i) {
1401 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1402 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001403 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404 } else {
htaa2a49d92016-03-04 02:51:39 -08001405 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001406 }
1407 }
1408
1409 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1410 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1411 WebRtcSessionCreateSDPObserverForTest::kFailed;
1412
1413 for (int i = 0; i < kNumber; ++i) {
1414 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1415 if (success) {
1416 EXPECT_TRUE(observers[i]->description() != NULL);
1417 } else {
1418 EXPECT_TRUE(observers[i]->description() == NULL);
1419 }
1420 }
1421 }
1422
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001423 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001424 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001425 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001426 turn_server.credentials = credentials;
1427 turn_server.ports.push_back(
1428 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1429 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001430 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001431 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001432 }
1433
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 cricket::FakeMediaEngine* media_engine_;
1435 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001436 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001437 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001438 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1439 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1440 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1441 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1442 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1443 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001444 rtc::SocketServerScope ss_scope_;
1445 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001446 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001447 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001448 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001449 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001450 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001451 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001452 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 MockIceObserver observer_;
1454 cricket::FakeVideoMediaChannel* video_channel_;
1455 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001456 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001457 // The following flags affect options created for CreateOffer/CreateAnswer.
1458 bool send_stream_1_ = false;
1459 bool send_stream_2_ = false;
1460 bool send_audio_ = false;
1461 bool send_video_ = false;
1462 rtc::scoped_refptr<DataChannel> data_channel_;
1463 // Last values received from data channel creation signal.
1464 std::string last_data_channel_label_;
1465 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001466 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467};
1468
Henrik Boström87713d02015-08-25 09:53:21 +02001469TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1470 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001471 // SDES is disabled when DTLS is on.
1472 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473}
1474
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001476 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 // SDES is required if DTLS is off.
1478 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001479}
1480
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1482 TestSessionCandidatesWithBundleRtcpMux(false, false);
1483}
1484
1485// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1486// with rtcp-mux and/or bundle.
1487TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1488 TestSessionCandidatesWithBundleRtcpMux(false, true);
1489}
1490
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1492 TestSessionCandidatesWithBundleRtcpMux(true, true);
1493}
1494
1495TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001496 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1497 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001498 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001499 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 InitiateCall();
1501 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1502 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1503 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1504}
1505
deadbeeff5f03e82016-06-06 11:16:06 -07001506TEST_F(WebRtcSessionTest, TestStunError) {
1507 rtc::ScopedFakeClock clock;
1508
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001509 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1510 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001511 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001512 rtc::FP_UDP,
1513 rtc::FD_ANY,
1514 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001515 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001516 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001518 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001519 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1521 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001522 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1523 // warning.
1524 session_->Close();
1525 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526}
1527
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001528TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001529 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001530 SessionDescriptionInterface* offer = NULL;
1531 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1532 std::string unknown_action;
1533 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1534 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1535}
1536
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537// Test creating offers and receive answers and make sure the
1538// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001539TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001540 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001541 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001542 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 const std::string session_id_orig = offer->session_id();
1544 const std::string session_version_orig = offer->session_version();
1545 SetLocalDescriptionWithoutError(offer);
1546
deadbeefab9b2d12015-10-14 11:33:11 -07001547 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 SessionDescriptionInterface* answer =
1549 CreateRemoteAnswer(session_->local_description());
1550 SetRemoteDescriptionWithoutError(answer);
1551
1552 video_channel_ = media_engine_->GetVideoChannel(0);
1553 voice_channel_ = media_engine_->GetVoiceChannel(0);
1554
1555 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1556 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1557
1558 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1559 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1560
1561 ASSERT_EQ(1u, video_channel_->send_streams().size());
1562 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1563 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1564 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1565
1566 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001567 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001568 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569
1570 // Verify the session id is the same and the session version is
1571 // increased.
1572 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001573 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1574 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575
1576 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001577 EXPECT_EQ(0u, video_channel_->send_streams().size());
1578 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579
deadbeefab9b2d12015-10-14 11:33:11 -07001580 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 answer = CreateRemoteAnswer(session_->local_description());
1582 SetRemoteDescriptionWithoutError(answer);
1583
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 // Make sure the receive streams have not changed.
1585 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1586 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1587 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1588 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1589}
1590
1591// Test receiving offers and creating answers and make sure the
1592// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001593TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001594 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001595 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001596 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001597 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 SetRemoteDescriptionWithoutError(offer);
1599
deadbeefab9b2d12015-10-14 11:33:11 -07001600 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001601 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001602 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 SetLocalDescriptionWithoutError(answer);
1604
1605 const std::string session_id_orig = answer->session_id();
1606 const std::string session_version_orig = answer->session_version();
1607
1608 video_channel_ = media_engine_->GetVideoChannel(0);
1609 voice_channel_ = media_engine_->GetVoiceChannel(0);
1610
htaa2a49d92016-03-04 02:51:39 -08001611 ASSERT_TRUE(video_channel_);
1612 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1614 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1615
1616 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1617 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1618
1619 ASSERT_EQ(1u, video_channel_->send_streams().size());
1620 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1621 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1622 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1623
deadbeefab9b2d12015-10-14 11:33:11 -07001624 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001625 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SetRemoteDescriptionWithoutError(offer);
1627
1628 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001629 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001630 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631
1632 // Verify the session id is the same and the session version is
1633 // increased.
1634 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001635 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1636 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 SetLocalDescriptionWithoutError(answer);
1638
1639 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1640 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1641 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1642 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1643 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1644 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1645
1646 // Make sure we have no send streams.
1647 EXPECT_EQ(0u, video_channel_->send_streams().size());
1648 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1649}
1650
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001651TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001652 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001653 media_engine_->set_fail_create_channel(true);
1654
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001655 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001656 ASSERT_TRUE(offer != NULL);
1657 // SetRemoteDescription and SetLocalDescription will take the ownership of
1658 // the offer.
1659 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001661 ASSERT_TRUE(offer != NULL);
1662 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1663}
1664
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001665//
1666// Tests for creating/setting SDP under different SDES/DTLS polices:
1667//
1668// --DTLS off and SDES on
1669// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1670// set local/remote offer/answer with crypto --> success
1671// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1672// failure
1673// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1674// failure
1675// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1676// failure
1677//
1678// --DTLS on and SDES off
1679// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1680// set local/remote offer/answer with DTLS fingerprint --> success
1681// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1682// fingerprint --> failure
1683// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1684// --> failure
1685// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1686// --> failure
1687//
1688// --Encryption disabled: DTLS off and SDES off
1689// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1690// answer without SDES or DTLS --> success
1691// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1692// answer without SDES or DTLS --> success
1693//
1694
1695// Test that we return a failure when applying a remote/local offer that doesn't
1696// have cryptos enabled when DTLS is off.
1697TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001698 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001700 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 JsepSessionDescription* offer = CreateRemoteOffer(
1702 options, cricket::SEC_DISABLED);
1703 ASSERT_TRUE(offer != NULL);
1704 VerifyNoCryptoParams(offer->description(), false);
1705 // SetRemoteDescription and SetLocalDescription will take the ownership of
1706 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001707 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1709 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001710 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711}
1712
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713// Test that we return a failure when applying a local answer that doesn't have
1714// cryptos enabled when DTLS is off.
1715TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001716 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 SessionDescriptionInterface* offer = NULL;
1718 SessionDescriptionInterface* answer = NULL;
1719 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1720 // SetRemoteDescription and SetLocalDescription will take the ownership of
1721 // the offer.
1722 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001723 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724}
1725
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001726// Test we will return fail when apply an remote answer that doesn't have
1727// crypto enabled when DTLS is off.
1728TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001729 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 SessionDescriptionInterface* offer = NULL;
1731 SessionDescriptionInterface* answer = NULL;
1732 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer.
1735 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001736 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737}
1738
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001739// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1740// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001741TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001742 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001743 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001744 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 SetFactoryDtlsSrtp();
1746 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001747 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001748 JsepSessionDescription* offer =
1749 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 ASSERT_TRUE(offer != NULL);
1751 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001752 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753
1754 // SetRemoteDescription will take the ownership of the offer.
1755 SetRemoteDescriptionWithoutError(offer);
1756
1757 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001758 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 ASSERT_TRUE(answer != NULL);
1760 VerifyFingerprintStatus(answer->description(), true);
1761 // Check that we don't have an a=crypto line in the answer.
1762 VerifyNoCryptoParams(answer->description(), true);
1763
1764 // Now set the local description, which should work, even without a=crypto.
1765 SetLocalDescriptionWithoutError(answer);
1766}
1767
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1769// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001770TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001771 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001772 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001773 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774 SetFactoryDtlsSrtp();
1775
1776 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001777 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778 ASSERT_TRUE(offer != NULL);
1779 VerifyFingerprintStatus(offer->description(), true);
1780 // Check that we don't have an a=crypto line in the offer.
1781 VerifyNoCryptoParams(offer->description(), true);
1782
1783 // Now set the local description, which should work, even without a=crypto.
1784 SetLocalDescriptionWithoutError(offer);
1785
1786 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001787 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788 JsepSessionDescription* answer =
1789 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1790 ASSERT_TRUE(answer != NULL);
1791 VerifyFingerprintStatus(answer->description(), true);
1792 VerifyNoCryptoParams(answer->description(), true);
1793
1794 // SetRemoteDescription will take the ownership of the answer.
1795 SetRemoteDescriptionWithoutError(answer);
1796}
1797
1798// Test that if we support DTLS and the other side didn't offer a fingerprint,
1799// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001800TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001801 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001802 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001804 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001805 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 JsepSessionDescription* offer = CreateRemoteOffer(
1807 options, cricket::SEC_REQUIRED);
1808 ASSERT_TRUE(offer != NULL);
1809 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001810 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 // SetRemoteDescription will take the ownership of the offer.
1813 SetRemoteDescriptionOfferExpectError(
1814 kSdpWithoutDtlsFingerprint, offer);
1815
1816 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1817 // SetLocalDescription will take the ownership of the offer.
1818 SetLocalDescriptionOfferExpectError(
1819 kSdpWithoutDtlsFingerprint, offer);
1820}
1821
1822// Test that we return a failure when applying a local answer that doesn't have
1823// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001824TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001825 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001826 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001827 SessionDescriptionInterface* offer = NULL;
1828 SessionDescriptionInterface* answer = NULL;
1829 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1830
1831 // SetRemoteDescription and SetLocalDescription will take the ownership of
1832 // the offer and answer.
1833 SetRemoteDescriptionWithoutError(offer);
1834 SetLocalDescriptionAnswerExpectError(
1835 kSdpWithoutDtlsFingerprint, answer);
1836}
1837
1838// Test that we return a failure when applying a remote answer that doesn't have
1839// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001840TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001841 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001842 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001843 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001845 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001846 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001847 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001849 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850
1851 // SetRemoteDescription and SetLocalDescription will take the ownership of
1852 // the offer and answer.
1853 SetLocalDescriptionWithoutError(offer);
1854 SetRemoteDescriptionAnswerExpectError(
1855 kSdpWithoutDtlsFingerprint, answer);
1856}
1857
1858// Test that we create a local offer without SDES or DTLS and accept a remote
1859// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001860TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001861 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001863 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864
1865 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001866 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867 ASSERT_TRUE(offer != NULL);
1868 VerifyFingerprintStatus(offer->description(), false);
1869 // Check that we don't have an a=crypto line in the offer.
1870 VerifyNoCryptoParams(offer->description(), false);
1871
1872 // Now set the local description, which should work, even without a=crypto.
1873 SetLocalDescriptionWithoutError(offer);
1874
1875 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001876 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001877 JsepSessionDescription* answer =
1878 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1879 ASSERT_TRUE(answer != NULL);
1880 VerifyFingerprintStatus(answer->description(), false);
1881 VerifyNoCryptoParams(answer->description(), false);
1882
1883 // SetRemoteDescription will take the ownership of the answer.
1884 SetRemoteDescriptionWithoutError(answer);
1885}
1886
1887// Test that we create a local answer without SDES or DTLS and accept a remote
1888// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001889TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001891 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001892
1893 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001894 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 JsepSessionDescription* offer =
1896 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1897 ASSERT_TRUE(offer != NULL);
1898 VerifyFingerprintStatus(offer->description(), false);
1899 VerifyNoCryptoParams(offer->description(), false);
1900
1901 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 SetRemoteDescriptionWithoutError(offer);
1903
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001905 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 ASSERT_TRUE(answer != NULL);
1907 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908 // Check that we don't have an a=crypto line in the answer.
1909 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001911 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 SetLocalDescriptionWithoutError(answer);
1913}
1914
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001915// Test that we can create and set an answer correctly when different
1916// SSL roles have been negotiated for different transports.
1917// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1918TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1919 SendAudioVideoStream1();
1920 InitWithDtls(GetParam());
1921 SetFactoryDtlsSrtp();
1922
1923 SessionDescriptionInterface* offer = CreateOffer();
1924 SetLocalDescriptionWithoutError(offer);
1925
1926 cricket::MediaSessionOptions options;
1927 options.recv_video = true;
1928
1929 // First, negotiate different SSL roles.
1930 SessionDescriptionInterface* answer =
1931 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1932 TransportInfo* audio_transport_info =
1933 answer->description()->GetTransportInfoByName("audio");
1934 audio_transport_info->description.connection_role =
1935 cricket::CONNECTIONROLE_ACTIVE;
1936 TransportInfo* video_transport_info =
1937 answer->description()->GetTransportInfoByName("video");
1938 video_transport_info->description.connection_role =
1939 cricket::CONNECTIONROLE_PASSIVE;
1940 SetRemoteDescriptionWithoutError(answer);
1941
1942 // Now create an offer in the reverse direction, and ensure the initial
1943 // offerer responds with an answer with correct SSL roles.
1944 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1945 kSessionVersion,
1946 session_->remote_description());
1947 SetRemoteDescriptionWithoutError(offer);
1948
htaa2a49d92016-03-04 02:51:39 -08001949 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001950 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1951 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1952 audio_transport_info->description.connection_role);
1953 video_transport_info = answer->description()->GetTransportInfoByName("video");
1954 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1955 video_transport_info->description.connection_role);
1956 SetLocalDescriptionWithoutError(answer);
1957
1958 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1959 // audio is transferred over to video in the answer that completes the BUNDLE
1960 // negotiation.
1961 options.bundle_enabled = true;
1962 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1963 kSessionVersion,
1964 session_->remote_description());
1965 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001966 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001967 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1968 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1969 audio_transport_info->description.connection_role);
1970 video_transport_info = answer->description()->GetTransportInfoByName("video");
1971 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1972 video_transport_info->description.connection_role);
1973 SetLocalDescriptionWithoutError(answer);
1974}
1975
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001977 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001978 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001980 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 SetLocalDescriptionWithoutError(offer);
1982
1983 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001984 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 SetLocalDescriptionWithoutError(offer2);
1986}
1987
1988TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001989 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001990 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001992 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 SetRemoteDescriptionWithoutError(offer);
1994
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001995 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 SetRemoteDescriptionWithoutError(offer2);
1997}
1998
1999TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002000 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002001 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002002 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002005 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2006 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007}
2008
2009TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002010 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002011 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002014 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002015 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002016 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017}
2018
2019TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002020 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002021 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002023 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024
htaa2a49d92016-03-04 02:51:39 -08002025 JsepSessionDescription* pranswer =
2026 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002028 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029
deadbeefab9b2d12015-10-14 11:33:11 -07002030 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002031 JsepSessionDescription* pranswer2 =
2032 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2034
deadbeefd59daf82015-10-14 15:02:44 -07002035 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036
deadbeefab9b2d12015-10-14 11:33:11 -07002037 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002038 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002039 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040}
2041
2042TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002043 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002044 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002045 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002046 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047
2048 JsepSessionDescription* pranswer =
2049 CreateRemoteAnswer(session_->local_description());
2050 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2051
2052 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002053 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054
deadbeefab9b2d12015-10-14 11:33:11 -07002055 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 JsepSessionDescription* pranswer2 =
2057 CreateRemoteAnswer(session_->local_description());
2058 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2059
2060 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002061 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062
deadbeefab9b2d12015-10-14 11:33:11 -07002063 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 SessionDescriptionInterface* answer =
2065 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002066 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067}
2068
2069TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002070 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002071 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002072 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 SessionDescriptionInterface* answer =
2075 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002076 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2077 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
2080TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002081 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002082 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002083 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 SessionDescriptionInterface* answer =
2086 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002087 SetRemoteDescriptionAnswerExpectError(
2088 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089}
2090
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002091// Tests that the remote candidates are added and removed successfully.
2092TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002093 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002094 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002096 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2097 "", "", "host", 0, "");
2098 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2100
deadbeefd59daf82015-10-14 15:02:44 -07002101 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002106
2107 // Fail since we have not set a remote description.
2108 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
2110 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2111 session_->local_description());
2112 SetRemoteDescriptionWithoutError(answer);
2113
deadbeefd59daf82015-10-14 15:02:44 -07002114 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2115 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002116 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002117 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2118 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 // Verifying the candidates are copied properly from internal vector.
2121 const SessionDescriptionInterface* remote_desc =
2122 session_->remote_description();
2123 ASSERT_TRUE(remote_desc != NULL);
2124 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2125 const IceCandidateCollection* candidates =
2126 remote_desc->candidates(kMediaContentIndex0);
2127 ASSERT_EQ(2u, candidates->count());
2128 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2129 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2130 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2131 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2132
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002133 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2134 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 candidate.set_component(2);
2136 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2137 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002138 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
2140 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2141 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002142
2143 // Remove candidate1 and candidate2
2144 std::vector<cricket::Candidate> remote_candidates;
2145 remote_candidates.push_back(ice_candidate1.candidate());
2146 remote_candidates.push_back(ice_candidate2.candidate());
2147 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2148 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149}
2150
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002151// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152// that it is retained if the remote session description is changed.
2153TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002154 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 cricket::Candidate candidate1;
2156 candidate1.set_component(1);
2157 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2158 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002159 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 CreateAndSetRemoteOfferAndLocalAnswer();
2161
2162 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2163 const SessionDescriptionInterface* remote_desc =
2164 session_->remote_description();
2165 ASSERT_TRUE(remote_desc != NULL);
2166 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2167 const IceCandidateCollection* candidates =
2168 remote_desc->candidates(kMediaContentIndex0);
2169 ASSERT_EQ(1u, candidates->count());
2170 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2171
2172 // Update the RemoteSessionDescription with a new session description and
2173 // a candidate and check that the new remote session description contains both
2174 // candidates.
2175 SessionDescriptionInterface* offer = CreateRemoteOffer();
2176 cricket::Candidate candidate2;
2177 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2178 candidate2);
2179 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2180 SetRemoteDescriptionWithoutError(offer);
2181
2182 remote_desc = session_->remote_description();
2183 ASSERT_TRUE(remote_desc != NULL);
2184 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2185 candidates = remote_desc->candidates(kMediaContentIndex0);
2186 ASSERT_EQ(2u, candidates->count());
2187 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2188 // Username and password have be updated with the TransportInfo of the
2189 // SessionDescription, won't be equal to the original one.
2190 candidate2.set_username(candidates->at(0)->candidate().username());
2191 candidate2.set_password(candidates->at(0)->candidate().password());
2192 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2193 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2194 // No need to verify the username and password.
2195 candidate1.set_username(candidates->at(1)->candidate().username());
2196 candidate1.set_password(candidates->at(1)->candidate().password());
2197 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2198
2199 // Test that the candidate is ignored if we can add the same candidate again.
2200 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2201}
2202
2203// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002204// that they are retained if the local session description is changed. And if
2205// continual gathering is enabled, they are removed from the local session
2206// description when the network is down.
2207TEST_F(WebRtcSessionTest,
2208 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002209 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002210 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002211 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 CreateAndSetRemoteOfferAndLocalAnswer();
2213
2214 const SessionDescriptionInterface* local_desc = session_->local_description();
2215 const IceCandidateCollection* candidates =
2216 local_desc->candidates(kMediaContentIndex0);
2217 ASSERT_TRUE(candidates != NULL);
2218 EXPECT_EQ(0u, candidates->count());
2219
2220 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2221
2222 local_desc = session_->local_description();
2223 candidates = local_desc->candidates(kMediaContentIndex0);
2224 ASSERT_TRUE(candidates != NULL);
2225 EXPECT_LT(0u, candidates->count());
2226 candidates = local_desc->candidates(1);
2227 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002228 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229
2230 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002231 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 CreateAndSetRemoteOfferAndLocalAnswer();
2233
2234 local_desc = session_->local_description();
2235 candidates = local_desc->candidates(kMediaContentIndex0);
2236 ASSERT_TRUE(candidates != NULL);
2237 EXPECT_LT(0u, candidates->count());
2238 candidates = local_desc->candidates(1);
2239 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002240 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002241
2242 candidates = local_desc->candidates(kMediaContentIndex0);
2243 size_t num_local_candidates = candidates->count();
2244 // Enable Continual Gathering
Honghai Zhang5622c5e2016-07-01 13:59:29 -07002245 cricket::IceConfig config;
2246 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2247 session_->SetIceConfig(config);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002248 // Bring down the network interface to trigger candidate removals.
2249 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2250 // Verify that all local candidates are removed.
2251 EXPECT_EQ(0, observer_.num_candidates_removed_);
2252 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2253 kIceCandidatesTimeout);
2254 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2255}
2256
2257// Tests that if continual gathering is disabled, local candidates won't be
2258// removed when the interface is turned down.
2259TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2260 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2261 Init();
2262 SendAudioVideoStream1();
2263 CreateAndSetRemoteOfferAndLocalAnswer();
2264
2265 const SessionDescriptionInterface* local_desc = session_->local_description();
2266 const IceCandidateCollection* candidates =
2267 local_desc->candidates(kMediaContentIndex0);
2268 ASSERT_TRUE(candidates != NULL);
2269 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2270
2271 size_t num_local_candidates = candidates->count();
2272 EXPECT_LT(0u, num_local_candidates);
2273 // By default, Continual Gathering is disabled.
2274 // Bring down the network interface.
2275 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2276 // Verify that the local candidates are not removed.
2277 rtc::Thread::Current()->ProcessMessages(1000);
2278 EXPECT_EQ(0, observer_.num_candidates_removed_);
2279 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280}
2281
2282// Test that we can set a remote session description with remote candidates.
2283TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002284 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285
2286 cricket::Candidate candidate1;
2287 candidate1.set_component(1);
2288 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2289 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002290 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002291 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292
2293 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2294 SetRemoteDescriptionWithoutError(offer);
2295
2296 const SessionDescriptionInterface* remote_desc =
2297 session_->remote_description();
2298 ASSERT_TRUE(remote_desc != NULL);
2299 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2300 const IceCandidateCollection* candidates =
2301 remote_desc->candidates(kMediaContentIndex0);
2302 ASSERT_EQ(1u, candidates->count());
2303 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2304
htaa2a49d92016-03-04 02:51:39 -08002305 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 SetLocalDescriptionWithoutError(answer);
2307}
2308
2309// Test that offers and answers contains ice candidates when Ice candidates have
2310// been gathered.
2311TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002312 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002313 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002314 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 // Ice is started but candidates are not provided until SetLocalDescription
2316 // is called.
2317 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2318 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2319 CreateAndSetRemoteOfferAndLocalAnswer();
2320 // Wait until at least one local candidate has been collected.
2321 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2322 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323
kwibergd1fe2812016-04-27 06:47:29 -07002324 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002325
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2327 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328
2329 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2330 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002331 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2333 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 SetLocalDescriptionWithoutError(answer);
2335}
2336
2337// Verifies TransportProxy and media channels are created with content names
2338// present in the SessionDescription.
2339TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002340 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002341 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002342 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343
2344 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002345 // "video". Goal is to modify these content names and verify transport
2346 // channels
2347 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 // present in SDP.
2349 std::string sdp;
2350 EXPECT_TRUE(offer->ToString(&sdp));
2351 const std::string kAudioMid = "a=mid:audio";
2352 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2353 const std::string kVideoMid = "a=mid:video";
2354 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2355
2356 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002357 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 kAudioMidReplaceStr.c_str(),
2359 kAudioMidReplaceStr.length(),
2360 &sdp);
2361 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002362 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 kVideoMidReplaceStr.c_str(),
2364 kVideoMidReplaceStr.length(),
2365 &sdp);
2366
2367 SessionDescriptionInterface* modified_offer =
2368 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2369
2370 SetRemoteDescriptionWithoutError(modified_offer);
2371
htaa2a49d92016-03-04 02:51:39 -08002372 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 SetLocalDescriptionWithoutError(answer);
2374
deadbeefcbecd352015-09-23 11:50:27 -07002375 cricket::TransportChannel* voice_transport_channel =
2376 session_->voice_rtp_transport_channel();
2377 EXPECT_TRUE(voice_transport_channel != NULL);
2378 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2379 cricket::TransportChannel* video_transport_channel =
2380 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002381 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002382 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2384 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2385}
2386
2387// Test that an offer contains the correct media content descriptions based on
2388// the send streams when no constraints have been set.
2389TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002390 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002391 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002392
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 ASSERT_TRUE(offer != NULL);
2394 const cricket::ContentInfo* content =
2395 cricket::GetFirstAudioContent(offer->description());
2396 EXPECT_TRUE(content != NULL);
2397 content = cricket::GetFirstVideoContent(offer->description());
2398 EXPECT_TRUE(content == NULL);
2399}
2400
2401// Test that an offer contains the correct media content descriptions based on
2402// the send streams when no constraints have been set.
2403TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002404 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002406 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002407 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002408
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 const cricket::ContentInfo* content =
2410 cricket::GetFirstAudioContent(offer->description());
2411 EXPECT_TRUE(content != NULL);
2412 content = cricket::GetFirstVideoContent(offer->description());
2413 EXPECT_TRUE(content == NULL);
2414
2415 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002416 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 content = cricket::GetFirstAudioContent(offer->description());
2419 EXPECT_TRUE(content != NULL);
2420 content = cricket::GetFirstVideoContent(offer->description());
2421 EXPECT_TRUE(content != NULL);
2422}
2423
2424// Test that an offer contains no media content descriptions if
2425// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2426TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002427 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002428 PeerConnectionInterface::RTCOfferAnswerOptions options;
2429 options.offer_to_receive_audio = 0;
2430 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431
kwibergd1fe2812016-04-27 06:47:29 -07002432 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002433
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 ASSERT_TRUE(offer != NULL);
2435 const cricket::ContentInfo* content =
2436 cricket::GetFirstAudioContent(offer->description());
2437 EXPECT_TRUE(content == NULL);
2438 content = cricket::GetFirstVideoContent(offer->description());
2439 EXPECT_TRUE(content == NULL);
2440}
2441
2442// Test that an offer contains only audio media content descriptions if
2443// kOfferToReceiveAudio constraints are set to true.
2444TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002445 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002446 PeerConnectionInterface::RTCOfferAnswerOptions options;
2447 options.offer_to_receive_audio =
2448 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2449
kwibergd1fe2812016-04-27 06:47:29 -07002450 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451
2452 const cricket::ContentInfo* content =
2453 cricket::GetFirstAudioContent(offer->description());
2454 EXPECT_TRUE(content != NULL);
2455 content = cricket::GetFirstVideoContent(offer->description());
2456 EXPECT_TRUE(content == NULL);
2457}
2458
2459// Test that an offer contains audio and video media content descriptions if
2460// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2461TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002462 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002464 PeerConnectionInterface::RTCOfferAnswerOptions options;
2465 options.offer_to_receive_audio =
2466 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2467 options.offer_to_receive_video =
2468 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2469
kwibergd1fe2812016-04-27 06:47:29 -07002470 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 const cricket::ContentInfo* content =
2473 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002474 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 content = cricket::GetFirstVideoContent(offer->description());
2477 EXPECT_TRUE(content != NULL);
2478
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002479 // Sets constraints to false and verifies that audio/video contents are
2480 // removed.
2481 options.offer_to_receive_audio = 0;
2482 options.offer_to_receive_video = 0;
2483 offer.reset(CreateOffer(options));
2484
2485 content = cricket::GetFirstAudioContent(offer->description());
2486 EXPECT_TRUE(content == NULL);
2487 content = cricket::GetFirstVideoContent(offer->description());
2488 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489}
2490
2491// Test that an answer can not be created if the last remote description is not
2492// an offer.
2493TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002494 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002495 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 SetLocalDescriptionWithoutError(offer);
2497 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2498 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002499 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500}
2501
2502// Test that an answer contains the correct media content descriptions when no
2503// constraints have been set.
2504TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002505 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002507 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002509 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 const cricket::ContentInfo* content =
2511 cricket::GetFirstAudioContent(answer->description());
2512 ASSERT_TRUE(content != NULL);
2513 EXPECT_FALSE(content->rejected);
2514
2515 content = cricket::GetFirstVideoContent(answer->description());
2516 ASSERT_TRUE(content != NULL);
2517 EXPECT_FALSE(content->rejected);
2518}
2519
2520// Test that an answer contains the correct media content descriptions when no
2521// constraints have been set and the offer only contain audio.
2522TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002523 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 // Create a remote offer with audio only.
2525 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002526
kwibergd1fe2812016-04-27 06:47:29 -07002527 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2529 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2530
2531 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002532 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 const cricket::ContentInfo* content =
2534 cricket::GetFirstAudioContent(answer->description());
2535 ASSERT_TRUE(content != NULL);
2536 EXPECT_FALSE(content->rejected);
2537
2538 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2539}
2540
2541// Test that an answer contains the correct media content descriptions when no
2542// constraints have been set.
2543TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002544 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002546 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 SetRemoteDescriptionWithoutError(offer.release());
2548 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002549 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002550 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 const cricket::ContentInfo* content =
2552 cricket::GetFirstAudioContent(answer->description());
2553 ASSERT_TRUE(content != NULL);
2554 EXPECT_FALSE(content->rejected);
2555
2556 content = cricket::GetFirstVideoContent(answer->description());
2557 ASSERT_TRUE(content != NULL);
2558 EXPECT_FALSE(content->rejected);
2559}
2560
2561// Test that an answer contains the correct media content descriptions when
2562// constraints have been set but no stream is sent.
2563TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002564 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002566 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 SetRemoteDescriptionWithoutError(offer.release());
2568
htaa2a49d92016-03-04 02:51:39 -08002569 cricket::MediaSessionOptions session_options;
2570 session_options.recv_audio = false;
2571 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002572 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002573 CreateAnswer(session_options));
2574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 const cricket::ContentInfo* content =
2576 cricket::GetFirstAudioContent(answer->description());
2577 ASSERT_TRUE(content != NULL);
2578 EXPECT_TRUE(content->rejected);
2579
2580 content = cricket::GetFirstVideoContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_TRUE(content->rejected);
2583}
2584
2585// Test that an answer contains the correct media content descriptions when
2586// constraints have been set and streams are sent.
2587TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002588 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002590 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 SetRemoteDescriptionWithoutError(offer.release());
2592
htaa2a49d92016-03-04 02:51:39 -08002593 cricket::MediaSessionOptions options;
2594 options.recv_audio = false;
2595 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596
2597 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002598 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002599 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600
2601 // TODO(perkj): Should the direction be set to SEND_ONLY?
2602 const cricket::ContentInfo* content =
2603 cricket::GetFirstAudioContent(answer->description());
2604 ASSERT_TRUE(content != NULL);
2605 EXPECT_FALSE(content->rejected);
2606
2607 // TODO(perkj): Should the direction be set to SEND_ONLY?
2608 content = cricket::GetFirstVideoContent(answer->description());
2609 ASSERT_TRUE(content != NULL);
2610 EXPECT_FALSE(content->rejected);
2611}
2612
2613TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2614 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002615 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002616 PeerConnectionInterface::RTCOfferAnswerOptions options;
2617 options.offer_to_receive_audio =
2618 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2619 options.voice_activity_detection = false;
2620
kwibergd1fe2812016-04-27 06:47:29 -07002621 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002622
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 const cricket::ContentInfo* content =
2624 cricket::GetFirstAudioContent(offer->description());
2625 EXPECT_TRUE(content != NULL);
2626 EXPECT_TRUE(VerifyNoCNCodecs(content));
2627}
2628
2629TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2630 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002631 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002633 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 SetRemoteDescriptionWithoutError(offer.release());
2635
htaa2a49d92016-03-04 02:51:39 -08002636 cricket::MediaSessionOptions options;
2637 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002638 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639 const cricket::ContentInfo* content =
2640 cricket::GetFirstAudioContent(answer->description());
2641 ASSERT_TRUE(content != NULL);
2642 EXPECT_TRUE(VerifyNoCNCodecs(content));
2643}
2644
2645// This test verifies the call setup when remote answer with audio only and
2646// later updates with video.
2647TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002648 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2650 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2651
deadbeefab9b2d12015-10-14 11:33:11 -07002652 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002653 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654
2655 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2657
2658 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2659 // and answer;
2660 SetLocalDescriptionWithoutError(offer);
2661 SetRemoteDescriptionWithoutError(answer);
2662
2663 video_channel_ = media_engine_->GetVideoChannel(0);
2664 voice_channel_ = media_engine_->GetVoiceChannel(0);
2665
2666 ASSERT_TRUE(video_channel_ == NULL);
2667
2668 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2669 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2670 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2671
2672 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002673 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 CreateAndSetRemoteOfferAndLocalAnswer();
2675
2676 video_channel_ = media_engine_->GetVideoChannel(0);
2677 voice_channel_ = media_engine_->GetVoiceChannel(0);
2678
2679 ASSERT_TRUE(video_channel_ != NULL);
2680 ASSERT_TRUE(voice_channel_ != NULL);
2681
2682 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2683 ASSERT_EQ(1u, video_channel_->send_streams().size());
2684 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2685 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2686 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2687 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2688 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2689 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2690
2691 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002692 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693 CreateAndSetRemoteOfferAndLocalAnswer();
2694
2695 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2696 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2697 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2698 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2699 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2700}
2701
2702// This test verifies the call setup when remote answer with video only and
2703// later updates with audio.
2704TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002705 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2707 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002708 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002709 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710
2711 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002712 options.recv_audio = false;
2713 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2715 offer, options, cricket::SEC_ENABLED);
2716
2717 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2718 // and answer.
2719 SetLocalDescriptionWithoutError(offer);
2720 SetRemoteDescriptionWithoutError(answer);
2721
2722 video_channel_ = media_engine_->GetVideoChannel(0);
2723 voice_channel_ = media_engine_->GetVoiceChannel(0);
2724
2725 ASSERT_TRUE(voice_channel_ == NULL);
2726 ASSERT_TRUE(video_channel_ != NULL);
2727
2728 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2729 ASSERT_EQ(1u, video_channel_->send_streams().size());
2730 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2731
2732 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002733 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 CreateAndSetRemoteOfferAndLocalAnswer();
2735
2736 voice_channel_ = media_engine_->GetVoiceChannel(0);
2737 ASSERT_TRUE(voice_channel_ != NULL);
2738
2739 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2740 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2741 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2742 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2743
2744 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002745 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746 CreateAndSetRemoteOfferAndLocalAnswer();
2747
2748 video_channel_ = media_engine_->GetVideoChannel(0);
2749 voice_channel_ = media_engine_->GetVoiceChannel(0);
2750
2751 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2752 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2753 ASSERT_EQ(1u, video_channel_->send_streams().size());
2754 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2755}
2756
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002758 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002759 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002760 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 VerifyCryptoParams(offer->description());
2762 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002763 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002764 VerifyCryptoParams(answer->description());
2765}
2766
2767TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002768 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002769 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002770 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002771 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 VerifyNoCryptoParams(offer->description(), false);
2773}
2774
2775TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002776 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777 VerifyAnswerFromNonCryptoOffer();
2778}
2779
2780TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 VerifyAnswerFromCryptoOffer();
2783}
2784
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002785// This test verifies that setLocalDescription fails if
2786// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2787TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002788 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002789 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002790 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002791
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002792 std::string sdp;
2793 RemoveIceUfragPwdLines(offer.get(), &sdp);
2794 SessionDescriptionInterface* modified_offer =
2795 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002796 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002797}
2798
2799// This test verifies that setRemoteDescription fails if
2800// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2801TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002802 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002803 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002804 std::string sdp;
2805 RemoveIceUfragPwdLines(offer.get(), &sdp);
2806 SessionDescriptionInterface* modified_offer =
2807 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002808 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002809}
2810
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002811// This test verifies that setLocalDescription fails if local offer has
2812// too short ice ufrag and pwd strings.
2813TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002814 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002815 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002816 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002817 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2818 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002819 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002820 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002821 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002822
2823 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002824 offer.reset(CreateOffer());
2825 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2826 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002827}
2828
2829// This test verifies that setRemoteDescription fails if remote offer has
2830// too short ice ufrag and pwd strings.
2831TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002832 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002833 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002834 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2835 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002836 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002837 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002838 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002839
deadbeef0ed85b22016-02-23 17:24:52 -08002840 offer.reset(CreateRemoteOffer());
2841 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2842 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002843}
2844
Honghai Zhang04e91462015-12-11 14:26:22 -08002845// Test that if the remote offer indicates the peer requested ICE restart (via
2846// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2847TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002848 Init();
honghaiz503726c2015-07-31 12:37:38 -07002849
2850 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002851 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002852 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002853 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2854 0, "", "", "relay", 0, "");
2855 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2856 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002857 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2858 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002859 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2860
2861 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002862 offer.reset(CreateRemoteOffer());
2863 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002864 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2865 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2866 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002867 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2868 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002869 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2870
2871 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002872 offer.reset(CreateRemoteOffer());
2873 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002874 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2875 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2876 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002877 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2878 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002879 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2880
2881 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002882 offer.reset(CreateRemoteOffer());
2883 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2884 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002885 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2886}
2887
Honghai Zhang04e91462015-12-11 14:26:22 -08002888// Test that if the remote answer indicates the peer requested ICE restart (via
2889// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2890TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2891 Init();
2892 SessionDescriptionInterface* offer = CreateOffer();
2893 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002894
2895 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002896 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002897 answer->set_type(JsepSessionDescription::kPrAnswer);
2898 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002899 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2900 0, "", "", "relay", 0, "");
2901 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2902 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002903 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2904 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002905 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2906
2907 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002908 answer.reset(CreateRemoteAnswer(offer));
2909 answer->set_type(JsepSessionDescription::kPrAnswer);
2910 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002911 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2912 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2913 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002914 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2915 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002916 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2917
2918 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002919 answer.reset(CreateRemoteAnswer(offer));
2920 answer->set_type(JsepSessionDescription::kPrAnswer);
2921 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002922 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2923 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2924 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002925 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2926 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002927 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2928
2929 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002930 answer.reset(CreateRemoteAnswer(offer));
2931 answer->set_type(JsepSessionDescription::kPrAnswer);
2932 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2933 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002934 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2935}
2936
Donald Curtisd4f769d2015-05-28 09:48:21 -07002937// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002938// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002939TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2940 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2941
2942 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002943 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002944
2945 PeerConnectionInterface::RTCOfferAnswerOptions options;
2946 options.use_rtp_mux = true;
2947
2948 SessionDescriptionInterface* offer = CreateRemoteOffer();
2949 SetRemoteDescriptionWithoutError(offer);
2950
htaa2a49d92016-03-04 02:51:39 -08002951 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002952 SetLocalDescriptionWithoutError(answer);
2953
deadbeefcbecd352015-09-23 11:50:27 -07002954 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2955 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002956
deadbeefcbecd352015-09-23 11:50:27 -07002957 cricket::BaseChannel* voice_channel = session_->voice_channel();
2958 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002959
2960 // Checks if one of the transport channels contains a connection using a given
2961 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002962 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002963 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002964 session_->GetChannelTransportStats(voice_channel, &stats);
2965 for (auto& kv : stats.transport_stats) {
2966 for (auto& chan_stat : kv.second.channel_stats) {
2967 for (auto& conn_info : chan_stat.connection_infos) {
2968 if (conn_info.remote_candidate.address().port() == port) {
2969 return true;
2970 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002971 }
2972 }
2973 }
2974 return false;
2975 };
2976
2977 EXPECT_FALSE(connection_with_remote_port(5000));
2978 EXPECT_FALSE(connection_with_remote_port(5001));
2979 EXPECT_FALSE(connection_with_remote_port(6000));
2980
2981 // The way the *_WAIT checks work is they only wait if the condition fails,
2982 // which does not help in the case where state is not changing. This is
2983 // problematic in this test since we want to verify that adding a video
2984 // candidate does _not_ change state. So we interleave candidates and assume
2985 // that messages are executed in the order they were posted.
2986
2987 // First audio candidate.
2988 cricket::Candidate candidate0;
2989 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2990 candidate0.set_component(1);
2991 candidate0.set_protocol("udp");
2992 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2993 candidate0);
2994 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2995
2996 // Video candidate.
2997 cricket::Candidate candidate1;
2998 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2999 candidate1.set_component(1);
3000 candidate1.set_protocol("udp");
3001 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3002 candidate1);
3003 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3004
3005 // Second audio candidate.
3006 cricket::Candidate candidate2;
3007 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3008 candidate2.set_component(1);
3009 candidate2.set_protocol("udp");
3010 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3011 candidate2);
3012 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3013
3014 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3015 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3016
3017 // No need here for a _WAIT check since we are checking that state hasn't
3018 // changed: if this is false we would be doing waits for nothing and if this
3019 // is true then there will be no messages processed anyways.
3020 EXPECT_FALSE(connection_with_remote_port(6000));
3021}
3022
deadbeefcbecd352015-09-23 11:50:27 -07003023// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003024TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3025 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003026 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003027
3028 PeerConnectionInterface::RTCOfferAnswerOptions options;
3029 options.use_rtp_mux = true;
3030
3031 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003033
deadbeefcbecd352015-09-23 11:50:27 -07003034 EXPECT_NE(session_->voice_rtp_transport_channel(),
3035 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003036
deadbeefab9b2d12015-10-14 11:33:11 -07003037 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003038 SessionDescriptionInterface* answer =
3039 CreateRemoteAnswer(session_->local_description());
3040 SetRemoteDescriptionWithoutError(answer);
3041
deadbeefcbecd352015-09-23 11:50:27 -07003042 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3043 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003044}
3045
deadbeefcbecd352015-09-23 11:50:27 -07003046// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003047TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3048 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003049 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003050
Donald Curtis0e209b02015-03-24 09:29:54 -07003051 PeerConnectionInterface::RTCOfferAnswerOptions options;
3052 options.use_rtp_mux = true;
3053
3054 SessionDescriptionInterface* offer = CreateOffer(options);
3055 SetLocalDescriptionWithoutError(offer);
3056
deadbeefcbecd352015-09-23 11:50:27 -07003057 EXPECT_NE(session_->voice_rtp_transport_channel(),
3058 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003059
deadbeefab9b2d12015-10-14 11:33:11 -07003060 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003061
3062 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003063 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003064 CreateRemoteAnswer(session_->local_description()));
3065 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3066 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3067 JsepSessionDescription* modified_answer =
3068 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3069 modified_answer->Initialize(answer_copy, "1", "1");
3070 SetRemoteDescriptionWithoutError(modified_answer); //
3071
deadbeefcbecd352015-09-23 11:50:27 -07003072 EXPECT_NE(session_->voice_rtp_transport_channel(),
3073 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003074}
3075
3076// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3077TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3078 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003079 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003080
3081 PeerConnectionInterface::RTCOfferAnswerOptions options;
3082 options.use_rtp_mux = true;
3083
3084 SessionDescriptionInterface* offer = CreateOffer(options);
3085 SetLocalDescriptionWithoutError(offer);
3086
deadbeefcbecd352015-09-23 11:50:27 -07003087 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3088 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003089
deadbeefab9b2d12015-10-14 11:33:11 -07003090 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003091 SessionDescriptionInterface* answer =
3092 CreateRemoteAnswer(session_->local_description());
3093 SetRemoteDescriptionWithoutError(answer);
3094
deadbeefcbecd352015-09-23 11:50:27 -07003095 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3096 session_->video_rtp_transport_channel());
3097}
3098
3099// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3100// audio content in the answer.
3101TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3102 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003103 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003104
3105 PeerConnectionInterface::RTCOfferAnswerOptions options;
3106 options.use_rtp_mux = true;
3107
3108 SessionDescriptionInterface* offer = CreateOffer(options);
3109 SetLocalDescriptionWithoutError(offer);
3110
3111 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3112 session_->video_rtp_transport_channel());
3113
deadbeefab9b2d12015-10-14 11:33:11 -07003114 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003115 cricket::MediaSessionOptions recv_options;
3116 recv_options.recv_audio = false;
3117 recv_options.recv_video = true;
3118 SessionDescriptionInterface* answer =
3119 CreateRemoteAnswer(session_->local_description(), recv_options);
3120 SetRemoteDescriptionWithoutError(answer);
3121
deadbeefd59daf82015-10-14 15:02:44 -07003122 EXPECT_TRUE(nullptr == session_->voice_channel());
3123 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003124
deadbeefd59daf82015-10-14 15:02:44 -07003125 session_->Close();
3126 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3127 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3128 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3129 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003130}
3131
3132// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3133TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3134 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003135 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003136
Donald Curtis0e209b02015-03-24 09:29:54 -07003137 PeerConnectionInterface::RTCOfferAnswerOptions options;
3138 options.use_rtp_mux = true;
3139
3140 SessionDescriptionInterface* offer = CreateOffer(options);
3141 SetLocalDescriptionWithoutError(offer);
3142
deadbeefcbecd352015-09-23 11:50:27 -07003143 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3144 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003145
deadbeefab9b2d12015-10-14 11:33:11 -07003146 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003147
3148 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003149 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150 CreateRemoteAnswer(session_->local_description()));
3151 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3152 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3153 JsepSessionDescription* modified_answer =
3154 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3155 modified_answer->Initialize(answer_copy, "1", "1");
3156 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157
deadbeefcbecd352015-09-23 11:50:27 -07003158 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3159 session_->video_rtp_transport_channel());
3160}
3161
3162// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3163TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3164 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003165 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003166
3167 SessionDescriptionInterface* offer = CreateRemoteOffer();
3168 SetRemoteDescriptionWithoutError(offer);
3169
3170 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3171 session_->video_rtp_transport_channel());
3172
deadbeefab9b2d12015-10-14 11:33:11 -07003173 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003174 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003175 SetLocalDescriptionWithoutError(answer);
3176
3177 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3178 session_->video_rtp_transport_channel());
3179}
3180
3181// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3182TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3183 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003184 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003185
3186 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003187 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003188 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3189 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3190 JsepSessionDescription* modified_offer =
3191 new JsepSessionDescription(JsepSessionDescription::kOffer);
3192 modified_offer->Initialize(offer_copy, "1", "1");
3193
3194 // Expect an error when applying the remote description
3195 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3196 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003197}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198
Peter Thatcher4eddf182015-04-30 10:55:59 -07003199// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003200TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3201 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003202 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203
Donald Curtis0e209b02015-03-24 09:29:54 -07003204 PeerConnectionInterface::RTCOfferAnswerOptions options;
3205 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206
Donald Curtis0e209b02015-03-24 09:29:54 -07003207 SessionDescriptionInterface* offer = CreateOffer(options);
3208 SetLocalDescriptionWithoutError(offer);
3209
deadbeefcbecd352015-09-23 11:50:27 -07003210 EXPECT_NE(session_->voice_rtp_transport_channel(),
3211 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003212
deadbeefab9b2d12015-10-14 11:33:11 -07003213 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003214 SessionDescriptionInterface* answer =
3215 CreateRemoteAnswer(session_->local_description());
3216 SetRemoteDescriptionWithoutError(answer);
3217
3218 // This should lead to an audio-only call but isn't implemented
3219 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003220 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3221 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003222}
3223
deadbeefcbecd352015-09-23 11:50:27 -07003224// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003225TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3226 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003227 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003228 PeerConnectionInterface::RTCOfferAnswerOptions options;
3229 options.use_rtp_mux = true;
3230
3231 SessionDescriptionInterface* offer = CreateOffer(options);
3232 SetLocalDescriptionWithoutError(offer);
3233
deadbeefcbecd352015-09-23 11:50:27 -07003234 EXPECT_NE(session_->voice_rtp_transport_channel(),
3235 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003236
deadbeefab9b2d12015-10-14 11:33:11 -07003237 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003238
3239 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003240 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003241 CreateRemoteAnswer(session_->local_description()));
3242 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3243 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3244 JsepSessionDescription* modified_answer =
3245 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3246 modified_answer->Initialize(answer_copy, "1", "1");
3247 SetRemoteDescriptionWithoutError(modified_answer); //
3248
deadbeefcbecd352015-09-23 11:50:27 -07003249 EXPECT_NE(session_->voice_rtp_transport_channel(),
3250 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251}
3252
Peter Thatcher4eddf182015-04-30 10:55:59 -07003253// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3254TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3255 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003256 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003257
3258 PeerConnectionInterface::RTCOfferAnswerOptions options;
3259 options.use_rtp_mux = true;
3260
3261 SessionDescriptionInterface* offer = CreateOffer(options);
3262 SetRemoteDescriptionWithoutError(offer);
3263
deadbeefcbecd352015-09-23 11:50:27 -07003264 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3265 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003266}
3267
skvlad6c87a672016-05-17 17:49:52 -07003268// Adding a new channel to a BUNDLE which is already connected should directly
3269// assign the bundle transport to the channel, without first setting a
3270// disconnected non-bundle transport and then replacing it. The application
3271// should not receive any changes in the ICE state.
3272TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3273 LoopbackNetworkConfiguration config;
3274 LoopbackNetworkManager loopback_network_manager(this, config);
3275 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3276 // connected. Disabling either of these two means that we need to wait for the
3277 // answer to find out if more transports are needed.
3278 configuration_.bundle_policy =
3279 PeerConnectionInterface::kBundlePolicyMaxBundle;
3280 configuration_.rtcp_mux_policy =
3281 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3282 options_.disable_encryption = true;
3283 Init();
3284
3285 // Negotiate an audio channel with MAX_BUNDLE enabled.
3286 SendAudioOnlyStream2();
3287 SessionDescriptionInterface* offer = CreateOffer();
3288 SetLocalDescriptionWithoutError(offer);
3289 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3290 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3291 std::string sdp;
3292 offer->ToString(&sdp);
3293 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3294 JsepSessionDescription::kAnswer, sdp, nullptr);
3295 ASSERT_TRUE(answer != NULL);
3296 SetRemoteDescriptionWithoutError(answer);
3297
3298 // Wait for the ICE state to stabilize.
3299 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3300 observer_.ice_connection_state_, kIceCandidatesTimeout);
3301 observer_.ice_connection_state_history_.clear();
3302
3303 // Now add a video channel which should be using the same bundle transport.
3304 SendAudioVideoStream2();
3305 offer = CreateOffer();
3306 offer->ToString(&sdp);
3307 SetLocalDescriptionWithoutError(offer);
3308 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3309 sdp, nullptr);
3310 ASSERT_TRUE(answer != NULL);
3311 SetRemoteDescriptionWithoutError(answer);
3312
3313 // Wait for ICE state to stabilize
3314 rtc::Thread::Current()->ProcessMessages(0);
3315 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3316 observer_.ice_connection_state_, kIceCandidatesTimeout);
3317
3318 // No ICE state changes are expected to happen.
3319 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3320}
3321
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003322TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3323 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003324 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003325
3326 PeerConnectionInterface::RTCOfferAnswerOptions options;
3327 SessionDescriptionInterface* offer = CreateOffer(options);
3328 SetLocalDescriptionWithoutError(offer);
3329
deadbeefcbecd352015-09-23 11:50:27 -07003330 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3331 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003332
deadbeefab9b2d12015-10-14 11:33:11 -07003333 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003334 SessionDescriptionInterface* answer =
3335 CreateRemoteAnswer(session_->local_description());
3336 SetRemoteDescriptionWithoutError(answer);
3337
deadbeefcbecd352015-09-23 11:50:27 -07003338 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3339 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003340}
3341
3342TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3343 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003344 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003345
3346 PeerConnectionInterface::RTCOfferAnswerOptions options;
3347 SessionDescriptionInterface* offer = CreateOffer(options);
3348 SetLocalDescriptionWithoutError(offer);
3349
deadbeefcbecd352015-09-23 11:50:27 -07003350 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3351 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003352
deadbeefab9b2d12015-10-14 11:33:11 -07003353 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003354 SessionDescriptionInterface* answer =
3355 CreateRemoteAnswer(session_->local_description());
3356 SetRemoteDescriptionWithoutError(answer);
3357
deadbeefcbecd352015-09-23 11:50:27 -07003358 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3359 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003360}
3361
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003362// This test verifies that SetLocalDescription and SetRemoteDescription fails
3363// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3364TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003365 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003366 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003367
3368 PeerConnectionInterface::RTCOfferAnswerOptions options;
3369 options.use_rtp_mux = true;
3370
3371 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003372 std::string offer_str;
3373 offer->ToString(&offer_str);
3374 // Disable rtcp-mux
3375 const std::string rtcp_mux = "rtcp-mux";
3376 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003377 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003378 xrtcp_mux.c_str(), xrtcp_mux.length(),
3379 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003380 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003381 new JsepSessionDescription(JsepSessionDescription::kOffer);
3382 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003383 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003384 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003385 new JsepSessionDescription(JsepSessionDescription::kOffer);
3386 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003387 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003388 // Trying unmodified SDP.
3389 SetLocalDescriptionWithoutError(offer);
3390}
3391
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3393 TestCanInsertDtmf(false);
3394}
3395
3396TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3397 TestCanInsertDtmf(true);
3398}
3399
3400TEST_F(WebRtcSessionTest, InsertDtmf) {
3401 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003402 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003403 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 CreateAndSetRemoteOfferAndLocalAnswer();
3405 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3406 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3407
3408 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 const int expected_duration = 90;
3410 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3411 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3412 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3413
3414 // Verify
3415 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003416 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003418 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003420 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003422 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423}
3424
deadbeefd59daf82015-10-14 15:02:44 -07003425// This test verifies the |initial_offerer| flag when session initiates the
3426// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003428 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003429 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003430 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3432 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003433 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003435 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436}
3437
deadbeefd59daf82015-10-14 15:02:44 -07003438// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003440 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003441 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 SessionDescriptionInterface* offer = CreateRemoteOffer();
3443 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003444 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445
deadbeefd59daf82015-10-14 15:02:44 -07003446 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003448 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449}
3450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3452TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003453 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003454 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003455 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003457 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 CreateRemoteAnswer(session_->local_description()));
3459
3460 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3461 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003462 JsepSessionDescription* modified_answer =
3463 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464
3465 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3466 answer->session_id(),
3467 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003468 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469
wu@webrtc.org4e393072014-04-07 17:04:35 +00003470 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471 std::string sdp;
3472 EXPECT_TRUE(answer->ToString(&sdp));
3473 const std::string kAudioMid = "a=mid:audio";
3474 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003475 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 kAudioMidReplaceStr.c_str(),
3477 kAudioMidReplaceStr.length(),
3478 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003479 SessionDescriptionInterface* modified_answer1 =
3480 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003481 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482
wu@webrtc.org4e393072014-04-07 17:04:35 +00003483 // Different media types.
3484 EXPECT_TRUE(answer->ToString(&sdp));
3485 const std::string kAudioMline = "m=audio";
3486 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003487 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003488 kAudioMlineReplaceStr.c_str(),
3489 kAudioMlineReplaceStr.length(),
3490 &sdp);
3491 SessionDescriptionInterface* modified_answer2 =
3492 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3493 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 SetRemoteDescriptionWithoutError(answer.release());
3496}
3497
3498// Verifying remote offer and local answer have matching m-lines as per
3499// RFC 3264.
3500TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
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 SessionDescriptionInterface* offer = CreateRemoteOffer();
3504 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003505 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506
3507 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3508 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003509 JsepSessionDescription* modified_answer =
3510 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511
3512 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3513 answer->session_id(),
3514 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003515 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 SetLocalDescriptionWithoutError(answer);
3517}
3518
3519// This test verifies that WebRtcSession does not start candidate allocation
3520// before SetLocalDescription is called.
3521TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003522 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003523 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 SessionDescriptionInterface* offer = CreateRemoteOffer();
3525 cricket::Candidate candidate;
3526 candidate.set_component(1);
3527 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3528 candidate);
3529 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3530 cricket::Candidate candidate1;
3531 candidate1.set_component(1);
3532 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3533 candidate1);
3534 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3535 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003536 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3537 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538
3539 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003540 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3542 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3543
htaa2a49d92016-03-04 02:51:39 -08003544 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3547}
3548
3549// This test verifies that crypto parameter is updated in local session
3550// description as per security policy set in MediaSessionDescriptionFactory.
3551TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003552 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003553 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003554 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003555
3556 // Making sure SetLocalDescription correctly sets crypto value in
3557 // SessionDescription object after de-serialization of sdp string. The value
3558 // will be set as per MediaSessionDescriptionFactory.
3559 std::string offer_str;
3560 offer->ToString(&offer_str);
3561 SessionDescriptionInterface* jsep_offer_str =
3562 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3563 SetLocalDescriptionWithoutError(jsep_offer_str);
3564 EXPECT_TRUE(session_->voice_channel()->secure_required());
3565 EXPECT_TRUE(session_->video_channel()->secure_required());
3566}
3567
3568// This test verifies the crypto parameter when security is disabled.
3569TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003570 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003571 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003572 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003573 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574
3575 // Making sure SetLocalDescription correctly sets crypto value in
3576 // SessionDescription object after de-serialization of sdp string. The value
3577 // will be set as per MediaSessionDescriptionFactory.
3578 std::string offer_str;
3579 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003580 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3582 SetLocalDescriptionWithoutError(jsep_offer_str);
3583 EXPECT_FALSE(session_->voice_channel()->secure_required());
3584 EXPECT_FALSE(session_->video_channel()->secure_required());
3585}
3586
3587// This test verifies that an answer contains new ufrag and password if an offer
3588// with new ufrag and password is received.
3589TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003590 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003592 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003593 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 SetRemoteDescriptionWithoutError(offer.release());
3595
deadbeefab9b2d12015-10-14 11:33:11 -07003596 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003597 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 SetLocalDescriptionWithoutError(answer.release());
3599
3600 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003601 for (const cricket::ContentInfo& content :
3602 session_->local_description()->description()->contents()) {
3603 options.transport_options[content.name].ice_restart = true;
3604 }
kwibergd1fe2812016-04-27 06:47:29 -07003605 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003606 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607 SetRemoteDescriptionWithoutError(updated_offer1.release());
3608
kwibergd1fe2812016-04-27 06:47:29 -07003609 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610
deadbeef0ed85b22016-02-23 17:24:52 -08003611 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3612 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613
deadbeef0ed85b22016-02-23 17:24:52 -08003614 // Even a second answer (created before the description is set) should have
3615 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003616 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003617
3618 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3619 session_->local_description()->description()));
3620
3621 SetLocalDescriptionWithoutError(updated_answer2.release());
3622}
3623
3624// This test verifies that an answer contains new ufrag and password if an offer
3625// that changes either the ufrag or password (but not both) is received.
3626// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3627// a=ice-pwd attributes compared to the previous SDP from the peer, it
3628// indicates that ICE is restarting for this media stream."
3629TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3630 Init();
3631 cricket::MediaSessionOptions options;
3632 options.recv_audio = true;
3633 options.recv_video = true;
3634 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003635 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003636 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3637 SetRemoteDescriptionWithoutError(offer.release());
3638
3639 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003640 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003641 SetLocalDescriptionWithoutError(answer.release());
3642
3643 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003644 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003645 CreateRemoteOffer(options, session_->remote_description()));
3646 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3647 "original_password12345");
3648 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3649
kwibergd1fe2812016-04-27 06:47:29 -07003650 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003651 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3652 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003654
3655 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003656 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003657 CreateRemoteOffer(options, session_->remote_description()));
3658 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3659 "modified_password12345");
3660 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3661
kwibergd1fe2812016-04-27 06:47:29 -07003662 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003663 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3664 session_->local_description()->description()));
3665 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003666}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
wu@webrtc.org91053e72013-08-10 07:18:04 +00003668// This test verifies that an answer contains old ufrag and password if an offer
3669// with old ufrag and password is received.
3670TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003671 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003672 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003673 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003674 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003675 SetRemoteDescriptionWithoutError(offer.release());
3676
deadbeefab9b2d12015-10-14 11:33:11 -07003677 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003678 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003679 SetLocalDescriptionWithoutError(answer.release());
3680
3681 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003682 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003683 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 SetRemoteDescriptionWithoutError(updated_offer2.release());
3685
kwibergd1fe2812016-04-27 06:47:29 -07003686 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003687
deadbeef0ed85b22016-02-23 17:24:52 -08003688 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3689 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690
3691 SetLocalDescriptionWithoutError(updated_answer2.release());
3692}
3693
deadbeef0ed85b22016-02-23 17:24:52 -08003694// This test verifies that if an offer does an ICE restart on some, but not all
3695// media sections, the answer will change the ufrag/password in the correct
3696// media sections.
3697TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3698 Init();
3699 cricket::MediaSessionOptions options;
3700 options.recv_video = true;
3701 options.recv_audio = true;
3702 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003703 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003704
3705 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3706 "aaaaaaaaaaaaaaaaaaaaaa");
3707 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3708 "bbbbbbbbbbbbbbbbbbbbbb");
3709 SetRemoteDescriptionWithoutError(offer.release());
3710
3711 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003712 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003713 SetLocalDescriptionWithoutError(answer.release());
3714
3715 // Receive an offer with new ufrag and password, but only for the video media
3716 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003717 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003718 CreateRemoteOffer(options, session_->remote_description()));
3719 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3720 "cccccccccccccccccccccc");
3721 SetRemoteDescriptionWithoutError(updated_offer.release());
3722
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003724
3725 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3726 session_->local_description()->description(),
3727 cricket::MEDIA_TYPE_AUDIO));
3728
3729 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3730 session_->local_description()->description(),
3731 cricket::MEDIA_TYPE_VIDEO));
3732
3733 SetLocalDescriptionWithoutError(updated_answer.release());
3734}
3735
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003737 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003738 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003739 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 const std::string session_id_orig = offer->session_id();
3741 const std::string session_version_orig = offer->session_version();
3742 SetLocalDescriptionWithoutError(offer);
3743
3744 video_channel_ = media_engine_->GetVideoChannel(0);
3745 video_channel_->set_fail_set_send_codecs(true);
3746
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003747 SessionDescriptionInterface* answer =
3748 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003749 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003750
3751 // Test that after a content error, setting any description will
3752 // result in an error.
3753 video_channel_->set_fail_set_send_codecs(false);
3754 answer = CreateRemoteAnswer(session_->local_description());
3755 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3756 offer = CreateRemoteOffer();
3757 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003758}
3759
3760// Runs the loopback call test with BUNDLE and STUN disabled.
3761TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3762 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003763 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003764 cricket::PORTALLOCATOR_DISABLE_STUN |
3765 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766 TestLoopbackCall();
3767}
3768
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003769TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003770 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003771 cricket::PORTALLOCATOR_DISABLE_STUN |
3772 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3773 cricket::PORTALLOCATOR_DISABLE_RELAY);
3774
3775 // best connection is IPv6 since it has higher network preference.
3776 LoopbackNetworkConfiguration config;
3777 config.test_ipv6_network_ = true;
3778 config.best_connection_after_initial_ice_converged_ =
3779 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3780
3781 TestLoopbackCall(config);
3782}
3783
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003784// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003785TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003786 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3787 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003788 TestLoopbackCall();
3789}
3790
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003791TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003792 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003793 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003794 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003795 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3797}
3798
Henrik Boström87713d02015-08-25 09:53:21 +02003799TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003800 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003801
htaa2a49d92016-03-04 02:51:39 -08003802 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003803 options_.disable_sctp_data_channels = false;
3804
Henrik Boström87713d02015-08-25 09:53:21 +02003805 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003806
3807 SetLocalDescriptionWithDataChannel();
3808 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3809}
3810
Henrik Boström87713d02015-08-25 09:53:21 +02003811TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003812 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003813
Henrik Boström87713d02015-08-25 09:53:21 +02003814 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003815
kwibergd1fe2812016-04-27 06:47:29 -07003816 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003817 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003818 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3819}
3820
Henrik Boström87713d02015-08-25 09:53:21 +02003821TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003822 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003823 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003824 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003825
3826 // Create remote offer with SCTP.
3827 cricket::MediaSessionOptions options;
3828 options.data_channel_type = cricket::DCT_SCTP;
3829 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003830 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003831 SetRemoteDescriptionWithoutError(offer);
3832
3833 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003834 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003835 EXPECT_TRUE(answer != NULL);
3836 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3837 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003838}
3839
Henrik Boström87713d02015-08-25 09:53:21 +02003840TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003841 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003842 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003843
3844 SetLocalDescriptionWithDataChannel();
3845 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3846}
3847
Henrik Boström87713d02015-08-25 09:53:21 +02003848TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003849 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850
Henrik Boström87713d02015-08-25 09:53:21 +02003851 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003852
3853 SetLocalDescriptionWithDataChannel();
3854 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3855}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003856
Henrik Boström87713d02015-08-25 09:53:21 +02003857TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003858 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003859 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003860 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003861
3862 SetLocalDescriptionWithDataChannel();
3863 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3864}
3865
Henrik Boström87713d02015-08-25 09:53:21 +02003866TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003867 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003868 const int new_send_port = 9998;
3869 const int new_recv_port = 7775;
3870
Henrik Boström87713d02015-08-25 09:53:21 +02003871 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003872 SetFactoryDtlsSrtp();
3873
3874 // By default, don't actually add the codecs to desc_factory_; they don't
3875 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3876 // let the session description get parsed. That'll get the proper codecs
3877 // into the stream.
3878 cricket::MediaSessionOptions options;
3879 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3880 "stream1", new_send_port, options);
3881
3882 // SetRemoteDescription will take the ownership of the offer.
3883 SetRemoteDescriptionWithoutError(offer);
3884
htaa2a49d92016-03-04 02:51:39 -08003885 SessionDescriptionInterface* answer =
3886 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003887 ASSERT_TRUE(answer != NULL);
3888
3889 // Now set the local description, which'll take ownership of the answer.
3890 SetLocalDescriptionWithoutError(answer);
3891
3892 // TEST PLAN: Set the port number to something new, set it in the SDP,
3893 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003894 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003895 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003896
3897 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3898 int portnum = -1;
3899 ASSERT_TRUE(ch != NULL);
3900 ASSERT_EQ(1UL, ch->send_codecs().size());
3901 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003902 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003903 ch->send_codecs()[0].name.c_str()));
3904 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3905 &portnum));
3906 EXPECT_EQ(new_send_port, portnum);
3907
3908 ASSERT_EQ(1UL, ch->recv_codecs().size());
3909 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003910 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003911 ch->recv_codecs()[0].name.c_str()));
3912 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3913 &portnum));
3914 EXPECT_EQ(new_recv_port, portnum);
3915}
3916
deadbeefab9b2d12015-10-14 11:33:11 -07003917// Verifies that when a session's DataChannel receives an OPEN message,
3918// WebRtcSession signals the DataChannel creation request with the expected
3919// config.
3920TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3921 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3922
3923 InitWithDtls(GetParam());
3924
3925 SetLocalDescriptionWithDataChannel();
3926 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3927
3928 webrtc::DataChannelInit config;
3929 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07003930 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07003931 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3932 cricket::ReceiveDataParams params;
3933 params.ssrc = config.id;
3934 params.type = cricket::DMT_CONTROL;
3935
3936 cricket::DataChannel* data_channel = session_->data_channel();
3937 data_channel->SignalDataReceived(data_channel, params, payload);
3938
3939 EXPECT_EQ("a", last_data_channel_label_);
3940 EXPECT_EQ(config.id, last_data_channel_config_.id);
3941 EXPECT_FALSE(last_data_channel_config_.negotiated);
3942 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3943 last_data_channel_config_.open_handshake_role);
3944}
3945
3946TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003947 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02003948 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02003949
htaa2a49d92016-03-04 02:51:39 -08003950 configuration_.certificates.push_back(certificate);
3951 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02003952 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3953
3954 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3955}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003956
Henrik Boström87713d02015-08-25 09:53:21 +02003957// Verifies that CreateOffer succeeds when CreateOffer is called before async
3958// identity generation is finished (even if a certificate is provided this is
3959// an async op).
3960TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3961 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3962 InitWithDtls(GetParam());
3963
Henrik Boströmd8281982015-08-27 10:12:24 +02003964 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003965 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003966 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003967
wu@webrtc.org91053e72013-08-10 07:18:04 +00003968 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003969 VerifyNoCryptoParams(offer->description(), true);
3970 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003971}
3972
3973// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003974// identity generation is finished (even if a certificate is provided this is
3975// an async op).
3976TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003978 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003979 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003980
3981 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003982 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003983 std::unique_ptr<JsepSessionDescription> offer(
3984 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003985 ASSERT_TRUE(offer.get() != NULL);
3986 SetRemoteDescriptionWithoutError(offer.release());
3987
kwibergd1fe2812016-04-27 06:47:29 -07003988 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003990 VerifyNoCryptoParams(answer->description(), true);
3991 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003992}
3993
3994// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003995// identity generation is finished (even if a certificate is provided this is
3996// an async op).
3997TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003998 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003999 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004000
Henrik Boströmd8281982015-08-27 10:12:24 +02004001 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004002
kwibergd1fe2812016-04-27 06:47:29 -07004003 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004004 EXPECT_TRUE(offer != NULL);
4005}
4006
4007// Verifies that CreateOffer fails when CreateOffer is called after async
4008// identity generation fails.
4009TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004010 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004011 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004012
Henrik Boströmd8281982015-08-27 10:12:24 +02004013 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004014
kwibergd1fe2812016-04-27 06:47:29 -07004015 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004016 EXPECT_TRUE(offer == NULL);
4017}
4018
4019// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4020// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004021TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004022 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004023 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004024 VerifyMultipleAsyncCreateDescription(GetParam(),
4025 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004026}
4027
4028// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4029// before async identity generation fails.
4030TEST_F(WebRtcSessionTest,
4031 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004033 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4034 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035}
4036
4037// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4038// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004039TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004040 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004042 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004043 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004044}
4045
4046// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4047// before async identity generation fails.
4048TEST_F(WebRtcSessionTest,
4049 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004050 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004051 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4052 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004053}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004054
4055// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4056// offer has no SDES crypto but only DTLS fingerprint.
4057TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4058 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004059 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004060 // Create a remote offer with secured transport disabled.
4061 cricket::MediaSessionOptions options;
4062 JsepSessionDescription* offer(CreateRemoteOffer(
4063 options, cricket::SEC_DISABLED));
4064 // Adds a DTLS fingerprint to the remote offer.
4065 cricket::SessionDescription* sdp = offer->description();
4066 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4067 ASSERT_TRUE(audio != NULL);
4068 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4069 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004070 rtc::SSLFingerprint::CreateFromRfc4572(
4071 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004072 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004073 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004074}
4075
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004076TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004077 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004078 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004079 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004080 SessionDescriptionInterface* offer = CreateOffer();
4081
4082 SetLocalDescriptionWithoutError(offer);
4083
4084 voice_channel_ = media_engine_->GetVoiceChannel(0);
4085
4086 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004087 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004088 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004089}
4090
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004091// Tests that we can renegotiate new media content with ICE candidates in the
4092// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004093TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004094 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004095 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004096 SetFactoryDtlsSrtp();
4097
deadbeefab9b2d12015-10-14 11:33:11 -07004098 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004099 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004100 SetLocalDescriptionWithoutError(offer);
4101
4102 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4103 SetRemoteDescriptionWithoutError(answer);
4104
4105 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004106 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004107 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4108
4109 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004110 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004111 candidate1.set_component(1);
4112 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4113 candidate1);
4114 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4115 SetRemoteDescriptionWithoutError(offer);
4116
htaa2a49d92016-03-04 02:51:39 -08004117 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004118 SetLocalDescriptionWithoutError(answer);
4119}
4120
4121// Tests that we can renegotiate new media content with ICE candidates separated
4122// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004123TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004124 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004125 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004126 SetFactoryDtlsSrtp();
4127
deadbeefab9b2d12015-10-14 11:33:11 -07004128 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004129 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004130 SetLocalDescriptionWithoutError(offer);
4131
4132 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4133 SetRemoteDescriptionWithoutError(answer);
4134
4135 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004136 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004137 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4138 SetRemoteDescriptionWithoutError(offer);
4139
4140 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004141 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004142 candidate1.set_component(1);
4143 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4144 candidate1);
4145 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4146
htaa2a49d92016-03-04 02:51:39 -08004147 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004148 SetLocalDescriptionWithoutError(answer);
4149}
honghaiz7f777492016-02-02 21:54:01 -08004150
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004151// Tests that RTX codec is removed from the answer when it isn't supported
4152// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004153TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004154 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004155 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004156 std::string offer_sdp(kSdpWithRtx);
4157
4158 SessionDescriptionInterface* offer =
4159 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4160 EXPECT_TRUE(offer->ToString(&offer_sdp));
4161
4162 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004163 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004164 SetRemoteDescriptionWithoutError(offer);
4165
htaa2a49d92016-03-04 02:51:39 -08004166 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004167 // Answer SDP does not contain the RTX codec.
4168 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004169 SetLocalDescriptionWithoutError(answer);
4170}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004171
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004172// This verifies that the voice channel after bundle has both options from video
4173// and voice channels.
4174TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4175 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004176 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004177
4178 PeerConnectionInterface::RTCOfferAnswerOptions options;
4179 options.use_rtp_mux = true;
4180
4181 SessionDescriptionInterface* offer = CreateOffer(options);
4182 SetLocalDescriptionWithoutError(offer);
4183
4184 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4185 rtc::Socket::Option::OPT_SNDBUF, 4000);
4186
4187 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4188 rtc::Socket::Option::OPT_RCVBUF, 8000);
4189
4190 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004191 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004192 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4193 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004194 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004195 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4196
deadbeefcbecd352015-09-23 11:50:27 -07004197 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004198 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4199 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004200 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004201 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4202
deadbeefcbecd352015-09-23 11:50:27 -07004203 EXPECT_NE(session_->voice_rtp_transport_channel(),
4204 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004205
deadbeefab9b2d12015-10-14 11:33:11 -07004206 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004207 SessionDescriptionInterface* answer =
4208 CreateRemoteAnswer(session_->local_description());
4209 SetRemoteDescriptionWithoutError(answer);
4210
deadbeefcbecd352015-09-23 11:50:27 -07004211 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004212 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4213 EXPECT_EQ(4000, option_val);
4214
deadbeefcbecd352015-09-23 11:50:27 -07004215 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004216 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4217 EXPECT_EQ(8000, option_val);
4218}
4219
tommi0f620f42015-07-09 03:25:02 -07004220// Test creating a session, request multiple offers, destroy the session
4221// and make sure we got success/failure callbacks for all of the requests.
4222// Background: crbug.com/507307
4223TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4224 Init();
4225
4226 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4227 PeerConnectionInterface::RTCOfferAnswerOptions options;
4228 options.offer_to_receive_audio =
4229 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004230 cricket::MediaSessionOptions session_options;
4231 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004232
4233 for (auto& o : observers) {
4234 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004235 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004236 }
4237
4238 session_.reset();
4239
tommi0f620f42015-07-09 03:25:02 -07004240 for (auto& o : observers) {
4241 // We expect to have received a notification now even if the session was
4242 // terminated. The offer creation may or may not have succeeded, but we
4243 // must have received a notification which, so the only invalid state
4244 // is kInit.
4245 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4246 }
4247}
4248
stefanc1aeaf02015-10-15 07:26:07 -07004249TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4250 TestPacketOptions();
4251}
4252
deadbeef057ecf02016-01-20 14:30:43 -08004253// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4254// is destroyed.
4255TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4256 Init();
4257 session_.reset();
4258 EXPECT_TRUE(session_destroyed_);
4259}
4260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004261// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4262// currently fails because upon disconnection and reconnection OnIceComplete is
4263// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004264
deadbeefcbecd352015-09-23 11:50:27 -07004265INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4266 WebRtcSessionTest,
4267 testing::Values(ALREADY_GENERATED,
4268 DTLS_IDENTITY_STORE));