blob: ba9ea2b438abb0c52c79252b3e008cb097e69e17 [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"
skvlad11a9cbf2016-10-07 11:53:05 -070038#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080039#include "webrtc/media/base/fakemediaengine.h"
40#include "webrtc/media/base/fakevideorenderer.h"
41#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010042#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080043#include "webrtc/p2p/base/stunserver.h"
44#include "webrtc/p2p/base/teststunserver.h"
45#include "webrtc/p2p/base/testturnserver.h"
46#include "webrtc/p2p/base/transportchannel.h"
47#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010048#include "webrtc/pc/channelmanager.h"
49#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51#define MAYBE_SKIP_TEST(feature) \
52 if (!(feature())) { \
53 LOG(LS_INFO) << "Feature disabled... skipping"; \
54 return; \
55 }
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000062using webrtc::CreateSessionDescriptionObserver;
63using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070064using webrtc::DataChannel;
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:
zhihuang29ff8442016-07-27 11:07:25 -0700215 WebRtcSessionForTest(
216 webrtc::MediaControllerInterface* media_controller,
217 rtc::Thread* network_thread,
218 rtc::Thread* worker_thread,
219 rtc::Thread* signaling_thread,
220 cricket::PortAllocator* port_allocator,
221 webrtc::IceObserver* ice_observer,
222 std::unique_ptr<cricket::TransportController> transport_controller)
stefanc1aeaf02015-10-15 07:26:07 -0700223 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700224 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700225 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700226 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700227 port_allocator,
228 std::move(transport_controller)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 RegisterIceObserver(ice_observer);
230 }
231 virtual ~WebRtcSessionForTest() {}
232
deadbeefcbecd352015-09-23 11:50:27 -0700233 // Note that these methods are only safe to use if the signaling thread
234 // is the same as the worker thread
235 cricket::TransportChannel* voice_rtp_transport_channel() {
236 return rtp_transport_channel(voice_channel());
237 }
238
239 cricket::TransportChannel* voice_rtcp_transport_channel() {
240 return rtcp_transport_channel(voice_channel());
241 }
242
243 cricket::TransportChannel* video_rtp_transport_channel() {
244 return rtp_transport_channel(video_channel());
245 }
246
247 cricket::TransportChannel* video_rtcp_transport_channel() {
248 return rtcp_transport_channel(video_channel());
249 }
250
251 cricket::TransportChannel* data_rtp_transport_channel() {
252 return rtp_transport_channel(data_channel());
253 }
254
255 cricket::TransportChannel* data_rtcp_transport_channel() {
256 return rtcp_transport_channel(data_channel());
257 }
258
deadbeefcbecd352015-09-23 11:50:27 -0700259 private:
260 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
261 if (!ch) {
262 return nullptr;
263 }
264 return ch->transport_channel();
265 }
266
267 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
268 if (!ch) {
269 return nullptr;
270 }
271 return ch->rtcp_transport_channel();
272 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273};
274
wu@webrtc.org91053e72013-08-10 07:18:04 +0000275class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000276 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278 enum State {
279 kInit,
280 kFailed,
281 kSucceeded,
282 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000283 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284
285 // CreateSessionDescriptionObserver implementation.
286 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000287 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000288 state_ = kSucceeded;
289 }
290 virtual void OnFailure(const std::string& error) {
291 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
293
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000294 SessionDescriptionInterface* description() { return description_.get(); }
295
296 SessionDescriptionInterface* ReleaseDescription() {
297 return description_.release();
298 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299
wu@webrtc.org91053e72013-08-10 07:18:04 +0000300 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
wu@webrtc.org91053e72013-08-10 07:18:04 +0000302 protected:
303 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
305 private:
kwibergd1fe2812016-04-27 06:47:29 -0700306 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308};
309
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800310class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800312 FakeAudioSource() : sink_(NULL) {}
313 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000314 if (sink_)
315 sink_->OnClose();
316 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000318 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800320 const cricket::AudioSource::Sink* sink() const { return sink_; }
321
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800323 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324};
325
Henrik Boström87713d02015-08-25 09:53:21 +0200326class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700327 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
328 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 protected:
330 // TODO Investigate why ChannelManager crashes, if it's created
331 // after stun_server.
332 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700333 : media_engine_(new cricket::FakeMediaEngine()),
334 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700335 channel_manager_(new cricket::ChannelManager(media_engine_,
336 data_engine_,
337 rtc::Thread::Current())),
338 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700339 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800340 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
341 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700342 channel_manager_.get(),
343 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700344 tdesc_factory_(new cricket::TransportDescriptionFactory()),
345 desc_factory_(
346 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
347 tdesc_factory_.get())),
348 pss_(new rtc::PhysicalSocketServer),
349 vss_(new rtc::VirtualSocketServer(pss_.get())),
350 fss_(new rtc::FirewallSocketServer(vss_.get())),
351 ss_scope_(fss_.get()),
352 stun_socket_addr_(
353 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
354 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
355 stun_socket_addr_)),
356 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
357 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000358 cricket::ServerAddresses stun_servers;
359 stun_servers.insert(stun_socket_addr_);
360 allocator_.reset(new cricket::BasicPortAllocator(
361 &network_manager_,
362 stun_servers,
363 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700365 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 EXPECT_TRUE(channel_manager_->Init());
367 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000368 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370
371 void AddInterface(const SocketAddress& addr) {
372 network_manager_.AddInterface(addr);
373 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700374 void RemoveInterface(const SocketAddress& addr) {
375 network_manager_.RemoveInterface(addr);
376 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377
Henrik Boströmd79599d2016-06-01 13:58:50 +0200378 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
379 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
380 // options. When DTLS is enabled a certificate will be used if provided,
381 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000382 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200383 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 ASSERT_TRUE(session_.get() == NULL);
385 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700386 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700387 rtc::Thread::Current(), allocator_.get(), &observer_,
388 std::unique_ptr<cricket::TransportController>(
389 new cricket::TransportController(rtc::Thread::Current(),
390 rtc::Thread::Current(),
391 allocator_.get()))));
deadbeefab9b2d12015-10-14 11:33:11 -0700392 session_->SignalDataChannelOpenMessage.connect(
393 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800394 session_->GetOnDestroyedSignal()->connect(
395 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396
397 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
398 observer_.ice_connection_state_);
399 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
400 observer_.ice_gathering_state_);
401
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200402 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800403 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700404 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
deadbeefab9b2d12015-10-14 11:33:11 -0700407 void OnDataChannelOpenMessage(const std::string& label,
408 const InternalDataChannelInit& config) {
409 last_data_channel_label_ = label;
410 last_data_channel_config_ = config;
411 }
412
deadbeef057ecf02016-01-20 14:30:43 -0800413 void OnSessionDestroyed() { session_destroyed_ = true; }
414
htaa2a49d92016-03-04 02:51:39 -0800415 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000416
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000417 void InitWithBundlePolicy(
418 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800419 configuration_.bundle_policy = bundle_policy;
420 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700421 }
422
423 void InitWithRtcpMuxPolicy(
424 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
425 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800426 configuration_.rtcp_mux_policy = rtcp_mux_policy;
427 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000428 }
429
Henrik Boström87713d02015-08-25 09:53:21 +0200430 // Successfully init with DTLS; with a certificate generated and supplied or
431 // with a store that generates it for us.
432 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200433 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200434 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800435 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200436 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200437 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200438 cert_generator.reset(new FakeRTCCertificateGenerator());
439 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200440 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700441 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200442 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200443 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200444 }
445
446 // Init with DTLS with a store that will fail to generate a certificate.
447 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200448 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
449 new FakeRTCCertificateGenerator());
450 cert_generator->set_should_fail(true);
451 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000452 }
453
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 void InitWithDtmfCodec() {
455 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700456 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
457 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 std::vector<cricket::AudioCodec> codecs;
459 codecs.push_back(kTelephoneEventCodec);
460 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700461 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000462 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 }
464
jbauchcb560652016-08-04 05:20:32 -0700465 void InitWithGcm() {
466 rtc::CryptoOptions crypto_options;
467 crypto_options.enable_gcm_crypto_suites = true;
468 channel_manager_->SetCryptoOptions(crypto_options);
469 with_gcm_ = true;
470 Init();
471 }
472
deadbeefab9b2d12015-10-14 11:33:11 -0700473 void SendAudioVideoStream1() {
474 send_stream_1_ = true;
475 send_stream_2_ = false;
476 send_audio_ = true;
477 send_video_ = true;
478 }
479
480 void SendAudioVideoStream2() {
481 send_stream_1_ = false;
482 send_stream_2_ = true;
483 send_audio_ = true;
484 send_video_ = true;
485 }
486
487 void SendAudioVideoStream1And2() {
488 send_stream_1_ = true;
489 send_stream_2_ = true;
490 send_audio_ = true;
491 send_video_ = true;
492 }
493
494 void SendNothing() {
495 send_stream_1_ = false;
496 send_stream_2_ = false;
497 send_audio_ = false;
498 send_video_ = false;
499 }
500
501 void SendAudioOnlyStream2() {
502 send_stream_1_ = false;
503 send_stream_2_ = true;
504 send_audio_ = true;
505 send_video_ = false;
506 }
507
508 void SendVideoOnlyStream2() {
509 send_stream_1_ = false;
510 send_stream_2_ = true;
511 send_audio_ = false;
512 send_video_ = true;
513 }
514
515 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
516 if (send_stream_1_ && send_audio_) {
517 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
518 kStream1);
519 }
520 if (send_stream_1_ && send_video_) {
521 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
522 kStream1);
523 }
524 if (send_stream_2_ && send_audio_) {
525 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
526 kStream2);
527 }
528 if (send_stream_2_ && send_video_) {
529 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
530 kStream2);
531 }
532 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
533 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
534 data_channel_->label(),
535 data_channel_->label());
536 }
537 }
538
539 void GetOptionsForOffer(
540 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
541 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800542 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700543
deadbeefc80741f2015-10-22 13:14:45 -0700544 AddStreamsToOptions(session_options);
545 if (rtc_options.offer_to_receive_audio ==
546 RTCOfferAnswerOptions::kUndefined) {
547 session_options->recv_audio =
548 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
549 }
550 if (rtc_options.offer_to_receive_video ==
551 RTCOfferAnswerOptions::kUndefined) {
552 session_options->recv_video =
553 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
554 }
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 && data_channel_) {
561 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700562 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
563 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700564 }
jbauchcb560652016-08-04 05:20:32 -0700565
566 if (with_gcm_) {
567 session_options->crypto_options.enable_gcm_crypto_suites = true;
568 }
deadbeefab9b2d12015-10-14 11:33:11 -0700569 }
570
htaa2a49d92016-03-04 02:51:39 -0800571 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
572 // ParseConstraintsForAnswer is used to set some defaults.
573 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700574
deadbeefc80741f2015-10-22 13:14:45 -0700575 AddStreamsToOptions(session_options);
576 session_options->bundle_enabled =
577 session_options->bundle_enabled &&
578 (session_options->has_audio() || session_options->has_video() ||
579 session_options->has_data());
580
zhihuang9763d562016-08-05 11:14:50 -0700581 if (session_->data_channel_type() != cricket::DCT_RTP) {
582 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700583 }
jbauchcb560652016-08-04 05:20:32 -0700584
585 if (with_gcm_) {
586 session_options->crypto_options.enable_gcm_crypto_suites = true;
587 }
deadbeefab9b2d12015-10-14 11:33:11 -0700588 }
589
590 // Creates a local offer and applies it. Starts ICE.
591 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 // to decide which streams to create.
593 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000594 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 SetLocalDescriptionWithoutError(offer);
596 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
597 observer_.ice_gathering_state_,
598 kIceCandidatesTimeout);
599 }
600
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000601 SessionDescriptionInterface* CreateOffer() {
602 PeerConnectionInterface::RTCOfferAnswerOptions options;
603 options.offer_to_receive_audio =
604 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
605
606 return CreateOffer(options);
607 }
608
wu@webrtc.org91053e72013-08-10 07:18:04 +0000609 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800610 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000611 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700613 cricket::MediaSessionOptions session_options;
614 GetOptionsForOffer(options, &session_options);
615 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 EXPECT_TRUE_WAIT(
617 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000618 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000619 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000620 }
621
622 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800623 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000624 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000625 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800626 cricket::MediaSessionOptions session_options = options;
627 GetOptionsForAnswer(&session_options);
628 // Overwrite recv_audio and recv_video with passed-in values.
629 session_options.recv_video = options.recv_video;
630 session_options.recv_audio = options.recv_audio;
631 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000632 EXPECT_TRUE_WAIT(
633 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000634 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000635 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000636 }
637
htaa2a49d92016-03-04 02:51:39 -0800638 SessionDescriptionInterface* CreateAnswer() {
639 cricket::MediaSessionOptions options;
640 options.recv_video = true;
641 options.recv_audio = true;
642 return CreateAnswer(options);
643 }
644
wu@webrtc.org364f2042013-11-20 21:49:41 +0000645 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 return (session_->voice_channel() != NULL &&
647 session_->video_channel() != NULL);
648 }
649
jbauchcb560652016-08-04 05:20:32 -0700650 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
651 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 ASSERT_TRUE(session_.get() != NULL);
653 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
654 ASSERT_TRUE(content != NULL);
655 const cricket::AudioContentDescription* audio_content =
656 static_cast<const cricket::AudioContentDescription*>(
657 content->description);
658 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700659 if (!gcm_enabled) {
660 ASSERT_EQ(1U, audio_content->cryptos().size());
661 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
662 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
663 audio_content->cryptos()[0].cipher_suite);
664 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
665 audio_content->protocol());
666 } else {
667 // The offer contains 3 possible crypto suites, the answer 1.
668 EXPECT_LE(1U, audio_content->cryptos().size());
669 EXPECT_NE(2U, audio_content->cryptos().size());
670 EXPECT_GE(3U, audio_content->cryptos().size());
671 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
672 ASSERT_EQ("AEAD_AES_256_GCM",
673 audio_content->cryptos()[0].cipher_suite);
674 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
675 audio_content->protocol());
676 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677
678 content = cricket::GetFirstVideoContent(sdp);
679 ASSERT_TRUE(content != NULL);
680 const cricket::VideoContentDescription* video_content =
681 static_cast<const cricket::VideoContentDescription*>(
682 content->description);
683 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700684 if (!gcm_enabled) {
685 ASSERT_EQ(1U, video_content->cryptos().size());
686 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
687 video_content->cryptos()[0].cipher_suite);
688 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
689 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
690 video_content->protocol());
691 } else {
692 // The offer contains 3 possible crypto suites, the answer 1.
693 EXPECT_LE(1U, video_content->cryptos().size());
694 EXPECT_NE(2U, video_content->cryptos().size());
695 EXPECT_GE(3U, video_content->cryptos().size());
696 ASSERT_EQ("AEAD_AES_256_GCM",
697 video_content->cryptos()[0].cipher_suite);
698 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
699 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
700 video_content->protocol());
701 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 }
703
704 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
705 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
706 ASSERT_TRUE(content != NULL);
707 const cricket::AudioContentDescription* audio_content =
708 static_cast<const cricket::AudioContentDescription*>(
709 content->description);
710 ASSERT_TRUE(audio_content != NULL);
711 ASSERT_EQ(0U, audio_content->cryptos().size());
712
713 content = cricket::GetFirstVideoContent(sdp);
714 ASSERT_TRUE(content != NULL);
715 const cricket::VideoContentDescription* video_content =
716 static_cast<const cricket::VideoContentDescription*>(
717 content->description);
718 ASSERT_TRUE(video_content != NULL);
719 ASSERT_EQ(0U, video_content->cryptos().size());
720
721 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700722 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700724 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 video_content->protocol());
726 } else {
727 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
728 audio_content->protocol());
729 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
730 video_content->protocol());
731 }
732 }
733
734 // Set the internal fake description factories to do DTLS-SRTP.
735 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000736 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000738 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200739 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800740 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700741 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800742 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
744 }
745
746 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
747 bool expected) {
748 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
749 ASSERT_TRUE(audio != NULL);
750 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 const TransportInfo* video = sdp->GetTransportInfoByName("video");
752 ASSERT_TRUE(video != NULL);
753 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 }
755
756 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000757 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000759 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000760 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000762 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000764 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
765 offer);
htaa2a49d92016-03-04 02:51:39 -0800766 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 // Answer should be NULL as no crypto params in offer.
768 ASSERT_TRUE(answer == NULL);
769 }
770
771 void VerifyAnswerFromCryptoOffer() {
772 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000773 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700775 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
777 ASSERT_TRUE(offer.get() != NULL);
778 VerifyCryptoParams(offer->description());
779 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700780 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 ASSERT_TRUE(answer.get() != NULL);
782 VerifyCryptoParams(answer->description());
783 }
784
deadbeef0ed85b22016-02-23 17:24:52 -0800785 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
786 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800788 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 }
790
791 const cricket::ContentInfos& contents = desc1->contents();
792 cricket::ContentInfos::const_iterator it = contents.begin();
793
794 for (; it != contents.end(); ++it) {
795 const cricket::TransportDescription* transport_desc1 =
796 desc1->GetTransportDescriptionByName(it->name);
797 const cricket::TransportDescription* transport_desc2 =
798 desc2->GetTransportDescriptionByName(it->name);
799 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800800 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
803 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800804 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 }
806 }
deadbeef0ed85b22016-02-23 17:24:52 -0800807 return true;
808 }
809
810 // Compares ufrag/password only for the specified |media_type|.
811 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
812 const cricket::SessionDescription* desc2,
813 cricket::MediaType media_type) {
814 if (desc1->contents().size() != desc2->contents().size()) {
815 return false;
816 }
817
818 const cricket::ContentInfo* cinfo =
819 cricket::GetFirstMediaContent(desc1->contents(), media_type);
820 const cricket::TransportDescription* transport_desc1 =
821 desc1->GetTransportDescriptionByName(cinfo->name);
822 const cricket::TransportDescription* transport_desc2 =
823 desc2->GetTransportDescriptionByName(cinfo->name);
824 if (!transport_desc1 || !transport_desc2) {
825 return false;
826 }
827 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
828 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
829 return false;
830 }
831 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000833
834 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
835 std::string *sdp) {
836 const cricket::SessionDescription* desc = current_desc->description();
837 EXPECT_TRUE(current_desc->ToString(sdp));
838
839 const cricket::ContentInfos& contents = desc->contents();
840 cricket::ContentInfos::const_iterator it = contents.begin();
841 // Replace ufrag and pwd lines with empty strings.
842 for (; it != contents.end(); ++it) {
843 const cricket::TransportDescription* transport_desc =
844 desc->GetTransportDescriptionByName(it->name);
845 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
846 + "\r\n";
847 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
848 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000849 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000850 "", 0,
851 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000852 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000853 "", 0,
854 sdp);
855 }
856 }
857
deadbeef0ed85b22016-02-23 17:24:52 -0800858 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
859 const std::string& ufrag,
860 const std::string& pwd) {
861 cricket::SessionDescription* desc = current_desc->description();
862 for (TransportInfo& transport_info : desc->transport_infos()) {
863 cricket::TransportDescription& transport_desc =
864 transport_info.description;
865 transport_desc.ice_ufrag = ufrag;
866 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000867 }
868 }
869
deadbeef0ed85b22016-02-23 17:24:52 -0800870 // Sets ufrag/pwd for specified |media_type|.
871 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
872 cricket::MediaType media_type,
873 const std::string& ufrag,
874 const std::string& pwd) {
875 cricket::SessionDescription* desc = current_desc->description();
876 const cricket::ContentInfo* cinfo =
877 cricket::GetFirstMediaContent(desc->contents(), media_type);
878 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
879 cricket::TransportDescription* transport_desc =
880 &transport_info->description;
881 transport_desc->ice_ufrag = ufrag;
882 transport_desc->ice_pwd = pwd;
883 }
884
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 // Creates a remote offer and and applies it as a remote description,
886 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700887 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 // to decide which local and remote streams to create.
889 void CreateAndSetRemoteOfferAndLocalAnswer() {
890 SessionDescriptionInterface* offer = CreateRemoteOffer();
891 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800892 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 SetLocalDescriptionWithoutError(answer);
894 }
895 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
896 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700897 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 }
899 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700900 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 SetLocalDescriptionWithoutError(desc);
902 EXPECT_EQ(expected_state, session_->state());
903 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000904 void SetLocalDescriptionExpectError(const std::string& action,
905 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 SessionDescriptionInterface* desc) {
907 std::string error;
908 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000909 std::string sdp_type = "local ";
910 sdp_type.append(action);
911 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_NE(std::string::npos, error.find(expected_error));
913 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000914 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
915 SessionDescriptionInterface* desc) {
916 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
917 expected_error, desc);
918 }
919 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
920 SessionDescriptionInterface* desc) {
921 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
922 expected_error, desc);
923 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
925 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
926 }
927 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700928 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 SetRemoteDescriptionWithoutError(desc);
930 EXPECT_EQ(expected_state, session_->state());
931 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000932 void SetRemoteDescriptionExpectError(const std::string& action,
933 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 SessionDescriptionInterface* desc) {
935 std::string error;
936 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000937 std::string sdp_type = "remote ";
938 sdp_type.append(action);
939 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 EXPECT_NE(std::string::npos, error.find(expected_error));
941 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000942 void SetRemoteDescriptionOfferExpectError(
943 const std::string& expected_error, SessionDescriptionInterface* desc) {
944 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
945 expected_error, desc);
946 }
947 void SetRemoteDescriptionPranswerExpectError(
948 const std::string& expected_error, SessionDescriptionInterface* desc) {
949 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
950 expected_error, desc);
951 }
952 void SetRemoteDescriptionAnswerExpectError(
953 const std::string& expected_error, SessionDescriptionInterface* desc) {
954 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
955 expected_error, desc);
956 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957
958 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
959 SessionDescriptionInterface** nocrypto_answer) {
960 // Create a SDP without Crypto.
961 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000962 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 options.bundle_enabled = true;
964 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
965 ASSERT_TRUE(*offer != NULL);
966 VerifyCryptoParams((*offer)->description());
967
968 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
969 cricket::SEC_DISABLED);
970 EXPECT_TRUE(*nocrypto_answer != NULL);
971 }
972
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000973 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
974 SessionDescriptionInterface** nodtls_answer) {
975 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000976 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000977 options.bundle_enabled = true;
978
kwibergd1fe2812016-04-27 06:47:29 -0700979 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000980 CreateRemoteOffer(options, cricket::SEC_ENABLED));
981
982 *nodtls_answer =
983 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
984 EXPECT_TRUE(*nodtls_answer != NULL);
985 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
986 VerifyCryptoParams((*nodtls_answer)->description());
987
988 SetFactoryDtlsSrtp();
989 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
990 ASSERT_TRUE(*offer != NULL);
991 VerifyFingerprintStatus((*offer)->description(), true);
992 VerifyCryptoParams((*offer)->description());
993 }
994
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 JsepSessionDescription* CreateRemoteOfferWithVersion(
996 cricket::MediaSessionOptions options,
997 cricket::SecurePolicy secure_policy,
998 const std::string& session_version,
999 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001000 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 const cricket::SessionDescription* cricket_desc = NULL;
1002 if (current_desc) {
1003 cricket_desc = current_desc->description();
1004 session_id = current_desc->session_id();
1005 }
1006
1007 desc_factory_->set_secure(secure_policy);
1008 JsepSessionDescription* offer(
1009 new JsepSessionDescription(JsepSessionDescription::kOffer));
1010 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1011 session_id, session_version)) {
1012 delete offer;
1013 offer = NULL;
1014 }
1015 return offer;
1016 }
1017 JsepSessionDescription* CreateRemoteOffer(
1018 cricket::MediaSessionOptions options) {
1019 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1020 kSessionVersion, NULL);
1021 }
1022 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001023 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1024 return CreateRemoteOfferWithVersion(
1025 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 }
1027 JsepSessionDescription* CreateRemoteOffer(
1028 cricket::MediaSessionOptions options,
1029 const SessionDescriptionInterface* current_desc) {
1030 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1031 kSessionVersion, current_desc);
1032 }
1033
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001034 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1035 const char* sctp_stream_name, int new_port,
1036 cricket::MediaSessionOptions options) {
1037 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001038 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1039 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001040 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1041 }
1042
1043 // Takes ownership of offer_basis (and deletes it).
1044 JsepSessionDescription* ChangeSDPSctpPort(
1045 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1046 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1047 // SessionDescription from the mutated string.
1048 const char* default_port_str = "5000";
1049 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001050 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001051 std::string offer_str;
1052 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001053 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001054 new_port_str, strlen(new_port_str),
1055 &offer_str);
1056 JsepSessionDescription* offer = new JsepSessionDescription(
1057 offer_basis->type());
1058 delete offer_basis;
1059 offer->Initialize(offer_str, NULL);
1060 return offer;
1061 }
1062
deadbeefab9b2d12015-10-14 11:33:11 -07001063 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // before this function to decide which streams to create.
1065 JsepSessionDescription* CreateRemoteOffer() {
1066 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001067 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 return CreateRemoteOffer(options, session_->remote_description());
1069 }
1070
1071 JsepSessionDescription* CreateRemoteAnswer(
1072 const SessionDescriptionInterface* offer,
1073 cricket::MediaSessionOptions options,
1074 cricket::SecurePolicy policy) {
1075 desc_factory_->set_secure(policy);
1076 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001077 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 JsepSessionDescription* answer(
1079 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1080 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1081 options, NULL),
1082 session_id, kSessionVersion)) {
1083 delete answer;
1084 answer = NULL;
1085 }
1086 return answer;
1087 }
1088
1089 JsepSessionDescription* CreateRemoteAnswer(
1090 const SessionDescriptionInterface* offer,
1091 cricket::MediaSessionOptions options) {
1092 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1093 }
1094
deadbeefab9b2d12015-10-14 11:33:11 -07001095 // Creates an answer session description.
1096 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 // to decide which streams to create.
1098 JsepSessionDescription* CreateRemoteAnswer(
1099 const SessionDescriptionInterface* offer) {
1100 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001101 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1103 }
1104
1105 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001106 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001107 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001108 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001109
1110 PeerConnectionInterface::RTCOfferAnswerOptions options;
1111 options.use_rtp_mux = bundle;
1112
1113 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1115 // and answer.
1116 SetLocalDescriptionWithoutError(offer);
1117
kwibergd1fe2812016-04-27 06:47:29 -07001118 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001119 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 std::string sdp;
1121 EXPECT_TRUE(answer->ToString(&sdp));
1122
1123 size_t expected_candidate_num = 2;
1124 if (!rtcp_mux) {
1125 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1126 // for rtp and rtcp.
1127 expected_candidate_num = 4;
1128 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 const std::string kRtcpMux = "a=rtcp-mux";
1130 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001131 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 kXRtcpMux.c_str(), kXRtcpMux.length(),
1133 &sdp);
1134 }
1135
1136 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1137 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138
1139 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001140 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1142 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001143 if (bundle) {
1144 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1145 } else {
1146 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 }
1148 }
1149 // Tests that we can only send DTMF when the dtmf codec is supported.
1150 void TestCanInsertDtmf(bool can) {
1151 if (can) {
1152 InitWithDtmfCodec();
1153 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001154 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 }
deadbeefab9b2d12015-10-14 11:33:11 -07001156 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 CreateAndSetRemoteOfferAndLocalAnswer();
1158 EXPECT_FALSE(session_->CanInsertDtmf(""));
1159 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1160 }
1161
zhihuang3a334652016-05-05 18:37:49 -07001162 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1163 const std::string& codec_name) {
1164 for (const auto& content : desc->description()->contents()) {
1165 if (static_cast<cricket::MediaContentDescription*>(content.description)
1166 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1167 const auto* mdesc =
1168 static_cast<cricket::VideoContentDescription*>(content.description);
1169 for (const auto& codec : mdesc->codecs()) {
1170 if (codec.name == codec_name) {
1171 return true;
1172 }
1173 }
1174 }
1175 }
1176 return false;
1177 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001178 // Helper class to configure loopback network and verify Best
1179 // Connection using right IP protocol for TestLoopbackCall
1180 // method. LoopbackNetworkManager applies firewall rules to block
1181 // all ping traffic once ICE completed, and remove them to observe
1182 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1183 // verifies the best connection is using the right IP protocol after
1184 // initial ICE convergences.
1185
1186 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001187 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001188 LoopbackNetworkConfiguration()
1189 : test_ipv6_network_(false),
1190 test_extra_ipv4_network_(false),
1191 best_connection_after_initial_ice_converged_(1, 0) {}
1192
1193 // Used to track the expected best connection count in each IP protocol.
1194 struct ExpectedBestConnection {
1195 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1196 : ipv4_count_(ipv4_count),
1197 ipv6_count_(ipv6_count) {}
1198
1199 int ipv4_count_;
1200 int ipv6_count_;
1201 };
1202
1203 bool test_ipv6_network_;
1204 bool test_extra_ipv4_network_;
1205 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1206
1207 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001208 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001209 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1210 }
1211
1212 private:
jbauchac8869e2015-07-03 01:36:14 -07001213 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001214 const ExpectedBestConnection& expected) const {
1215 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001216 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1217 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001218 expected.ipv4_count_);
1219 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001220 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1221 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001222 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001223 // This is used in the loopback call so there is only single host to host
1224 // candidate pair.
1225 EXPECT_EQ(metrics_observer->GetEnumCounter(
1226 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1227 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001228 0);
1229 EXPECT_EQ(metrics_observer->GetEnumCounter(
1230 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1231 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001232 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001233 }
1234 };
1235
1236 class LoopbackNetworkManager {
1237 public:
1238 LoopbackNetworkManager(WebRtcSessionTest* session,
1239 const LoopbackNetworkConfiguration& config)
1240 : config_(config) {
1241 session->AddInterface(
1242 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1243 if (config_.test_extra_ipv4_network_) {
1244 session->AddInterface(
1245 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1246 }
1247 if (config_.test_ipv6_network_) {
1248 session->AddInterface(
1249 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1250 }
1251 }
1252
1253 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1254 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1255 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1256 if (config_.test_extra_ipv4_network_) {
1257 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1258 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1259 }
1260 if (config_.test_ipv6_network_) {
1261 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1262 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1263 }
1264 }
1265
1266 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1267
1268 private:
1269 LoopbackNetworkConfiguration config_;
1270 };
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 // The method sets up a call from the session to itself, in a loopback
1273 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001274 // disconnection, and then a permanent disconnection.
1275 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1277 // While running the call, this method also checks if the session goes through
1278 // the correct sequence of ICE states when a connection is established,
1279 // broken, and re-established.
1280 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001281 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1282 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001284
stefanc1aeaf02015-10-15 07:26:07 -07001285 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001286 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001287 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001288 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289
1290 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1291 observer_.ice_gathering_state_);
1292 SetLocalDescriptionWithoutError(offer);
1293 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1294 observer_.ice_connection_state_);
1295 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001296 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1298 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001299 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300
1301 std::string sdp;
1302 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001303 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1304 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 ASSERT_TRUE(desc != NULL);
1306 SetRemoteDescriptionWithoutError(desc);
1307
1308 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001309 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001310
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001311 // The ice connection state is "Connected" too briefly to catch in a test.
1312 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001313 observer_.ice_connection_state_, kIceCandidatesTimeout);
1314 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315
stefanc1aeaf02015-10-15 07:26:07 -07001316 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1317 LoopbackNetworkManager loopback_network_manager(this, config);
1318 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001319 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 // Adding firewall rule to block ping requests, which should cause
1321 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001322
1323 loopback_network_manager.ApplyFirewallRules(fss_.get());
1324
1325 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1327 observer_.ice_connection_state_,
1328 kIceCandidatesTimeout);
1329
jbauchac8869e2015-07-03 01:36:14 -07001330 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001333 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001335 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001336 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337 observer_.ice_connection_state_,
1338 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001339
1340 // Now we block ping requests and wait until the ICE connection transitions
1341 // to the Failed state. This will take at least 30 seconds because it must
1342 // wait for the Port to timeout.
1343 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001344
1345 loopback_network_manager.ApplyFirewallRules(fss_.get());
1346 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001347 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001348 observer_.ice_connection_state_,
1349 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 }
1351
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001352 void TestLoopbackCall() {
1353 LoopbackNetworkConfiguration config;
1354 TestLoopbackCall(config);
1355 }
1356
stefanc1aeaf02015-10-15 07:26:07 -07001357 void TestPacketOptions() {
1358 media_controller_.reset(
1359 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1360 LoopbackNetworkConfiguration config;
1361 LoopbackNetworkManager loopback_network_manager(this, config);
1362
1363 SetupLoopbackCall();
1364
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001365 // Wait for channel to be ready for sending.
1366 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001367 uint8_t test_packet[15] = {0};
1368 rtc::PacketOptions options;
1369 options.packet_id = 10;
1370 media_engine_->GetVideoChannel(0)
1371 ->SendRtp(test_packet, sizeof(test_packet), options);
1372
1373 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001374 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1375 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001376 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1377 }
1378
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1380 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001381 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1382 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001383
1384 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001385 std::vector<cricket::AudioCodec> codecs =
1386 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 codecs.push_back(kCNCodec1);
1388 codecs.push_back(kCNCodec2);
1389 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001390 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 }
1392
1393 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1394 const cricket::ContentDescription* description = content->description;
1395 ASSERT(description != NULL);
1396 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001397 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 ASSERT(audio_content_desc != NULL);
1399 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1400 if (audio_content_desc->codecs()[i].name == "CN")
1401 return false;
1402 }
1403 return true;
1404 }
1405
deadbeefab9b2d12015-10-14 11:33:11 -07001406 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001407 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001408 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001409 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1410 data_channel_ = DataChannel::Create(
1411 session_.get(), session_->data_channel_type(), "datachannel", dci);
1412 }
1413
1414 void SetLocalDescriptionWithDataChannel() {
1415 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001416 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 SetLocalDescriptionWithoutError(offer);
1418 }
1419
wu@webrtc.org91053e72013-08-10 07:18:04 +00001420 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001421 RTCCertificateGenerationMethod cert_gen_method,
1422 CreateSessionDescriptionRequest::Type type) {
1423 InitWithDtls(cert_gen_method);
1424 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1425 }
1426
1427 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1428 CreateSessionDescriptionRequest::Type type) {
1429 InitWithDtlsIdentityGenFail();
1430 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1431 }
1432
1433 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001434 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001435 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001436 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001437 if (type == CreateSessionDescriptionRequest::kAnswer) {
1438 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001439 std::unique_ptr<JsepSessionDescription> offer(
1440 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001441 ASSERT_TRUE(offer.get() != NULL);
1442 SetRemoteDescriptionWithoutError(offer.release());
1443 }
1444
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001445 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001446 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001447 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001448 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001449 observers[kNumber];
1450 for (int i = 0; i < kNumber; ++i) {
1451 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1452 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001453 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001454 } else {
htaa2a49d92016-03-04 02:51:39 -08001455 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001456 }
1457 }
1458
1459 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1460 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1461 WebRtcSessionCreateSDPObserverForTest::kFailed;
1462
1463 for (int i = 0; i < kNumber; ++i) {
1464 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1465 if (success) {
1466 EXPECT_TRUE(observers[i]->description() != NULL);
1467 } else {
1468 EXPECT_TRUE(observers[i]->description() == NULL);
1469 }
1470 }
1471 }
1472
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001473 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001474 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001475 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001476 turn_server.credentials = credentials;
1477 turn_server.ports.push_back(
1478 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1479 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001480 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001481 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001482 }
1483
skvlad11a9cbf2016-10-07 11:53:05 -07001484 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 cricket::FakeMediaEngine* media_engine_;
1486 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001487 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001488 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001489 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1490 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1491 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1492 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1493 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1494 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001495 rtc::SocketServerScope ss_scope_;
1496 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001497 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001498 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001499 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001500 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001501 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001502 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001503 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 MockIceObserver observer_;
1505 cricket::FakeVideoMediaChannel* video_channel_;
1506 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001507 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001508 // The following flags affect options created for CreateOffer/CreateAnswer.
1509 bool send_stream_1_ = false;
1510 bool send_stream_2_ = false;
1511 bool send_audio_ = false;
1512 bool send_video_ = false;
1513 rtc::scoped_refptr<DataChannel> data_channel_;
1514 // Last values received from data channel creation signal.
1515 std::string last_data_channel_label_;
1516 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001517 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001518 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519};
1520
Henrik Boström87713d02015-08-25 09:53:21 +02001521TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1522 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001523 // SDES is disabled when DTLS is on.
1524 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525}
1526
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001527TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001528 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001529 // SDES is required if DTLS is off.
1530 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001531}
1532
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1534 TestSessionCandidatesWithBundleRtcpMux(false, false);
1535}
1536
1537// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1538// with rtcp-mux and/or bundle.
1539TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1540 TestSessionCandidatesWithBundleRtcpMux(false, true);
1541}
1542
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1544 TestSessionCandidatesWithBundleRtcpMux(true, true);
1545}
1546
1547TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001548 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1549 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001550 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001551 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 InitiateCall();
1553 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1554 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1555 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1556}
1557
deadbeeff5f03e82016-06-06 11:16:06 -07001558TEST_F(WebRtcSessionTest, TestStunError) {
1559 rtc::ScopedFakeClock clock;
1560
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001561 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1562 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001563 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001564 rtc::FP_UDP,
1565 rtc::FD_ANY,
1566 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001567 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001568 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001570 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001571 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1573 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001574 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1575 // warning.
1576 session_->Close();
1577 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578}
1579
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001580TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001581 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001582 SessionDescriptionInterface* offer = NULL;
1583 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1584 std::string unknown_action;
1585 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1586 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1587}
1588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589// Test creating offers and receive answers and make sure the
1590// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001592 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001593 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001594 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 const std::string session_id_orig = offer->session_id();
1596 const std::string session_version_orig = offer->session_version();
1597 SetLocalDescriptionWithoutError(offer);
1598
deadbeefab9b2d12015-10-14 11:33:11 -07001599 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 SessionDescriptionInterface* answer =
1601 CreateRemoteAnswer(session_->local_description());
1602 SetRemoteDescriptionWithoutError(answer);
1603
1604 video_channel_ = media_engine_->GetVideoChannel(0);
1605 voice_channel_ = media_engine_->GetVoiceChannel(0);
1606
1607 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1608 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1609
1610 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1611 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1612
1613 ASSERT_EQ(1u, video_channel_->send_streams().size());
1614 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1615 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1616 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1617
1618 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001619 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001620 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621
1622 // Verify the session id is the same and the session version is
1623 // increased.
1624 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001625 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1626 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
1628 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001629 EXPECT_EQ(0u, video_channel_->send_streams().size());
1630 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631
deadbeefab9b2d12015-10-14 11:33:11 -07001632 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 answer = CreateRemoteAnswer(session_->local_description());
1634 SetRemoteDescriptionWithoutError(answer);
1635
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 // Make sure the receive streams have not changed.
1637 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1638 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1639 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1640 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1641}
1642
1643// Test receiving offers and creating answers and make sure the
1644// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001645TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001646 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001647 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001648 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001649 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 SetRemoteDescriptionWithoutError(offer);
1651
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001653 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001654 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 SetLocalDescriptionWithoutError(answer);
1656
1657 const std::string session_id_orig = answer->session_id();
1658 const std::string session_version_orig = answer->session_version();
1659
1660 video_channel_ = media_engine_->GetVideoChannel(0);
1661 voice_channel_ = media_engine_->GetVoiceChannel(0);
1662
htaa2a49d92016-03-04 02:51:39 -08001663 ASSERT_TRUE(video_channel_);
1664 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1666 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1667
1668 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1669 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1670
1671 ASSERT_EQ(1u, video_channel_->send_streams().size());
1672 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1673 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1674 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1675
deadbeefab9b2d12015-10-14 11:33:11 -07001676 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001677 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 SetRemoteDescriptionWithoutError(offer);
1679
1680 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001681 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001682 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683
1684 // Verify the session id is the same and the session version is
1685 // increased.
1686 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001687 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1688 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 SetLocalDescriptionWithoutError(answer);
1690
1691 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1692 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1693 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1694 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1695 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1696 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1697
1698 // Make sure we have no send streams.
1699 EXPECT_EQ(0u, video_channel_->send_streams().size());
1700 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1701}
1702
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001703TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001704 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001705 media_engine_->set_fail_create_channel(true);
1706
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001707 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001708 ASSERT_TRUE(offer != NULL);
1709 // SetRemoteDescription and SetLocalDescription will take the ownership of
1710 // the offer.
1711 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001712 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001713 ASSERT_TRUE(offer != NULL);
1714 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1715}
1716
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001717//
1718// Tests for creating/setting SDP under different SDES/DTLS polices:
1719//
1720// --DTLS off and SDES on
1721// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1722// set local/remote offer/answer with crypto --> success
1723// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1724// failure
1725// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1726// failure
1727// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1728// failure
1729//
1730// --DTLS on and SDES off
1731// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1732// set local/remote offer/answer with DTLS fingerprint --> success
1733// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1734// fingerprint --> failure
1735// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1736// --> failure
1737// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1738// --> failure
1739//
1740// --Encryption disabled: DTLS off and SDES off
1741// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1742// answer without SDES or DTLS --> success
1743// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1744// answer without SDES or DTLS --> success
1745//
1746
1747// Test that we return a failure when applying a remote/local offer that doesn't
1748// have cryptos enabled when DTLS is off.
1749TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001750 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001752 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 JsepSessionDescription* offer = CreateRemoteOffer(
1754 options, cricket::SEC_DISABLED);
1755 ASSERT_TRUE(offer != NULL);
1756 VerifyNoCryptoParams(offer->description(), false);
1757 // SetRemoteDescription and SetLocalDescription will take the ownership of
1758 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001759 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1761 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001762 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763}
1764
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765// Test that we return a failure when applying a local answer that doesn't have
1766// cryptos enabled when DTLS is off.
1767TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001768 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 SessionDescriptionInterface* offer = NULL;
1770 SessionDescriptionInterface* answer = NULL;
1771 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1772 // SetRemoteDescription and SetLocalDescription will take the ownership of
1773 // the offer.
1774 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001775 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776}
1777
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778// Test we will return fail when apply an remote answer that doesn't have
1779// crypto enabled when DTLS is off.
1780TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 SessionDescriptionInterface* offer = NULL;
1783 SessionDescriptionInterface* answer = NULL;
1784 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1785 // SetRemoteDescription and SetLocalDescription will take the ownership of
1786 // the offer.
1787 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789}
1790
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1792// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001793TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001794 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001795 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001796 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 SetFactoryDtlsSrtp();
1798 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001799 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001800 JsepSessionDescription* offer =
1801 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 ASSERT_TRUE(offer != NULL);
1803 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805
1806 // SetRemoteDescription will take the ownership of the offer.
1807 SetRemoteDescriptionWithoutError(offer);
1808
1809 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001810 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 ASSERT_TRUE(answer != NULL);
1812 VerifyFingerprintStatus(answer->description(), true);
1813 // Check that we don't have an a=crypto line in the answer.
1814 VerifyNoCryptoParams(answer->description(), true);
1815
1816 // Now set the local description, which should work, even without a=crypto.
1817 SetLocalDescriptionWithoutError(answer);
1818}
1819
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001820// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1821// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001822TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001823 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001824 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001825 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001826 SetFactoryDtlsSrtp();
1827
1828 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001829 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 ASSERT_TRUE(offer != NULL);
1831 VerifyFingerprintStatus(offer->description(), true);
1832 // Check that we don't have an a=crypto line in the offer.
1833 VerifyNoCryptoParams(offer->description(), true);
1834
1835 // Now set the local description, which should work, even without a=crypto.
1836 SetLocalDescriptionWithoutError(offer);
1837
1838 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001839 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840 JsepSessionDescription* answer =
1841 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1842 ASSERT_TRUE(answer != NULL);
1843 VerifyFingerprintStatus(answer->description(), true);
1844 VerifyNoCryptoParams(answer->description(), true);
1845
1846 // SetRemoteDescription will take the ownership of the answer.
1847 SetRemoteDescriptionWithoutError(answer);
1848}
1849
1850// Test that if we support DTLS and the other side didn't offer a fingerprint,
1851// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001852TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001853 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001854 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001856 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001857 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 JsepSessionDescription* offer = CreateRemoteOffer(
1859 options, cricket::SEC_REQUIRED);
1860 ASSERT_TRUE(offer != NULL);
1861 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 // SetRemoteDescription will take the ownership of the offer.
1865 SetRemoteDescriptionOfferExpectError(
1866 kSdpWithoutDtlsFingerprint, offer);
1867
1868 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1869 // SetLocalDescription will take the ownership of the offer.
1870 SetLocalDescriptionOfferExpectError(
1871 kSdpWithoutDtlsFingerprint, offer);
1872}
1873
1874// Test that we return a failure when applying a local answer that doesn't have
1875// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001876TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001877 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001878 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879 SessionDescriptionInterface* offer = NULL;
1880 SessionDescriptionInterface* answer = NULL;
1881 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1882
1883 // SetRemoteDescription and SetLocalDescription will take the ownership of
1884 // the offer and answer.
1885 SetRemoteDescriptionWithoutError(offer);
1886 SetLocalDescriptionAnswerExpectError(
1887 kSdpWithoutDtlsFingerprint, answer);
1888}
1889
1890// Test that we return a failure when applying a remote answer that doesn't have
1891// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001892TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001893 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001894 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001895 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001897 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001898 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001899 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001901 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001902
1903 // SetRemoteDescription and SetLocalDescription will take the ownership of
1904 // the offer and answer.
1905 SetLocalDescriptionWithoutError(offer);
1906 SetRemoteDescriptionAnswerExpectError(
1907 kSdpWithoutDtlsFingerprint, answer);
1908}
1909
1910// Test that we create a local offer without SDES or DTLS and accept a remote
1911// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001912TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001913 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001915 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916
1917 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001918 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919 ASSERT_TRUE(offer != NULL);
1920 VerifyFingerprintStatus(offer->description(), false);
1921 // Check that we don't have an a=crypto line in the offer.
1922 VerifyNoCryptoParams(offer->description(), false);
1923
1924 // Now set the local description, which should work, even without a=crypto.
1925 SetLocalDescriptionWithoutError(offer);
1926
1927 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001928 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001929 JsepSessionDescription* answer =
1930 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1931 ASSERT_TRUE(answer != NULL);
1932 VerifyFingerprintStatus(answer->description(), false);
1933 VerifyNoCryptoParams(answer->description(), false);
1934
1935 // SetRemoteDescription will take the ownership of the answer.
1936 SetRemoteDescriptionWithoutError(answer);
1937}
1938
1939// Test that we create a local answer without SDES or DTLS and accept a remote
1940// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001941TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001942 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001943 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001944
1945 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001946 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001947 JsepSessionDescription* offer =
1948 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1949 ASSERT_TRUE(offer != NULL);
1950 VerifyFingerprintStatus(offer->description(), false);
1951 VerifyNoCryptoParams(offer->description(), false);
1952
1953 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 SetRemoteDescriptionWithoutError(offer);
1955
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001956 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001957 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 ASSERT_TRUE(answer != NULL);
1959 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001960 // Check that we don't have an a=crypto line in the answer.
1961 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 SetLocalDescriptionWithoutError(answer);
1965}
1966
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001967// Test that we can create and set an answer correctly when different
1968// SSL roles have been negotiated for different transports.
1969// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1970TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1971 SendAudioVideoStream1();
1972 InitWithDtls(GetParam());
1973 SetFactoryDtlsSrtp();
1974
1975 SessionDescriptionInterface* offer = CreateOffer();
1976 SetLocalDescriptionWithoutError(offer);
1977
1978 cricket::MediaSessionOptions options;
1979 options.recv_video = true;
1980
1981 // First, negotiate different SSL roles.
1982 SessionDescriptionInterface* answer =
1983 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1984 TransportInfo* audio_transport_info =
1985 answer->description()->GetTransportInfoByName("audio");
1986 audio_transport_info->description.connection_role =
1987 cricket::CONNECTIONROLE_ACTIVE;
1988 TransportInfo* video_transport_info =
1989 answer->description()->GetTransportInfoByName("video");
1990 video_transport_info->description.connection_role =
1991 cricket::CONNECTIONROLE_PASSIVE;
1992 SetRemoteDescriptionWithoutError(answer);
1993
1994 // Now create an offer in the reverse direction, and ensure the initial
1995 // offerer responds with an answer with correct SSL roles.
1996 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1997 kSessionVersion,
1998 session_->remote_description());
1999 SetRemoteDescriptionWithoutError(offer);
2000
htaa2a49d92016-03-04 02:51:39 -08002001 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002002 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2003 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2004 audio_transport_info->description.connection_role);
2005 video_transport_info = answer->description()->GetTransportInfoByName("video");
2006 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2007 video_transport_info->description.connection_role);
2008 SetLocalDescriptionWithoutError(answer);
2009
2010 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2011 // audio is transferred over to video in the answer that completes the BUNDLE
2012 // negotiation.
2013 options.bundle_enabled = true;
2014 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2015 kSessionVersion,
2016 session_->remote_description());
2017 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002018 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002019 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2020 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2021 audio_transport_info->description.connection_role);
2022 video_transport_info = answer->description()->GetTransportInfoByName("video");
2023 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2024 video_transport_info->description.connection_role);
2025 SetLocalDescriptionWithoutError(answer);
2026}
2027
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002029 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002030 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002032 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033 SetLocalDescriptionWithoutError(offer);
2034
2035 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002036 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 SetLocalDescriptionWithoutError(offer2);
2038}
2039
2040TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002041 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002042 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002044 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 SetRemoteDescriptionWithoutError(offer);
2046
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 SetRemoteDescriptionWithoutError(offer2);
2049}
2050
2051TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002052 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002053 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002054 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002057 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2058 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059}
2060
2061TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002062 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002063 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002064 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002067 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002068 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069}
2070
2071TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002072 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002075 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076
htaa2a49d92016-03-04 02:51:39 -08002077 JsepSessionDescription* pranswer =
2078 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002080 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081
deadbeefab9b2d12015-10-14 11:33:11 -07002082 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002083 JsepSessionDescription* pranswer2 =
2084 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2086
deadbeefd59daf82015-10-14 15:02:44 -07002087 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002090 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002091 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092}
2093
2094TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002095 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002096 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002097 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002098 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
2100 JsepSessionDescription* pranswer =
2101 CreateRemoteAnswer(session_->local_description());
2102 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2103
2104 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002105 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106
deadbeefab9b2d12015-10-14 11:33:11 -07002107 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 JsepSessionDescription* pranswer2 =
2109 CreateRemoteAnswer(session_->local_description());
2110 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2111
2112 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002113 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
deadbeefab9b2d12015-10-14 11:33:11 -07002115 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 SessionDescriptionInterface* answer =
2117 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002118 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119}
2120
2121TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002122 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002123 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002124 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 SessionDescriptionInterface* answer =
2127 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002128 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2129 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130}
2131
2132TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002133 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002134 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002135 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 SessionDescriptionInterface* answer =
2138 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002139 SetRemoteDescriptionAnswerExpectError(
2140 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141}
2142
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002143// Tests that the remote candidates are added and removed successfully.
2144TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002145 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002146 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002148 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2149 "", "", "host", 0, "");
2150 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2152
deadbeefd59daf82015-10-14 15:02:44 -07002153 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2155
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002158
2159 // Fail since we have not set a remote description.
2160 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161
2162 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2163 session_->local_description());
2164 SetRemoteDescriptionWithoutError(answer);
2165
deadbeefd59daf82015-10-14 15:02:44 -07002166 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2167 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002168 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002169 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2170 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2171
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 // Verifying the candidates are copied properly from internal vector.
2173 const SessionDescriptionInterface* remote_desc =
2174 session_->remote_description();
2175 ASSERT_TRUE(remote_desc != NULL);
2176 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2177 const IceCandidateCollection* candidates =
2178 remote_desc->candidates(kMediaContentIndex0);
2179 ASSERT_EQ(2u, candidates->count());
2180 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2181 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2182 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2183 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2184
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002185 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2186 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 candidate.set_component(2);
2188 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2189 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002190 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191
2192 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2193 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002194
2195 // Remove candidate1 and candidate2
2196 std::vector<cricket::Candidate> remote_candidates;
2197 remote_candidates.push_back(ice_candidate1.candidate());
2198 remote_candidates.push_back(ice_candidate2.candidate());
2199 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2200 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201}
2202
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002203// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204// that it is retained if the remote session description is changed.
2205TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002206 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 cricket::Candidate candidate1;
2208 candidate1.set_component(1);
2209 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2210 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002211 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 CreateAndSetRemoteOfferAndLocalAnswer();
2213
2214 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2215 const SessionDescriptionInterface* remote_desc =
2216 session_->remote_description();
2217 ASSERT_TRUE(remote_desc != NULL);
2218 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2219 const IceCandidateCollection* candidates =
2220 remote_desc->candidates(kMediaContentIndex0);
2221 ASSERT_EQ(1u, candidates->count());
2222 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2223
2224 // Update the RemoteSessionDescription with a new session description and
2225 // a candidate and check that the new remote session description contains both
2226 // candidates.
2227 SessionDescriptionInterface* offer = CreateRemoteOffer();
2228 cricket::Candidate candidate2;
2229 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2230 candidate2);
2231 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2232 SetRemoteDescriptionWithoutError(offer);
2233
2234 remote_desc = session_->remote_description();
2235 ASSERT_TRUE(remote_desc != NULL);
2236 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2237 candidates = remote_desc->candidates(kMediaContentIndex0);
2238 ASSERT_EQ(2u, candidates->count());
2239 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2240 // Username and password have be updated with the TransportInfo of the
2241 // SessionDescription, won't be equal to the original one.
2242 candidate2.set_username(candidates->at(0)->candidate().username());
2243 candidate2.set_password(candidates->at(0)->candidate().password());
2244 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2245 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2246 // No need to verify the username and password.
2247 candidate1.set_username(candidates->at(1)->candidate().username());
2248 candidate1.set_password(candidates->at(1)->candidate().password());
2249 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2250
2251 // Test that the candidate is ignored if we can add the same candidate again.
2252 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2253}
2254
2255// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002256// that they are retained if the local session description is changed. And if
2257// continual gathering is enabled, they are removed from the local session
2258// description when the network is down.
2259TEST_F(WebRtcSessionTest,
2260 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002262 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002263 // Enable Continual Gathering.
2264 cricket::IceConfig config;
2265 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2266 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002267 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 CreateAndSetRemoteOfferAndLocalAnswer();
2269
2270 const SessionDescriptionInterface* local_desc = session_->local_description();
2271 const IceCandidateCollection* candidates =
2272 local_desc->candidates(kMediaContentIndex0);
2273 ASSERT_TRUE(candidates != NULL);
2274 EXPECT_EQ(0u, candidates->count());
2275
deadbeefb60a8192016-08-24 15:15:00 -07002276 // Since we're using continual gathering, we won't get "gathering done".
2277 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278
2279 local_desc = session_->local_description();
2280 candidates = local_desc->candidates(kMediaContentIndex0);
2281 ASSERT_TRUE(candidates != NULL);
2282 EXPECT_LT(0u, candidates->count());
2283 candidates = local_desc->candidates(1);
2284 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002285 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286
2287 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002288 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 CreateAndSetRemoteOfferAndLocalAnswer();
2290
2291 local_desc = session_->local_description();
2292 candidates = local_desc->candidates(kMediaContentIndex0);
2293 ASSERT_TRUE(candidates != NULL);
2294 EXPECT_LT(0u, candidates->count());
2295 candidates = local_desc->candidates(1);
2296 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002297 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002298
2299 candidates = local_desc->candidates(kMediaContentIndex0);
2300 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002301 // Bring down the network interface to trigger candidate removals.
2302 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2303 // Verify that all local candidates are removed.
2304 EXPECT_EQ(0, observer_.num_candidates_removed_);
2305 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2306 kIceCandidatesTimeout);
2307 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2308}
2309
2310// Tests that if continual gathering is disabled, local candidates won't be
2311// removed when the interface is turned down.
2312TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2313 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2314 Init();
2315 SendAudioVideoStream1();
2316 CreateAndSetRemoteOfferAndLocalAnswer();
2317
2318 const SessionDescriptionInterface* local_desc = session_->local_description();
2319 const IceCandidateCollection* candidates =
2320 local_desc->candidates(kMediaContentIndex0);
2321 ASSERT_TRUE(candidates != NULL);
2322 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2323
2324 size_t num_local_candidates = candidates->count();
2325 EXPECT_LT(0u, num_local_candidates);
2326 // By default, Continual Gathering is disabled.
2327 // Bring down the network interface.
2328 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2329 // Verify that the local candidates are not removed.
2330 rtc::Thread::Current()->ProcessMessages(1000);
2331 EXPECT_EQ(0, observer_.num_candidates_removed_);
2332 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333}
2334
2335// Test that we can set a remote session description with remote candidates.
2336TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002337 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338
2339 cricket::Candidate candidate1;
2340 candidate1.set_component(1);
2341 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2342 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002343 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002344 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345
2346 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2347 SetRemoteDescriptionWithoutError(offer);
2348
2349 const SessionDescriptionInterface* remote_desc =
2350 session_->remote_description();
2351 ASSERT_TRUE(remote_desc != NULL);
2352 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2353 const IceCandidateCollection* candidates =
2354 remote_desc->candidates(kMediaContentIndex0);
2355 ASSERT_EQ(1u, candidates->count());
2356 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2357
htaa2a49d92016-03-04 02:51:39 -08002358 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 SetLocalDescriptionWithoutError(answer);
2360}
2361
2362// Test that offers and answers contains ice candidates when Ice candidates have
2363// been gathered.
2364TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002365 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002366 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002367 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 // Ice is started but candidates are not provided until SetLocalDescription
2369 // is called.
2370 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2371 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2372 CreateAndSetRemoteOfferAndLocalAnswer();
2373 // Wait until at least one local candidate has been collected.
2374 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2375 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376
kwibergd1fe2812016-04-27 06:47:29 -07002377 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002378
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2380 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381
2382 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2383 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002384 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2386 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 SetLocalDescriptionWithoutError(answer);
2388}
2389
2390// Verifies TransportProxy and media channels are created with content names
2391// present in the SessionDescription.
2392TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002393 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002394 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002395 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396
2397 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002398 // "video". Goal is to modify these content names and verify transport
2399 // channels
2400 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 // present in SDP.
2402 std::string sdp;
2403 EXPECT_TRUE(offer->ToString(&sdp));
2404 const std::string kAudioMid = "a=mid:audio";
2405 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2406 const std::string kVideoMid = "a=mid:video";
2407 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2408
2409 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002410 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 kAudioMidReplaceStr.c_str(),
2412 kAudioMidReplaceStr.length(),
2413 &sdp);
2414 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002415 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 kVideoMidReplaceStr.c_str(),
2417 kVideoMidReplaceStr.length(),
2418 &sdp);
2419
2420 SessionDescriptionInterface* modified_offer =
2421 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2422
2423 SetRemoteDescriptionWithoutError(modified_offer);
2424
htaa2a49d92016-03-04 02:51:39 -08002425 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 SetLocalDescriptionWithoutError(answer);
2427
deadbeefcbecd352015-09-23 11:50:27 -07002428 cricket::TransportChannel* voice_transport_channel =
2429 session_->voice_rtp_transport_channel();
2430 EXPECT_TRUE(voice_transport_channel != NULL);
2431 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2432 cricket::TransportChannel* video_transport_channel =
2433 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002434 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002435 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2437 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2438}
2439
2440// Test that an offer contains the correct media content descriptions based on
2441// the send streams when no constraints have been set.
2442TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002443 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002444 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002445
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 ASSERT_TRUE(offer != NULL);
2447 const cricket::ContentInfo* content =
2448 cricket::GetFirstAudioContent(offer->description());
2449 EXPECT_TRUE(content != NULL);
2450 content = cricket::GetFirstVideoContent(offer->description());
2451 EXPECT_TRUE(content == NULL);
2452}
2453
2454// Test that an offer contains the correct media content descriptions based on
2455// the send streams when no constraints have been set.
2456TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002457 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002459 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002460 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002461
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 const cricket::ContentInfo* content =
2463 cricket::GetFirstAudioContent(offer->description());
2464 EXPECT_TRUE(content != NULL);
2465 content = cricket::GetFirstVideoContent(offer->description());
2466 EXPECT_TRUE(content == NULL);
2467
2468 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002469 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 content = cricket::GetFirstAudioContent(offer->description());
2472 EXPECT_TRUE(content != NULL);
2473 content = cricket::GetFirstVideoContent(offer->description());
2474 EXPECT_TRUE(content != NULL);
2475}
2476
2477// Test that an offer contains no media content descriptions if
2478// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2479TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002480 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002481 PeerConnectionInterface::RTCOfferAnswerOptions options;
2482 options.offer_to_receive_audio = 0;
2483 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484
kwibergd1fe2812016-04-27 06:47:29 -07002485 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002486
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 ASSERT_TRUE(offer != NULL);
2488 const cricket::ContentInfo* content =
2489 cricket::GetFirstAudioContent(offer->description());
2490 EXPECT_TRUE(content == NULL);
2491 content = cricket::GetFirstVideoContent(offer->description());
2492 EXPECT_TRUE(content == NULL);
2493}
2494
2495// Test that an offer contains only audio media content descriptions if
2496// kOfferToReceiveAudio constraints are set to true.
2497TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002498 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002499 PeerConnectionInterface::RTCOfferAnswerOptions options;
2500 options.offer_to_receive_audio =
2501 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2502
kwibergd1fe2812016-04-27 06:47:29 -07002503 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504
2505 const cricket::ContentInfo* content =
2506 cricket::GetFirstAudioContent(offer->description());
2507 EXPECT_TRUE(content != NULL);
2508 content = cricket::GetFirstVideoContent(offer->description());
2509 EXPECT_TRUE(content == NULL);
2510}
2511
2512// Test that an offer contains audio and video media content descriptions if
2513// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2514TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002515 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002517 PeerConnectionInterface::RTCOfferAnswerOptions options;
2518 options.offer_to_receive_audio =
2519 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2520 options.offer_to_receive_video =
2521 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2522
kwibergd1fe2812016-04-27 06:47:29 -07002523 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002527 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002528
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 content = cricket::GetFirstVideoContent(offer->description());
2530 EXPECT_TRUE(content != NULL);
2531
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002532 // Sets constraints to false and verifies that audio/video contents are
2533 // removed.
2534 options.offer_to_receive_audio = 0;
2535 options.offer_to_receive_video = 0;
2536 offer.reset(CreateOffer(options));
2537
2538 content = cricket::GetFirstAudioContent(offer->description());
2539 EXPECT_TRUE(content == NULL);
2540 content = cricket::GetFirstVideoContent(offer->description());
2541 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542}
2543
2544// Test that an answer can not be created if the last remote description is not
2545// an offer.
2546TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002547 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002548 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 SetLocalDescriptionWithoutError(offer);
2550 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2551 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002552 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553}
2554
2555// Test that an answer contains the correct media content descriptions when no
2556// constraints have been set.
2557TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002558 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002560 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002562 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563 const cricket::ContentInfo* content =
2564 cricket::GetFirstAudioContent(answer->description());
2565 ASSERT_TRUE(content != NULL);
2566 EXPECT_FALSE(content->rejected);
2567
2568 content = cricket::GetFirstVideoContent(answer->description());
2569 ASSERT_TRUE(content != NULL);
2570 EXPECT_FALSE(content->rejected);
2571}
2572
2573// Test that an answer contains the correct media content descriptions when no
2574// constraints have been set and the offer only contain audio.
2575TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002576 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 // Create a remote offer with audio only.
2578 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002579
kwibergd1fe2812016-04-27 06:47:29 -07002580 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2582 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2583
2584 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002585 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 const cricket::ContentInfo* content =
2587 cricket::GetFirstAudioContent(answer->description());
2588 ASSERT_TRUE(content != NULL);
2589 EXPECT_FALSE(content->rejected);
2590
2591 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2592}
2593
2594// Test that an answer contains the correct media content descriptions when no
2595// constraints have been set.
2596TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002597 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002599 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 SetRemoteDescriptionWithoutError(offer.release());
2601 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002602 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002603 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 const cricket::ContentInfo* content =
2605 cricket::GetFirstAudioContent(answer->description());
2606 ASSERT_TRUE(content != NULL);
2607 EXPECT_FALSE(content->rejected);
2608
2609 content = cricket::GetFirstVideoContent(answer->description());
2610 ASSERT_TRUE(content != NULL);
2611 EXPECT_FALSE(content->rejected);
2612}
2613
2614// Test that an answer contains the correct media content descriptions when
2615// constraints have been set but no stream is sent.
2616TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002617 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002619 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 SetRemoteDescriptionWithoutError(offer.release());
2621
htaa2a49d92016-03-04 02:51:39 -08002622 cricket::MediaSessionOptions session_options;
2623 session_options.recv_audio = false;
2624 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002625 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002626 CreateAnswer(session_options));
2627
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 const cricket::ContentInfo* content =
2629 cricket::GetFirstAudioContent(answer->description());
2630 ASSERT_TRUE(content != NULL);
2631 EXPECT_TRUE(content->rejected);
2632
2633 content = cricket::GetFirstVideoContent(answer->description());
2634 ASSERT_TRUE(content != NULL);
2635 EXPECT_TRUE(content->rejected);
2636}
2637
2638// Test that an answer contains the correct media content descriptions when
2639// constraints have been set and streams are sent.
2640TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002641 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002643 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 SetRemoteDescriptionWithoutError(offer.release());
2645
htaa2a49d92016-03-04 02:51:39 -08002646 cricket::MediaSessionOptions options;
2647 options.recv_audio = false;
2648 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649
2650 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002651 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002652 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653
2654 // TODO(perkj): Should the direction be set to SEND_ONLY?
2655 const cricket::ContentInfo* content =
2656 cricket::GetFirstAudioContent(answer->description());
2657 ASSERT_TRUE(content != NULL);
2658 EXPECT_FALSE(content->rejected);
2659
2660 // TODO(perkj): Should the direction be set to SEND_ONLY?
2661 content = cricket::GetFirstVideoContent(answer->description());
2662 ASSERT_TRUE(content != NULL);
2663 EXPECT_FALSE(content->rejected);
2664}
2665
2666TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2667 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002668 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002669 PeerConnectionInterface::RTCOfferAnswerOptions options;
2670 options.offer_to_receive_audio =
2671 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2672 options.voice_activity_detection = false;
2673
kwibergd1fe2812016-04-27 06:47:29 -07002674 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002675
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 const cricket::ContentInfo* content =
2677 cricket::GetFirstAudioContent(offer->description());
2678 EXPECT_TRUE(content != NULL);
2679 EXPECT_TRUE(VerifyNoCNCodecs(content));
2680}
2681
2682TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2683 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002684 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002686 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 SetRemoteDescriptionWithoutError(offer.release());
2688
htaa2a49d92016-03-04 02:51:39 -08002689 cricket::MediaSessionOptions options;
2690 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002691 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 const cricket::ContentInfo* content =
2693 cricket::GetFirstAudioContent(answer->description());
2694 ASSERT_TRUE(content != NULL);
2695 EXPECT_TRUE(VerifyNoCNCodecs(content));
2696}
2697
2698// This test verifies the call setup when remote answer with audio only and
2699// later updates with video.
2700TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002701 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2703 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2704
deadbeefab9b2d12015-10-14 11:33:11 -07002705 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002706 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707
2708 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2710
2711 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2712 // and answer;
2713 SetLocalDescriptionWithoutError(offer);
2714 SetRemoteDescriptionWithoutError(answer);
2715
2716 video_channel_ = media_engine_->GetVideoChannel(0);
2717 voice_channel_ = media_engine_->GetVoiceChannel(0);
2718
2719 ASSERT_TRUE(video_channel_ == NULL);
2720
2721 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2722 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2723 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2724
2725 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002726 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727 CreateAndSetRemoteOfferAndLocalAnswer();
2728
2729 video_channel_ = media_engine_->GetVideoChannel(0);
2730 voice_channel_ = media_engine_->GetVoiceChannel(0);
2731
2732 ASSERT_TRUE(video_channel_ != NULL);
2733 ASSERT_TRUE(voice_channel_ != NULL);
2734
2735 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2736 ASSERT_EQ(1u, video_channel_->send_streams().size());
2737 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2738 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
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 audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002745 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746 CreateAndSetRemoteOfferAndLocalAnswer();
2747
2748 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2749 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2750 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2751 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2752 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2753}
2754
2755// This test verifies the call setup when remote answer with video only and
2756// later updates with audio.
2757TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002758 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2760 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002761 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002762 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763
2764 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002765 options.recv_audio = false;
2766 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2768 offer, options, cricket::SEC_ENABLED);
2769
2770 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2771 // and answer.
2772 SetLocalDescriptionWithoutError(offer);
2773 SetRemoteDescriptionWithoutError(answer);
2774
2775 video_channel_ = media_engine_->GetVideoChannel(0);
2776 voice_channel_ = media_engine_->GetVoiceChannel(0);
2777
2778 ASSERT_TRUE(voice_channel_ == NULL);
2779 ASSERT_TRUE(video_channel_ != NULL);
2780
2781 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2782 ASSERT_EQ(1u, video_channel_->send_streams().size());
2783 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2784
2785 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002786 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 CreateAndSetRemoteOfferAndLocalAnswer();
2788
2789 voice_channel_ = media_engine_->GetVoiceChannel(0);
2790 ASSERT_TRUE(voice_channel_ != NULL);
2791
2792 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2793 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2794 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2795 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2796
2797 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002798 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799 CreateAndSetRemoteOfferAndLocalAnswer();
2800
2801 video_channel_ = media_engine_->GetVideoChannel(0);
2802 voice_channel_ = media_engine_->GetVoiceChannel(0);
2803
2804 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2805 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2806 ASSERT_EQ(1u, video_channel_->send_streams().size());
2807 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2808}
2809
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002811 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002812 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002813 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 VerifyCryptoParams(offer->description());
2815 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002816 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 VerifyCryptoParams(answer->description());
2818}
2819
jbauchcb560652016-08-04 05:20:32 -07002820TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2821 InitWithGcm();
2822 SendAudioVideoStream1();
2823 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2824 VerifyCryptoParams(offer->description(), true);
2825 SetRemoteDescriptionWithoutError(offer.release());
2826 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2827 VerifyCryptoParams(answer->description(), true);
2828}
2829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002831 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002832 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002833 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002834 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 VerifyNoCryptoParams(offer->description(), false);
2836}
2837
2838TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002839 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 VerifyAnswerFromNonCryptoOffer();
2841}
2842
2843TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002844 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845 VerifyAnswerFromCryptoOffer();
2846}
2847
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002848// This test verifies that setLocalDescription fails if
2849// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2850TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002851 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002852 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002853 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002854
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002855 std::string sdp;
2856 RemoveIceUfragPwdLines(offer.get(), &sdp);
2857 SessionDescriptionInterface* modified_offer =
2858 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002859 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002860}
2861
2862// This test verifies that setRemoteDescription fails if
2863// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2864TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002865 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002866 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002867 std::string sdp;
2868 RemoveIceUfragPwdLines(offer.get(), &sdp);
2869 SessionDescriptionInterface* modified_offer =
2870 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002871 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002872}
2873
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002874// This test verifies that setLocalDescription fails if local offer has
2875// too short ice ufrag and pwd strings.
2876TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002877 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002878 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002880 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2881 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002882 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002883 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002884 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002885
2886 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002887 offer.reset(CreateOffer());
2888 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2889 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002890}
2891
2892// This test verifies that setRemoteDescription fails if remote offer has
2893// too short ice ufrag and pwd strings.
2894TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002895 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002896 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002897 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2898 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002899 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002900 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002901 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002902
deadbeef0ed85b22016-02-23 17:24:52 -08002903 offer.reset(CreateRemoteOffer());
2904 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2905 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002906}
2907
Honghai Zhang04e91462015-12-11 14:26:22 -08002908// Test that if the remote offer indicates the peer requested ICE restart (via
2909// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2910TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002911 Init();
honghaiz503726c2015-07-31 12:37:38 -07002912
2913 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002914 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002915 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002916 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2917 0, "", "", "relay", 0, "");
2918 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2919 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002920 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2921 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002922 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2923
2924 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002925 offer.reset(CreateRemoteOffer());
2926 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002927 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2928 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2929 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002930 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2931 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002932 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2933
2934 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002935 offer.reset(CreateRemoteOffer());
2936 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002937 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2938 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2939 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002940 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2941 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002942 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2943
2944 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002945 offer.reset(CreateRemoteOffer());
2946 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2947 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002948 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2949}
2950
Honghai Zhang04e91462015-12-11 14:26:22 -08002951// Test that if the remote answer indicates the peer requested ICE restart (via
2952// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2953TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2954 Init();
2955 SessionDescriptionInterface* offer = CreateOffer();
2956 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002957
2958 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002959 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002960 answer->set_type(JsepSessionDescription::kPrAnswer);
2961 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002962 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2963 0, "", "", "relay", 0, "");
2964 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2965 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002966 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2967 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002968 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2969
2970 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002971 answer.reset(CreateRemoteAnswer(offer));
2972 answer->set_type(JsepSessionDescription::kPrAnswer);
2973 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002974 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2975 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2976 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002977 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2978 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002979 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2980
2981 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002982 answer.reset(CreateRemoteAnswer(offer));
2983 answer->set_type(JsepSessionDescription::kPrAnswer);
2984 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002985 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2986 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2987 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002988 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2989 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002990 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2991
2992 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002993 answer.reset(CreateRemoteAnswer(offer));
2994 answer->set_type(JsepSessionDescription::kPrAnswer);
2995 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2996 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002997 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2998}
2999
Donald Curtisd4f769d2015-05-28 09:48:21 -07003000// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003001// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003002TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3003 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3004
3005 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003006 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003007
3008 PeerConnectionInterface::RTCOfferAnswerOptions options;
3009 options.use_rtp_mux = true;
3010
3011 SessionDescriptionInterface* offer = CreateRemoteOffer();
3012 SetRemoteDescriptionWithoutError(offer);
3013
htaa2a49d92016-03-04 02:51:39 -08003014 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003015 SetLocalDescriptionWithoutError(answer);
3016
deadbeefcbecd352015-09-23 11:50:27 -07003017 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3018 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003019
deadbeefcbecd352015-09-23 11:50:27 -07003020 cricket::BaseChannel* voice_channel = session_->voice_channel();
3021 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003022
3023 // Checks if one of the transport channels contains a connection using a given
3024 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003025 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003026 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003027 session_->GetChannelTransportStats(voice_channel, &stats);
3028 for (auto& kv : stats.transport_stats) {
3029 for (auto& chan_stat : kv.second.channel_stats) {
3030 for (auto& conn_info : chan_stat.connection_infos) {
3031 if (conn_info.remote_candidate.address().port() == port) {
3032 return true;
3033 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003034 }
3035 }
3036 }
3037 return false;
3038 };
3039
3040 EXPECT_FALSE(connection_with_remote_port(5000));
3041 EXPECT_FALSE(connection_with_remote_port(5001));
3042 EXPECT_FALSE(connection_with_remote_port(6000));
3043
3044 // The way the *_WAIT checks work is they only wait if the condition fails,
3045 // which does not help in the case where state is not changing. This is
3046 // problematic in this test since we want to verify that adding a video
3047 // candidate does _not_ change state. So we interleave candidates and assume
3048 // that messages are executed in the order they were posted.
3049
3050 // First audio candidate.
3051 cricket::Candidate candidate0;
3052 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3053 candidate0.set_component(1);
3054 candidate0.set_protocol("udp");
3055 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3056 candidate0);
3057 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3058
3059 // Video candidate.
3060 cricket::Candidate candidate1;
3061 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3062 candidate1.set_component(1);
3063 candidate1.set_protocol("udp");
3064 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3065 candidate1);
3066 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3067
3068 // Second audio candidate.
3069 cricket::Candidate candidate2;
3070 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3071 candidate2.set_component(1);
3072 candidate2.set_protocol("udp");
3073 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3074 candidate2);
3075 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3076
3077 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3078 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3079
3080 // No need here for a _WAIT check since we are checking that state hasn't
3081 // changed: if this is false we would be doing waits for nothing and if this
3082 // is true then there will be no messages processed anyways.
3083 EXPECT_FALSE(connection_with_remote_port(6000));
3084}
3085
deadbeefcbecd352015-09-23 11:50:27 -07003086// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003087TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3088 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003089 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003090
3091 PeerConnectionInterface::RTCOfferAnswerOptions options;
3092 options.use_rtp_mux = true;
3093
3094 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003095 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003096
deadbeefcbecd352015-09-23 11:50:27 -07003097 EXPECT_NE(session_->voice_rtp_transport_channel(),
3098 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003099
deadbeefab9b2d12015-10-14 11:33:11 -07003100 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003101 SessionDescriptionInterface* answer =
3102 CreateRemoteAnswer(session_->local_description());
3103 SetRemoteDescriptionWithoutError(answer);
3104
deadbeefcbecd352015-09-23 11:50:27 -07003105 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3106 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003107}
3108
deadbeefcbecd352015-09-23 11:50:27 -07003109// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003110TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3111 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003112 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003113
Donald Curtis0e209b02015-03-24 09:29:54 -07003114 PeerConnectionInterface::RTCOfferAnswerOptions options;
3115 options.use_rtp_mux = true;
3116
3117 SessionDescriptionInterface* offer = CreateOffer(options);
3118 SetLocalDescriptionWithoutError(offer);
3119
deadbeefcbecd352015-09-23 11:50:27 -07003120 EXPECT_NE(session_->voice_rtp_transport_channel(),
3121 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003122
deadbeefab9b2d12015-10-14 11:33:11 -07003123 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
3125 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003126 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003127 CreateRemoteAnswer(session_->local_description()));
3128 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3129 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3130 JsepSessionDescription* modified_answer =
3131 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3132 modified_answer->Initialize(answer_copy, "1", "1");
3133 SetRemoteDescriptionWithoutError(modified_answer); //
3134
deadbeefcbecd352015-09-23 11:50:27 -07003135 EXPECT_NE(session_->voice_rtp_transport_channel(),
3136 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003137}
3138
3139// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3140TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3141 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003142 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003143
3144 PeerConnectionInterface::RTCOfferAnswerOptions options;
3145 options.use_rtp_mux = true;
3146
3147 SessionDescriptionInterface* offer = CreateOffer(options);
3148 SetLocalDescriptionWithoutError(offer);
3149
deadbeefcbecd352015-09-23 11:50:27 -07003150 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3151 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003152
deadbeefab9b2d12015-10-14 11:33:11 -07003153 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003154 SessionDescriptionInterface* answer =
3155 CreateRemoteAnswer(session_->local_description());
3156 SetRemoteDescriptionWithoutError(answer);
3157
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 answer, but no
3163// audio content in the answer.
3164TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3165 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003166 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003167
3168 PeerConnectionInterface::RTCOfferAnswerOptions options;
3169 options.use_rtp_mux = true;
3170
3171 SessionDescriptionInterface* offer = CreateOffer(options);
3172 SetLocalDescriptionWithoutError(offer);
3173
3174 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3175 session_->video_rtp_transport_channel());
3176
deadbeefab9b2d12015-10-14 11:33:11 -07003177 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003178 cricket::MediaSessionOptions recv_options;
3179 recv_options.recv_audio = false;
3180 recv_options.recv_video = true;
3181 SessionDescriptionInterface* answer =
3182 CreateRemoteAnswer(session_->local_description(), recv_options);
3183 SetRemoteDescriptionWithoutError(answer);
3184
deadbeefd59daf82015-10-14 15:02:44 -07003185 EXPECT_TRUE(nullptr == session_->voice_channel());
3186 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003187
deadbeefd59daf82015-10-14 15:02:44 -07003188 session_->Close();
3189 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3190 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3191 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3192 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003193}
3194
3195// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3196TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3197 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003198 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003199
Donald Curtis0e209b02015-03-24 09:29:54 -07003200 PeerConnectionInterface::RTCOfferAnswerOptions options;
3201 options.use_rtp_mux = true;
3202
3203 SessionDescriptionInterface* offer = CreateOffer(options);
3204 SetLocalDescriptionWithoutError(offer);
3205
deadbeefcbecd352015-09-23 11:50:27 -07003206 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3207 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003208
deadbeefab9b2d12015-10-14 11:33:11 -07003209 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003210
3211 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003212 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213 CreateRemoteAnswer(session_->local_description()));
3214 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3215 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3216 JsepSessionDescription* modified_answer =
3217 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3218 modified_answer->Initialize(answer_copy, "1", "1");
3219 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220
deadbeefcbecd352015-09-23 11:50:27 -07003221 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3222 session_->video_rtp_transport_channel());
3223}
3224
3225// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3226TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3227 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003229
3230 SessionDescriptionInterface* offer = CreateRemoteOffer();
3231 SetRemoteDescriptionWithoutError(offer);
3232
3233 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3234 session_->video_rtp_transport_channel());
3235
deadbeefab9b2d12015-10-14 11:33:11 -07003236 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003237 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003238 SetLocalDescriptionWithoutError(answer);
3239
3240 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3241 session_->video_rtp_transport_channel());
3242}
3243
3244// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3245TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3246 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003247 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003248
3249 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003250 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003251 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3252 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3253 JsepSessionDescription* modified_offer =
3254 new JsepSessionDescription(JsepSessionDescription::kOffer);
3255 modified_offer->Initialize(offer_copy, "1", "1");
3256
3257 // Expect an error when applying the remote description
3258 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3259 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003260}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261
Peter Thatcher4eddf182015-04-30 10:55:59 -07003262// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003263TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3264 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003265 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266
Donald Curtis0e209b02015-03-24 09:29:54 -07003267 PeerConnectionInterface::RTCOfferAnswerOptions options;
3268 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269
Donald Curtis0e209b02015-03-24 09:29:54 -07003270 SessionDescriptionInterface* offer = CreateOffer(options);
3271 SetLocalDescriptionWithoutError(offer);
3272
deadbeefcbecd352015-09-23 11:50:27 -07003273 EXPECT_NE(session_->voice_rtp_transport_channel(),
3274 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003275
deadbeefab9b2d12015-10-14 11:33:11 -07003276 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003277 SessionDescriptionInterface* answer =
3278 CreateRemoteAnswer(session_->local_description());
3279 SetRemoteDescriptionWithoutError(answer);
3280
3281 // This should lead to an audio-only call but isn't implemented
3282 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003283 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3284 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003285}
3286
deadbeefcbecd352015-09-23 11:50:27 -07003287// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003288TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3289 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003291 PeerConnectionInterface::RTCOfferAnswerOptions options;
3292 options.use_rtp_mux = true;
3293
3294 SessionDescriptionInterface* offer = CreateOffer(options);
3295 SetLocalDescriptionWithoutError(offer);
3296
deadbeefcbecd352015-09-23 11:50:27 -07003297 EXPECT_NE(session_->voice_rtp_transport_channel(),
3298 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003299
deadbeefab9b2d12015-10-14 11:33:11 -07003300 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003301
3302 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003303 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003304 CreateRemoteAnswer(session_->local_description()));
3305 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3306 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3307 JsepSessionDescription* modified_answer =
3308 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3309 modified_answer->Initialize(answer_copy, "1", "1");
3310 SetRemoteDescriptionWithoutError(modified_answer); //
3311
deadbeefcbecd352015-09-23 11:50:27 -07003312 EXPECT_NE(session_->voice_rtp_transport_channel(),
3313 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314}
3315
Peter Thatcher4eddf182015-04-30 10:55:59 -07003316// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3317TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3318 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003319 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003320
3321 PeerConnectionInterface::RTCOfferAnswerOptions options;
3322 options.use_rtp_mux = true;
3323
3324 SessionDescriptionInterface* offer = CreateOffer(options);
3325 SetRemoteDescriptionWithoutError(offer);
3326
deadbeefcbecd352015-09-23 11:50:27 -07003327 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3328 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003329}
3330
skvlad6c87a672016-05-17 17:49:52 -07003331// Adding a new channel to a BUNDLE which is already connected should directly
3332// assign the bundle transport to the channel, without first setting a
3333// disconnected non-bundle transport and then replacing it. The application
3334// should not receive any changes in the ICE state.
3335TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3336 LoopbackNetworkConfiguration config;
3337 LoopbackNetworkManager loopback_network_manager(this, config);
3338 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3339 // connected. Disabling either of these two means that we need to wait for the
3340 // answer to find out if more transports are needed.
3341 configuration_.bundle_policy =
3342 PeerConnectionInterface::kBundlePolicyMaxBundle;
3343 configuration_.rtcp_mux_policy =
3344 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3345 options_.disable_encryption = true;
3346 Init();
3347
3348 // Negotiate an audio channel with MAX_BUNDLE enabled.
3349 SendAudioOnlyStream2();
3350 SessionDescriptionInterface* offer = CreateOffer();
3351 SetLocalDescriptionWithoutError(offer);
3352 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3353 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3354 std::string sdp;
3355 offer->ToString(&sdp);
3356 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3357 JsepSessionDescription::kAnswer, sdp, nullptr);
3358 ASSERT_TRUE(answer != NULL);
3359 SetRemoteDescriptionWithoutError(answer);
3360
3361 // Wait for the ICE state to stabilize.
3362 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3363 observer_.ice_connection_state_, kIceCandidatesTimeout);
3364 observer_.ice_connection_state_history_.clear();
3365
3366 // Now add a video channel which should be using the same bundle transport.
3367 SendAudioVideoStream2();
3368 offer = CreateOffer();
3369 offer->ToString(&sdp);
3370 SetLocalDescriptionWithoutError(offer);
3371 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3372 sdp, nullptr);
3373 ASSERT_TRUE(answer != NULL);
3374 SetRemoteDescriptionWithoutError(answer);
3375
3376 // Wait for ICE state to stabilize
3377 rtc::Thread::Current()->ProcessMessages(0);
3378 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3379 observer_.ice_connection_state_, kIceCandidatesTimeout);
3380
3381 // No ICE state changes are expected to happen.
3382 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3383}
3384
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003385TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3386 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003387 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003388
3389 PeerConnectionInterface::RTCOfferAnswerOptions options;
3390 SessionDescriptionInterface* offer = CreateOffer(options);
3391 SetLocalDescriptionWithoutError(offer);
3392
deadbeefcbecd352015-09-23 11:50:27 -07003393 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3394 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003395
deadbeefab9b2d12015-10-14 11:33:11 -07003396 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003397 SessionDescriptionInterface* answer =
3398 CreateRemoteAnswer(session_->local_description());
3399 SetRemoteDescriptionWithoutError(answer);
3400
deadbeefcbecd352015-09-23 11:50:27 -07003401 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3402 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003403}
3404
3405TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3406 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003407 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408
3409 PeerConnectionInterface::RTCOfferAnswerOptions options;
3410 SessionDescriptionInterface* offer = CreateOffer(options);
3411 SetLocalDescriptionWithoutError(offer);
3412
deadbeefcbecd352015-09-23 11:50:27 -07003413 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3414 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003415
deadbeefab9b2d12015-10-14 11:33:11 -07003416 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003417 SessionDescriptionInterface* answer =
3418 CreateRemoteAnswer(session_->local_description());
3419 SetRemoteDescriptionWithoutError(answer);
3420
deadbeefcbecd352015-09-23 11:50:27 -07003421 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3422 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003423}
3424
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003425// This test verifies that SetLocalDescription and SetRemoteDescription fails
3426// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3427TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003428 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003429 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003430
3431 PeerConnectionInterface::RTCOfferAnswerOptions options;
3432 options.use_rtp_mux = true;
3433
3434 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003435 std::string offer_str;
3436 offer->ToString(&offer_str);
3437 // Disable rtcp-mux
3438 const std::string rtcp_mux = "rtcp-mux";
3439 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003440 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003441 xrtcp_mux.c_str(), xrtcp_mux.length(),
3442 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003443 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003444 new JsepSessionDescription(JsepSessionDescription::kOffer);
3445 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003446 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003447 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003448 new JsepSessionDescription(JsepSessionDescription::kOffer);
3449 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003450 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003451 // Trying unmodified SDP.
3452 SetLocalDescriptionWithoutError(offer);
3453}
3454
jbauchcb560652016-08-04 05:20:32 -07003455TEST_F(WebRtcSessionTest, SetSetupGcm) {
3456 InitWithGcm();
3457 SendAudioVideoStream1();
3458 CreateAndSetRemoteOfferAndLocalAnswer();
3459}
3460
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3462 TestCanInsertDtmf(false);
3463}
3464
3465TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3466 TestCanInsertDtmf(true);
3467}
3468
3469TEST_F(WebRtcSessionTest, InsertDtmf) {
3470 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003471 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003472 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 CreateAndSetRemoteOfferAndLocalAnswer();
3474 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3475 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3476
3477 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 const int expected_duration = 90;
3479 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3480 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3481 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3482
3483 // Verify
3484 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003485 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003487 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003489 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003491 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492}
3493
deadbeefd59daf82015-10-14 15:02:44 -07003494// This test verifies the |initial_offerer| flag when session initiates the
3495// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003497 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003498 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003499 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3501 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003502 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003504 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505}
3506
deadbeefd59daf82015-10-14 15:02:44 -07003507// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003509 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003510 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511 SessionDescriptionInterface* offer = CreateRemoteOffer();
3512 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003513 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514
deadbeefd59daf82015-10-14 15:02:44 -07003515 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003517 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518}
3519
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3521TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003522 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003523 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003524 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003526 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527 CreateRemoteAnswer(session_->local_description()));
3528
3529 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3530 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003531 JsepSessionDescription* modified_answer =
3532 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533
3534 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3535 answer->session_id(),
3536 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003537 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538
wu@webrtc.org4e393072014-04-07 17:04:35 +00003539 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 std::string sdp;
3541 EXPECT_TRUE(answer->ToString(&sdp));
3542 const std::string kAudioMid = "a=mid:audio";
3543 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003544 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545 kAudioMidReplaceStr.c_str(),
3546 kAudioMidReplaceStr.length(),
3547 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003548 SessionDescriptionInterface* modified_answer1 =
3549 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003550 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551
wu@webrtc.org4e393072014-04-07 17:04:35 +00003552 // Different media types.
3553 EXPECT_TRUE(answer->ToString(&sdp));
3554 const std::string kAudioMline = "m=audio";
3555 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003556 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003557 kAudioMlineReplaceStr.c_str(),
3558 kAudioMlineReplaceStr.length(),
3559 &sdp);
3560 SessionDescriptionInterface* modified_answer2 =
3561 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3562 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3563
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 SetRemoteDescriptionWithoutError(answer.release());
3565}
3566
3567// Verifying remote offer and local answer have matching m-lines as per
3568// RFC 3264.
3569TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003570 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003571 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 SessionDescriptionInterface* offer = CreateRemoteOffer();
3573 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003574 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575
3576 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3577 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003578 JsepSessionDescription* modified_answer =
3579 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580
3581 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3582 answer->session_id(),
3583 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003584 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585 SetLocalDescriptionWithoutError(answer);
3586}
3587
3588// This test verifies that WebRtcSession does not start candidate allocation
3589// before SetLocalDescription is called.
3590TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003591 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003592 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593 SessionDescriptionInterface* offer = CreateRemoteOffer();
3594 cricket::Candidate candidate;
3595 candidate.set_component(1);
3596 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3597 candidate);
3598 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3599 cricket::Candidate candidate1;
3600 candidate1.set_component(1);
3601 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3602 candidate1);
3603 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3604 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003605 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3606 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607
3608 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003609 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3611 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3612
htaa2a49d92016-03-04 02:51:39 -08003613 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003615 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3616}
3617
3618// This test verifies that crypto parameter is updated in local session
3619// description as per security policy set in MediaSessionDescriptionFactory.
3620TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003621 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003622 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003623 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624
3625 // Making sure SetLocalDescription correctly sets crypto value in
3626 // SessionDescription object after de-serialization of sdp string. The value
3627 // will be set as per MediaSessionDescriptionFactory.
3628 std::string offer_str;
3629 offer->ToString(&offer_str);
3630 SessionDescriptionInterface* jsep_offer_str =
3631 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3632 SetLocalDescriptionWithoutError(jsep_offer_str);
3633 EXPECT_TRUE(session_->voice_channel()->secure_required());
3634 EXPECT_TRUE(session_->video_channel()->secure_required());
3635}
3636
3637// This test verifies the crypto parameter when security is disabled.
3638TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003639 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003640 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003641 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003642 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003643
3644 // Making sure SetLocalDescription correctly sets crypto value in
3645 // SessionDescription object after de-serialization of sdp string. The value
3646 // will be set as per MediaSessionDescriptionFactory.
3647 std::string offer_str;
3648 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003649 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3651 SetLocalDescriptionWithoutError(jsep_offer_str);
3652 EXPECT_FALSE(session_->voice_channel()->secure_required());
3653 EXPECT_FALSE(session_->video_channel()->secure_required());
3654}
3655
3656// This test verifies that an answer contains new ufrag and password if an offer
3657// with new ufrag and password is received.
3658TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003659 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003660 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003661 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003662 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SetRemoteDescriptionWithoutError(offer.release());
3664
deadbeefab9b2d12015-10-14 11:33:11 -07003665 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003666 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 SetLocalDescriptionWithoutError(answer.release());
3668
3669 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003670 for (const cricket::ContentInfo& content :
3671 session_->local_description()->description()->contents()) {
3672 options.transport_options[content.name].ice_restart = true;
3673 }
kwibergd1fe2812016-04-27 06:47:29 -07003674 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003675 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 SetRemoteDescriptionWithoutError(updated_offer1.release());
3677
kwibergd1fe2812016-04-27 06:47:29 -07003678 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003679
deadbeef0ed85b22016-02-23 17:24:52 -08003680 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3681 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003682
deadbeef0ed85b22016-02-23 17:24:52 -08003683 // Even a second answer (created before the description is set) should have
3684 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003685 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003686
3687 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3688 session_->local_description()->description()));
3689
3690 SetLocalDescriptionWithoutError(updated_answer2.release());
3691}
3692
3693// This test verifies that an answer contains new ufrag and password if an offer
3694// that changes either the ufrag or password (but not both) is received.
3695// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3696// a=ice-pwd attributes compared to the previous SDP from the peer, it
3697// indicates that ICE is restarting for this media stream."
3698TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3699 Init();
3700 cricket::MediaSessionOptions options;
3701 options.recv_audio = true;
3702 options.recv_video = true;
3703 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003704 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003705 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3706 SetRemoteDescriptionWithoutError(offer.release());
3707
3708 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003709 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003710 SetLocalDescriptionWithoutError(answer.release());
3711
3712 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003713 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003714 CreateRemoteOffer(options, session_->remote_description()));
3715 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3716 "original_password12345");
3717 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3718
kwibergd1fe2812016-04-27 06:47:29 -07003719 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003720 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3721 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003722 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003723
3724 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003725 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003726 CreateRemoteOffer(options, session_->remote_description()));
3727 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3728 "modified_password12345");
3729 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3730
kwibergd1fe2812016-04-27 06:47:29 -07003731 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003732 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3733 session_->local_description()->description()));
3734 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736
wu@webrtc.org91053e72013-08-10 07:18:04 +00003737// This test verifies that an answer contains old ufrag and password if an offer
3738// with old ufrag and password is received.
3739TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003740 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003741 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003742 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003743 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003744 SetRemoteDescriptionWithoutError(offer.release());
3745
deadbeefab9b2d12015-10-14 11:33:11 -07003746 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003747 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003748 SetLocalDescriptionWithoutError(answer.release());
3749
3750 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003751 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003752 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003753 SetRemoteDescriptionWithoutError(updated_offer2.release());
3754
kwibergd1fe2812016-04-27 06:47:29 -07003755 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003756
deadbeef0ed85b22016-02-23 17:24:52 -08003757 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3758 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759
3760 SetLocalDescriptionWithoutError(updated_answer2.release());
3761}
3762
deadbeef0ed85b22016-02-23 17:24:52 -08003763// This test verifies that if an offer does an ICE restart on some, but not all
3764// media sections, the answer will change the ufrag/password in the correct
3765// media sections.
3766TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3767 Init();
3768 cricket::MediaSessionOptions options;
3769 options.recv_video = true;
3770 options.recv_audio = true;
3771 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003772 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003773
3774 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3775 "aaaaaaaaaaaaaaaaaaaaaa");
3776 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3777 "bbbbbbbbbbbbbbbbbbbbbb");
3778 SetRemoteDescriptionWithoutError(offer.release());
3779
3780 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003781 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003782 SetLocalDescriptionWithoutError(answer.release());
3783
3784 // Receive an offer with new ufrag and password, but only for the video media
3785 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003786 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003787 CreateRemoteOffer(options, session_->remote_description()));
3788 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3789 "cccccccccccccccccccccc");
3790 SetRemoteDescriptionWithoutError(updated_offer.release());
3791
kwibergd1fe2812016-04-27 06:47:29 -07003792 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003793
3794 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3795 session_->local_description()->description(),
3796 cricket::MEDIA_TYPE_AUDIO));
3797
3798 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3799 session_->local_description()->description(),
3800 cricket::MEDIA_TYPE_VIDEO));
3801
3802 SetLocalDescriptionWithoutError(updated_answer.release());
3803}
3804
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003806 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003807 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003808 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003809 const std::string session_id_orig = offer->session_id();
3810 const std::string session_version_orig = offer->session_version();
3811 SetLocalDescriptionWithoutError(offer);
3812
3813 video_channel_ = media_engine_->GetVideoChannel(0);
3814 video_channel_->set_fail_set_send_codecs(true);
3815
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003816 SessionDescriptionInterface* answer =
3817 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003818 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003819
3820 // Test that after a content error, setting any description will
3821 // result in an error.
3822 video_channel_->set_fail_set_send_codecs(false);
3823 answer = CreateRemoteAnswer(session_->local_description());
3824 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3825 offer = CreateRemoteOffer();
3826 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003827}
3828
3829// Runs the loopback call test with BUNDLE and STUN disabled.
3830TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3831 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003832 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003833 cricket::PORTALLOCATOR_DISABLE_STUN |
3834 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003835 TestLoopbackCall();
3836}
3837
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003838TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003839 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003840 cricket::PORTALLOCATOR_DISABLE_STUN |
3841 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3842 cricket::PORTALLOCATOR_DISABLE_RELAY);
3843
3844 // best connection is IPv6 since it has higher network preference.
3845 LoopbackNetworkConfiguration config;
3846 config.test_ipv6_network_ = true;
3847 config.best_connection_after_initial_ice_converged_ =
3848 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3849
3850 TestLoopbackCall(config);
3851}
3852
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003853// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003854TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003855 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3856 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003857 TestLoopbackCall();
3858}
3859
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003860TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003861 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003862 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003864 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003865 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3866}
3867
Henrik Boström87713d02015-08-25 09:53:21 +02003868TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003869 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870
htaa2a49d92016-03-04 02:51:39 -08003871 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003872 options_.disable_sctp_data_channels = false;
3873
Henrik Boström87713d02015-08-25 09:53:21 +02003874 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003875
3876 SetLocalDescriptionWithDataChannel();
3877 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3878}
3879
Henrik Boström87713d02015-08-25 09:53:21 +02003880TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003881 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003882
Henrik Boström87713d02015-08-25 09:53:21 +02003883 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003884
kwibergd1fe2812016-04-27 06:47:29 -07003885 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003886 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003887 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3888}
3889
Henrik Boström87713d02015-08-25 09:53:21 +02003890TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003891 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003892 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003893 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003894
3895 // Create remote offer with SCTP.
3896 cricket::MediaSessionOptions options;
3897 options.data_channel_type = cricket::DCT_SCTP;
3898 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003899 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003900 SetRemoteDescriptionWithoutError(offer);
3901
3902 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003903 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003904 EXPECT_TRUE(answer != NULL);
3905 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3906 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003907}
3908
Henrik Boström87713d02015-08-25 09:53:21 +02003909TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003910 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003911 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003912
3913 SetLocalDescriptionWithDataChannel();
3914 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3915}
3916
Henrik Boström87713d02015-08-25 09:53:21 +02003917TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003918 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003919
Henrik Boström87713d02015-08-25 09:53:21 +02003920 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003921
3922 SetLocalDescriptionWithDataChannel();
3923 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3924}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003925
Henrik Boström87713d02015-08-25 09:53:21 +02003926TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003927 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003928 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003929 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003930
3931 SetLocalDescriptionWithDataChannel();
3932 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3933}
3934
Henrik Boström87713d02015-08-25 09:53:21 +02003935TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003936 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003937 const int new_send_port = 9998;
3938 const int new_recv_port = 7775;
3939
Henrik Boström87713d02015-08-25 09:53:21 +02003940 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003941 SetFactoryDtlsSrtp();
3942
3943 // By default, don't actually add the codecs to desc_factory_; they don't
3944 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3945 // let the session description get parsed. That'll get the proper codecs
3946 // into the stream.
3947 cricket::MediaSessionOptions options;
3948 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3949 "stream1", new_send_port, options);
3950
3951 // SetRemoteDescription will take the ownership of the offer.
3952 SetRemoteDescriptionWithoutError(offer);
3953
htaa2a49d92016-03-04 02:51:39 -08003954 SessionDescriptionInterface* answer =
3955 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003956 ASSERT_TRUE(answer != NULL);
3957
3958 // Now set the local description, which'll take ownership of the answer.
3959 SetLocalDescriptionWithoutError(answer);
3960
3961 // TEST PLAN: Set the port number to something new, set it in the SDP,
3962 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003963 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003964 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003965
3966 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3967 int portnum = -1;
3968 ASSERT_TRUE(ch != NULL);
3969 ASSERT_EQ(1UL, ch->send_codecs().size());
3970 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003971 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003972 ch->send_codecs()[0].name.c_str()));
3973 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3974 &portnum));
3975 EXPECT_EQ(new_send_port, portnum);
3976
3977 ASSERT_EQ(1UL, ch->recv_codecs().size());
3978 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003979 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003980 ch->recv_codecs()[0].name.c_str()));
3981 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3982 &portnum));
3983 EXPECT_EQ(new_recv_port, portnum);
3984}
3985
deadbeefab9b2d12015-10-14 11:33:11 -07003986// Verifies that when a session's DataChannel receives an OPEN message,
3987// WebRtcSession signals the DataChannel creation request with the expected
3988// config.
3989TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3990 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3991
3992 InitWithDtls(GetParam());
3993
3994 SetLocalDescriptionWithDataChannel();
3995 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3996
3997 webrtc::DataChannelInit config;
3998 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07003999 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004000 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4001 cricket::ReceiveDataParams params;
4002 params.ssrc = config.id;
4003 params.type = cricket::DMT_CONTROL;
4004
4005 cricket::DataChannel* data_channel = session_->data_channel();
4006 data_channel->SignalDataReceived(data_channel, params, payload);
4007
4008 EXPECT_EQ("a", last_data_channel_label_);
4009 EXPECT_EQ(config.id, last_data_channel_config_.id);
4010 EXPECT_FALSE(last_data_channel_config_.negotiated);
4011 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4012 last_data_channel_config_.open_handshake_role);
4013}
4014
4015TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004016 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004017 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004018
htaa2a49d92016-03-04 02:51:39 -08004019 configuration_.certificates.push_back(certificate);
4020 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004021 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4022
4023 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4024}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004025
Henrik Boström87713d02015-08-25 09:53:21 +02004026// Verifies that CreateOffer succeeds when CreateOffer is called before async
4027// identity generation is finished (even if a certificate is provided this is
4028// an async op).
4029TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4030 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4031 InitWithDtls(GetParam());
4032
Henrik Boströmd8281982015-08-27 10:12:24 +02004033 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004034 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004035 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004036
wu@webrtc.org91053e72013-08-10 07:18:04 +00004037 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004038 VerifyNoCryptoParams(offer->description(), true);
4039 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004040}
4041
4042// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004043// identity generation is finished (even if a certificate is provided this is
4044// an async op).
4045TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004046 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004047 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004048 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004049
4050 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004051 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004052 std::unique_ptr<JsepSessionDescription> offer(
4053 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004054 ASSERT_TRUE(offer.get() != NULL);
4055 SetRemoteDescriptionWithoutError(offer.release());
4056
kwibergd1fe2812016-04-27 06:47:29 -07004057 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004058 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004059 VerifyNoCryptoParams(answer->description(), true);
4060 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061}
4062
4063// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004064// identity generation is finished (even if a certificate is provided this is
4065// an async op).
4066TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004067 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004068 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004069
Henrik Boströmd8281982015-08-27 10:12:24 +02004070 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004071
kwibergd1fe2812016-04-27 06:47:29 -07004072 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004073 EXPECT_TRUE(offer != NULL);
4074}
4075
4076// Verifies that CreateOffer fails when CreateOffer is called after async
4077// identity generation fails.
4078TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004079 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004080 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004081
Henrik Boströmd8281982015-08-27 10:12:24 +02004082 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004083
kwibergd1fe2812016-04-27 06:47:29 -07004084 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004085 EXPECT_TRUE(offer == NULL);
4086}
4087
4088// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4089// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004090TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004091 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004092 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004093 VerifyMultipleAsyncCreateDescription(GetParam(),
4094 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004095}
4096
4097// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4098// before async identity generation fails.
4099TEST_F(WebRtcSessionTest,
4100 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004101 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004102 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4103 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004104}
4105
4106// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4107// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004108TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004109 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004110 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004111 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004112 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004113}
4114
4115// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4116// before async identity generation fails.
4117TEST_F(WebRtcSessionTest,
4118 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004119 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004120 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4121 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004122}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004123
4124// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4125// offer has no SDES crypto but only DTLS fingerprint.
4126TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4127 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004128 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004129 // Create a remote offer with secured transport disabled.
4130 cricket::MediaSessionOptions options;
4131 JsepSessionDescription* offer(CreateRemoteOffer(
4132 options, cricket::SEC_DISABLED));
4133 // Adds a DTLS fingerprint to the remote offer.
4134 cricket::SessionDescription* sdp = offer->description();
4135 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4136 ASSERT_TRUE(audio != NULL);
4137 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4138 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004139 rtc::SSLFingerprint::CreateFromRfc4572(
4140 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004141 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004142 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004143}
4144
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004145TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004146 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004147 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004148 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004149 SessionDescriptionInterface* offer = CreateOffer();
4150
4151 SetLocalDescriptionWithoutError(offer);
4152
4153 voice_channel_ = media_engine_->GetVoiceChannel(0);
4154
4155 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004156 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004157 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004158}
4159
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004160// Tests that we can renegotiate new media content with ICE candidates in the
4161// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004162TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004163 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004164 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004165 SetFactoryDtlsSrtp();
4166
deadbeefab9b2d12015-10-14 11:33:11 -07004167 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004168 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169 SetLocalDescriptionWithoutError(offer);
4170
4171 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4172 SetRemoteDescriptionWithoutError(answer);
4173
4174 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004175 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4177
4178 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004179 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004180 candidate1.set_component(1);
4181 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4182 candidate1);
4183 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4184 SetRemoteDescriptionWithoutError(offer);
4185
htaa2a49d92016-03-04 02:51:39 -08004186 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004187 SetLocalDescriptionWithoutError(answer);
4188}
4189
4190// Tests that we can renegotiate new media content with ICE candidates separated
4191// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004192TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004193 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004194 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004195 SetFactoryDtlsSrtp();
4196
deadbeefab9b2d12015-10-14 11:33:11 -07004197 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004198 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199 SetLocalDescriptionWithoutError(offer);
4200
4201 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4202 SetRemoteDescriptionWithoutError(answer);
4203
4204 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004205 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4207 SetRemoteDescriptionWithoutError(offer);
4208
4209 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004210 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004211 candidate1.set_component(1);
4212 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4213 candidate1);
4214 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4215
htaa2a49d92016-03-04 02:51:39 -08004216 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004217 SetLocalDescriptionWithoutError(answer);
4218}
honghaiz7f777492016-02-02 21:54:01 -08004219
zhihuang9763d562016-08-05 11:14:50 -07004220#ifdef HAVE_QUIC
4221TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4222 configuration_.enable_quic = true;
4223 InitWithDtls(GetParam());
4224 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4225 SessionDescriptionInterface* offer = CreateOffer();
4226 ASSERT_TRUE(offer);
4227 ASSERT_TRUE(offer->description());
4228 SetLocalDescriptionWithoutError(offer);
4229 cricket::MediaSessionOptions options;
4230 options.recv_audio = true;
4231 options.recv_video = true;
4232 SessionDescriptionInterface* answer =
4233 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4234 ASSERT_TRUE(answer);
4235 ASSERT_TRUE(answer->description());
4236 SetRemoteDescriptionWithoutError(answer);
4237}
4238#endif // HAVE_QUIC
4239
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004240// Tests that RTX codec is removed from the answer when it isn't supported
4241// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004242TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004243 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004244 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004245 std::string offer_sdp(kSdpWithRtx);
4246
4247 SessionDescriptionInterface* offer =
4248 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4249 EXPECT_TRUE(offer->ToString(&offer_sdp));
4250
4251 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004252 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004253 SetRemoteDescriptionWithoutError(offer);
4254
htaa2a49d92016-03-04 02:51:39 -08004255 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004256 // Answer SDP does not contain the RTX codec.
4257 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004258 SetLocalDescriptionWithoutError(answer);
4259}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004261// This verifies that the voice channel after bundle has both options from video
4262// and voice channels.
4263TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4264 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004265 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004266
4267 PeerConnectionInterface::RTCOfferAnswerOptions options;
4268 options.use_rtp_mux = true;
4269
4270 SessionDescriptionInterface* offer = CreateOffer(options);
4271 SetLocalDescriptionWithoutError(offer);
4272
4273 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4274 rtc::Socket::Option::OPT_SNDBUF, 4000);
4275
4276 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4277 rtc::Socket::Option::OPT_RCVBUF, 8000);
4278
4279 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004280 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004281 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4282 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004283 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004284 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4285
deadbeefcbecd352015-09-23 11:50:27 -07004286 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004287 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4288 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004289 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004290 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4291
deadbeefcbecd352015-09-23 11:50:27 -07004292 EXPECT_NE(session_->voice_rtp_transport_channel(),
4293 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294
deadbeefab9b2d12015-10-14 11:33:11 -07004295 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004296 SessionDescriptionInterface* answer =
4297 CreateRemoteAnswer(session_->local_description());
4298 SetRemoteDescriptionWithoutError(answer);
4299
deadbeefcbecd352015-09-23 11:50:27 -07004300 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004301 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4302 EXPECT_EQ(4000, option_val);
4303
deadbeefcbecd352015-09-23 11:50:27 -07004304 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004305 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4306 EXPECT_EQ(8000, option_val);
4307}
4308
tommi0f620f42015-07-09 03:25:02 -07004309// Test creating a session, request multiple offers, destroy the session
4310// and make sure we got success/failure callbacks for all of the requests.
4311// Background: crbug.com/507307
4312TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4313 Init();
4314
4315 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4316 PeerConnectionInterface::RTCOfferAnswerOptions options;
4317 options.offer_to_receive_audio =
4318 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004319 cricket::MediaSessionOptions session_options;
4320 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004321
4322 for (auto& o : observers) {
4323 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004324 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004325 }
4326
4327 session_.reset();
4328
tommi0f620f42015-07-09 03:25:02 -07004329 for (auto& o : observers) {
4330 // We expect to have received a notification now even if the session was
4331 // terminated. The offer creation may or may not have succeeded, but we
4332 // must have received a notification which, so the only invalid state
4333 // is kInit.
4334 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4335 }
4336}
4337
stefanc1aeaf02015-10-15 07:26:07 -07004338TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4339 TestPacketOptions();
4340}
4341
deadbeef057ecf02016-01-20 14:30:43 -08004342// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4343// is destroyed.
4344TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4345 Init();
4346 session_.reset();
4347 EXPECT_TRUE(session_destroyed_);
4348}
4349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004350// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4351// currently fails because upon disconnection and reconnection OnIceComplete is
4352// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004353
deadbeefcbecd352015-09-23 11:50:27 -07004354INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4355 WebRtcSessionTest,
4356 testing::Values(ALREADY_GENERATED,
4357 DTLS_IDENTITY_STORE));