blob: e8234d7c1b9295ad8428b6d17fd4203e865c6c50 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Boströmd79599d2016-06-01 13:58:50 +020022#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/media/base/fakemediaengine.h"
39#include "webrtc/media/base/fakevideorenderer.h"
40#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010041#include "webrtc/media/engine/fakewebrtccall.h"
kjellandera96e2d72016-02-04 23:52:28 -080042#include "webrtc/p2p/base/stunserver.h"
43#include "webrtc/p2p/base/teststunserver.h"
44#include "webrtc/p2p/base/testturnserver.h"
45#include "webrtc/p2p/base/transportchannel.h"
46#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010047#include "webrtc/pc/channelmanager.h"
48#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
51 if (!(feature())) { \
52 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061using webrtc::CreateSessionDescriptionObserver;
62using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020064using webrtc::DtlsIdentityStoreInterface;
jbauchac8869e2015-07-03 01:36:14 -070065using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::JsepIceCandidate;
69using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000070using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::PeerConnectionInterface;
72using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070073using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000075using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000076using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000077using webrtc::kCreateChannelFailed;
78using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000082using webrtc::kSdpWithoutDtlsFingerprint;
83using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000085using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000086using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000088typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
89
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const int kClientAddrPort = 0;
91static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000092static const char kClientIPv6AddrHost1[] =
93 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000094static const char kClientAddrHost2[] = "22.22.22.22";
95static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000096static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
97static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000098static const char kTurnUsername[] = "test";
99static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
101static const char kSessionVersion[] = "1";
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Media index of candidates belonging to the first media content.
104static const int kMediaContentIndex0 = 0;
105static const char kMediaContentName0[] = "audio";
106
107// Media index of candidates belonging to the second media content.
108static const int kMediaContentIndex1 = 1;
109static const char kMediaContentName1[] = "video";
110
111static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700112// STUN timeout with all retransmissions is a total of 9500ms.
113static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000115static const char kFakeDtlsFingerprint[] =
116 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
117 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
118
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000119static const char kTooLongIceUfragPwd[] =
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
124
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000125static const char kSdpWithRtx[] =
126 "v=0\r\n"
127 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
128 "s=-\r\n"
129 "t=0 0\r\n"
130 "a=msid-semantic: WMS stream1\r\n"
131 "m=video 9 RTP/SAVPF 0 96\r\n"
132 "c=IN IP4 0.0.0.0\r\n"
133 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
134 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
135 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
136 "a=mid:video\r\n"
137 "a=sendrecv\r\n"
138 "a=rtcp-mux\r\n"
139 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
140 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
141 "a=rtpmap:0 fake_video_codec/90000\r\n"
142 "a=rtpmap:96 rtx/90000\r\n"
143 "a=fmtp:96 apt=0\r\n";
144
deadbeefab9b2d12015-10-14 11:33:11 -0700145static const char kStream1[] = "stream1";
146static const char kVideoTrack1[] = "video1";
147static const char kAudioTrack1[] = "audio1";
148
149static const char kStream2[] = "stream2";
150static const char kVideoTrack2[] = "video2";
151static const char kAudioTrack2[] = "audio2";
152
Henrik Boström87713d02015-08-25 09:53:21 +0200153enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155class MockIceObserver : public webrtc::IceObserver {
156 public:
157 MockIceObserver()
158 : oncandidatesready_(false),
159 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
160 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
161 }
162
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200163 virtual ~MockIceObserver() = default;
164
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceConnectionChange(
166 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700168 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 }
perkjdfb769d2016-02-09 03:09:43 -0800170 void OnIceGatheringChange(
171 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 // We can never transition back to "new".
173 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
174 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800175 oncandidatesready_ =
176 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 }
178
179 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800180 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000181 switch (candidate->sdp_mline_index()) {
182 case kMediaContentIndex0:
183 mline_0_candidates_.push_back(candidate->candidate());
184 break;
185 case kMediaContentIndex1:
186 mline_1_candidates_.push_back(candidate->candidate());
187 break;
188 default:
189 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // The ICE gathering state should always be Gathering when a candidate is
193 // received (or possibly Completed in the case of the final candidate).
194 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
195 }
196
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 // Some local candidates are removed.
198 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700199 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700200 num_candidates_removed_ += candidates.size();
201 }
202
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 bool oncandidatesready_;
204 std::vector<cricket::Candidate> mline_0_candidates_;
205 std::vector<cricket::Candidate> mline_1_candidates_;
206 PeerConnectionInterface::IceConnectionState ice_connection_state_;
207 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700208 std::vector<PeerConnectionInterface::IceConnectionState>
209 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700210 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211};
212
213class WebRtcSessionForTest : public webrtc::WebRtcSession {
214 public:
stefanc1aeaf02015-10-15 07:26:07 -0700215 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
danilchape9021a32016-05-17 01:52:02 -0700216 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000217 rtc::Thread* worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700218 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700220 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700221 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700222 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700223 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700224 signaling_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700225 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 RegisterIceObserver(ice_observer);
227 }
228 virtual ~WebRtcSessionForTest() {}
229
deadbeefcbecd352015-09-23 11:50:27 -0700230 // Note that these methods are only safe to use if the signaling thread
231 // is the same as the worker thread
232 cricket::TransportChannel* voice_rtp_transport_channel() {
233 return rtp_transport_channel(voice_channel());
234 }
235
236 cricket::TransportChannel* voice_rtcp_transport_channel() {
237 return rtcp_transport_channel(voice_channel());
238 }
239
240 cricket::TransportChannel* video_rtp_transport_channel() {
241 return rtp_transport_channel(video_channel());
242 }
243
244 cricket::TransportChannel* video_rtcp_transport_channel() {
245 return rtcp_transport_channel(video_channel());
246 }
247
248 cricket::TransportChannel* data_rtp_transport_channel() {
249 return rtp_transport_channel(data_channel());
250 }
251
252 cricket::TransportChannel* data_rtcp_transport_channel() {
253 return rtcp_transport_channel(data_channel());
254 }
255
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 using webrtc::WebRtcSession::SetAudioPlayout;
257 using webrtc::WebRtcSession::SetAudioSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 using webrtc::WebRtcSession::SetVideoPlayout;
259 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700260
261 private:
262 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
263 if (!ch) {
264 return nullptr;
265 }
266 return ch->transport_channel();
267 }
268
269 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
270 if (!ch) {
271 return nullptr;
272 }
273 return ch->rtcp_transport_channel();
274 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275};
276
wu@webrtc.org91053e72013-08-10 07:18:04 +0000277class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000278 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 enum State {
281 kInit,
282 kFailed,
283 kSucceeded,
284 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000285 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000286
287 // CreateSessionDescriptionObserver implementation.
288 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000289 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000290 state_ = kSucceeded;
291 }
292 virtual void OnFailure(const std::string& error) {
293 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 }
295
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000296 SessionDescriptionInterface* description() { return description_.get(); }
297
298 SessionDescriptionInterface* ReleaseDescription() {
299 return description_.release();
300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301
wu@webrtc.org91053e72013-08-10 07:18:04 +0000302 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303
wu@webrtc.org91053e72013-08-10 07:18:04 +0000304 protected:
305 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306
307 private:
kwibergd1fe2812016-04-27 06:47:29 -0700308 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310};
311
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800312class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800314 FakeAudioSource() : sink_(NULL) {}
315 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000316 if (sink_)
317 sink_->OnClose();
318 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000319
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000320 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000321
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800322 const cricket::AudioSource::Sink* sink() const { return sink_; }
323
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800325 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000326};
327
Henrik Boström87713d02015-08-25 09:53:21 +0200328class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700329 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
330 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 protected:
332 // TODO Investigate why ChannelManager crashes, if it's created
333 // after stun_server.
334 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700335 : media_engine_(new cricket::FakeMediaEngine()),
336 data_engine_(new cricket::FakeDataEngine()),
337 channel_manager_(
338 new cricket::ChannelManager(media_engine_,
339 data_engine_,
stefanc1aeaf02015-10-15 07:26:07 -0700340 rtc::Thread::Current())),
341 fake_call_(webrtc::Call::Config()),
342 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800343 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
344 rtc::Thread::Current(),
stefanc1aeaf02015-10-15 07:26:07 -0700345 channel_manager_.get())),
346 tdesc_factory_(new cricket::TransportDescriptionFactory()),
347 desc_factory_(
348 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
349 tdesc_factory_.get())),
350 pss_(new rtc::PhysicalSocketServer),
351 vss_(new rtc::VirtualSocketServer(pss_.get())),
352 fss_(new rtc::FirewallSocketServer(vss_.get())),
353 ss_scope_(fss_.get()),
354 stun_socket_addr_(
355 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
356 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
357 stun_socket_addr_)),
358 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
359 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000360 cricket::ServerAddresses stun_servers;
361 stun_servers.insert(stun_socket_addr_);
362 allocator_.reset(new cricket::BasicPortAllocator(
363 &network_manager_,
364 stun_servers,
365 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000366 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700367 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 EXPECT_TRUE(channel_manager_->Init());
369 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000370 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
372
373 void AddInterface(const SocketAddress& addr) {
374 network_manager_.AddInterface(addr);
375 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700376 void RemoveInterface(const SocketAddress& addr) {
377 network_manager_.RemoveInterface(addr);
378 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379
Henrik Boströmd79599d2016-06-01 13:58:50 +0200380 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
381 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
382 // options. When DTLS is enabled a certificate will be used if provided,
383 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200385 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 ASSERT_TRUE(session_.get() == NULL);
387 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700388 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
danilchape9021a32016-05-17 01:52:02 -0700389 rtc::Thread::Current(), allocator_.get(), &observer_));
deadbeefab9b2d12015-10-14 11:33:11 -0700390 session_->SignalDataChannelOpenMessage.connect(
391 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800392 session_->GetOnDestroyedSignal()->connect(
393 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
395 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
396 observer_.ice_connection_state_);
397 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
398 observer_.ice_gathering_state_);
399
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200400 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800401 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700402 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 }
404
deadbeefab9b2d12015-10-14 11:33:11 -0700405 void OnDataChannelOpenMessage(const std::string& label,
406 const InternalDataChannelInit& config) {
407 last_data_channel_label_ = label;
408 last_data_channel_config_ = config;
409 }
410
deadbeef057ecf02016-01-20 14:30:43 -0800411 void OnSessionDestroyed() { session_destroyed_ = true; }
412
htaa2a49d92016-03-04 02:51:39 -0800413 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000414
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000415 void InitWithBundlePolicy(
416 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800417 configuration_.bundle_policy = bundle_policy;
418 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700419 }
420
421 void InitWithRtcpMuxPolicy(
422 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
423 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800424 configuration_.rtcp_mux_policy = rtcp_mux_policy;
425 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000426 }
427
Henrik Boström87713d02015-08-25 09:53:21 +0200428 // Successfully init with DTLS; with a certificate generated and supplied or
429 // with a store that generates it for us.
430 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200431 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200432 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800433 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200434 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200435 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200436 cert_generator.reset(new FakeRTCCertificateGenerator());
437 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200438 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700439 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200440 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200441 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200442 }
443
444 // Init with DTLS with a store that will fail to generate a certificate.
445 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200446 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
447 new FakeRTCCertificateGenerator());
448 cert_generator->set_should_fail(true);
449 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000450 }
451
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 void InitWithDtmfCodec() {
453 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700454 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
455 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 std::vector<cricket::AudioCodec> codecs;
457 codecs.push_back(kTelephoneEventCodec);
458 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700459 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000460 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 }
462
deadbeefab9b2d12015-10-14 11:33:11 -0700463 void SendAudioVideoStream1() {
464 send_stream_1_ = true;
465 send_stream_2_ = false;
466 send_audio_ = true;
467 send_video_ = true;
468 }
469
470 void SendAudioVideoStream2() {
471 send_stream_1_ = false;
472 send_stream_2_ = true;
473 send_audio_ = true;
474 send_video_ = true;
475 }
476
477 void SendAudioVideoStream1And2() {
478 send_stream_1_ = true;
479 send_stream_2_ = true;
480 send_audio_ = true;
481 send_video_ = true;
482 }
483
484 void SendNothing() {
485 send_stream_1_ = false;
486 send_stream_2_ = false;
487 send_audio_ = false;
488 send_video_ = false;
489 }
490
491 void SendAudioOnlyStream2() {
492 send_stream_1_ = false;
493 send_stream_2_ = true;
494 send_audio_ = true;
495 send_video_ = false;
496 }
497
498 void SendVideoOnlyStream2() {
499 send_stream_1_ = false;
500 send_stream_2_ = true;
501 send_audio_ = false;
502 send_video_ = true;
503 }
504
505 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
506 if (send_stream_1_ && send_audio_) {
507 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
508 kStream1);
509 }
510 if (send_stream_1_ && send_video_) {
511 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
512 kStream1);
513 }
514 if (send_stream_2_ && send_audio_) {
515 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
516 kStream2);
517 }
518 if (send_stream_2_ && send_video_) {
519 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
520 kStream2);
521 }
522 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
523 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
524 data_channel_->label(),
525 data_channel_->label());
526 }
527 }
528
529 void GetOptionsForOffer(
530 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
531 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800532 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700533
deadbeefc80741f2015-10-22 13:14:45 -0700534 AddStreamsToOptions(session_options);
535 if (rtc_options.offer_to_receive_audio ==
536 RTCOfferAnswerOptions::kUndefined) {
537 session_options->recv_audio =
538 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
539 }
540 if (rtc_options.offer_to_receive_video ==
541 RTCOfferAnswerOptions::kUndefined) {
542 session_options->recv_video =
543 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
544 }
545 session_options->bundle_enabled =
546 session_options->bundle_enabled &&
547 (session_options->has_audio() || session_options->has_video() ||
548 session_options->has_data());
549
deadbeefab9b2d12015-10-14 11:33:11 -0700550 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
551 session_options->data_channel_type = cricket::DCT_SCTP;
552 }
553 }
554
htaa2a49d92016-03-04 02:51:39 -0800555 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
556 // ParseConstraintsForAnswer is used to set some defaults.
557 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700558
deadbeefc80741f2015-10-22 13:14:45 -0700559 AddStreamsToOptions(session_options);
560 session_options->bundle_enabled =
561 session_options->bundle_enabled &&
562 (session_options->has_audio() || session_options->has_video() ||
563 session_options->has_data());
564
deadbeefab9b2d12015-10-14 11:33:11 -0700565 if (session_->data_channel_type() == cricket::DCT_SCTP) {
566 session_options->data_channel_type = cricket::DCT_SCTP;
567 }
568 }
569
570 // Creates a local offer and applies it. Starts ICE.
571 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 // to decide which streams to create.
573 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000574 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 SetLocalDescriptionWithoutError(offer);
576 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
577 observer_.ice_gathering_state_,
578 kIceCandidatesTimeout);
579 }
580
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000581 SessionDescriptionInterface* CreateOffer() {
582 PeerConnectionInterface::RTCOfferAnswerOptions options;
583 options.offer_to_receive_audio =
584 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
585
586 return CreateOffer(options);
587 }
588
wu@webrtc.org91053e72013-08-10 07:18:04 +0000589 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800590 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000592 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700593 cricket::MediaSessionOptions session_options;
594 GetOptionsForOffer(options, &session_options);
595 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000596 EXPECT_TRUE_WAIT(
597 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000598 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000599 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000600 }
601
602 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800603 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000604 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000605 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800606 cricket::MediaSessionOptions session_options = options;
607 GetOptionsForAnswer(&session_options);
608 // Overwrite recv_audio and recv_video with passed-in values.
609 session_options.recv_video = options.recv_video;
610 session_options.recv_audio = options.recv_audio;
611 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 EXPECT_TRUE_WAIT(
613 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000614 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000615 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000616 }
617
htaa2a49d92016-03-04 02:51:39 -0800618 SessionDescriptionInterface* CreateAnswer() {
619 cricket::MediaSessionOptions options;
620 options.recv_video = true;
621 options.recv_audio = true;
622 return CreateAnswer(options);
623 }
624
wu@webrtc.org364f2042013-11-20 21:49:41 +0000625 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 return (session_->voice_channel() != NULL &&
627 session_->video_channel() != NULL);
628 }
629
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
631 ASSERT_TRUE(session_.get() != NULL);
632 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
633 ASSERT_TRUE(content != NULL);
634 const cricket::AudioContentDescription* audio_content =
635 static_cast<const cricket::AudioContentDescription*>(
636 content->description);
637 ASSERT_TRUE(audio_content != NULL);
638 ASSERT_EQ(1U, audio_content->cryptos().size());
639 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
640 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
641 audio_content->cryptos()[0].cipher_suite);
642 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
643 audio_content->protocol());
644
645 content = cricket::GetFirstVideoContent(sdp);
646 ASSERT_TRUE(content != NULL);
647 const cricket::VideoContentDescription* video_content =
648 static_cast<const cricket::VideoContentDescription*>(
649 content->description);
650 ASSERT_TRUE(video_content != NULL);
651 ASSERT_EQ(1U, video_content->cryptos().size());
652 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
653 video_content->cryptos()[0].cipher_suite);
654 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
655 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
656 video_content->protocol());
657 }
658
659 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
660 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
661 ASSERT_TRUE(content != NULL);
662 const cricket::AudioContentDescription* audio_content =
663 static_cast<const cricket::AudioContentDescription*>(
664 content->description);
665 ASSERT_TRUE(audio_content != NULL);
666 ASSERT_EQ(0U, audio_content->cryptos().size());
667
668 content = cricket::GetFirstVideoContent(sdp);
669 ASSERT_TRUE(content != NULL);
670 const cricket::VideoContentDescription* video_content =
671 static_cast<const cricket::VideoContentDescription*>(
672 content->description);
673 ASSERT_TRUE(video_content != NULL);
674 ASSERT_EQ(0U, video_content->cryptos().size());
675
676 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700677 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700679 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 video_content->protocol());
681 } else {
682 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
683 audio_content->protocol());
684 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
685 video_content->protocol());
686 }
687 }
688
689 // Set the internal fake description factories to do DTLS-SRTP.
690 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000691 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000693 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200694 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800695 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700696 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800697 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
699 }
700
701 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
702 bool expected) {
703 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
704 ASSERT_TRUE(audio != NULL);
705 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 const TransportInfo* video = sdp->GetTransportInfoByName("video");
707 ASSERT_TRUE(video != NULL);
708 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 }
710
711 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000712 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000714 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000715 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000717 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000719 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
720 offer);
htaa2a49d92016-03-04 02:51:39 -0800721 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 // Answer should be NULL as no crypto params in offer.
723 ASSERT_TRUE(answer == NULL);
724 }
725
726 void VerifyAnswerFromCryptoOffer() {
727 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000728 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700730 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
732 ASSERT_TRUE(offer.get() != NULL);
733 VerifyCryptoParams(offer->description());
734 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700735 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 ASSERT_TRUE(answer.get() != NULL);
737 VerifyCryptoParams(answer->description());
738 }
739
deadbeef0ed85b22016-02-23 17:24:52 -0800740 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
741 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800743 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 }
745
746 const cricket::ContentInfos& contents = desc1->contents();
747 cricket::ContentInfos::const_iterator it = contents.begin();
748
749 for (; it != contents.end(); ++it) {
750 const cricket::TransportDescription* transport_desc1 =
751 desc1->GetTransportDescriptionByName(it->name);
752 const cricket::TransportDescription* transport_desc2 =
753 desc2->GetTransportDescriptionByName(it->name);
754 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800755 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 }
757 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
758 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800759 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 }
761 }
deadbeef0ed85b22016-02-23 17:24:52 -0800762 return true;
763 }
764
765 // Compares ufrag/password only for the specified |media_type|.
766 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
767 const cricket::SessionDescription* desc2,
768 cricket::MediaType media_type) {
769 if (desc1->contents().size() != desc2->contents().size()) {
770 return false;
771 }
772
773 const cricket::ContentInfo* cinfo =
774 cricket::GetFirstMediaContent(desc1->contents(), media_type);
775 const cricket::TransportDescription* transport_desc1 =
776 desc1->GetTransportDescriptionByName(cinfo->name);
777 const cricket::TransportDescription* transport_desc2 =
778 desc2->GetTransportDescriptionByName(cinfo->name);
779 if (!transport_desc1 || !transport_desc2) {
780 return false;
781 }
782 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
783 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
784 return false;
785 }
786 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000788
789 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
790 std::string *sdp) {
791 const cricket::SessionDescription* desc = current_desc->description();
792 EXPECT_TRUE(current_desc->ToString(sdp));
793
794 const cricket::ContentInfos& contents = desc->contents();
795 cricket::ContentInfos::const_iterator it = contents.begin();
796 // Replace ufrag and pwd lines with empty strings.
797 for (; it != contents.end(); ++it) {
798 const cricket::TransportDescription* transport_desc =
799 desc->GetTransportDescriptionByName(it->name);
800 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
801 + "\r\n";
802 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
803 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000804 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000805 "", 0,
806 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000808 "", 0,
809 sdp);
810 }
811 }
812
deadbeef0ed85b22016-02-23 17:24:52 -0800813 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
814 const std::string& ufrag,
815 const std::string& pwd) {
816 cricket::SessionDescription* desc = current_desc->description();
817 for (TransportInfo& transport_info : desc->transport_infos()) {
818 cricket::TransportDescription& transport_desc =
819 transport_info.description;
820 transport_desc.ice_ufrag = ufrag;
821 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000822 }
823 }
824
deadbeef0ed85b22016-02-23 17:24:52 -0800825 // Sets ufrag/pwd for specified |media_type|.
826 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
827 cricket::MediaType media_type,
828 const std::string& ufrag,
829 const std::string& pwd) {
830 cricket::SessionDescription* desc = current_desc->description();
831 const cricket::ContentInfo* cinfo =
832 cricket::GetFirstMediaContent(desc->contents(), media_type);
833 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
834 cricket::TransportDescription* transport_desc =
835 &transport_info->description;
836 transport_desc->ice_ufrag = ufrag;
837 transport_desc->ice_pwd = pwd;
838 }
839
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 // Creates a remote offer and and applies it as a remote description,
841 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700842 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // to decide which local and remote streams to create.
844 void CreateAndSetRemoteOfferAndLocalAnswer() {
845 SessionDescriptionInterface* offer = CreateRemoteOffer();
846 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800847 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 SetLocalDescriptionWithoutError(answer);
849 }
850 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
851 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700852 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 }
854 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700855 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 SetLocalDescriptionWithoutError(desc);
857 EXPECT_EQ(expected_state, session_->state());
858 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 void SetLocalDescriptionExpectError(const std::string& action,
860 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 SessionDescriptionInterface* desc) {
862 std::string error;
863 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000864 std::string sdp_type = "local ";
865 sdp_type.append(action);
866 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_NE(std::string::npos, error.find(expected_error));
868 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000869 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
870 SessionDescriptionInterface* desc) {
871 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
872 expected_error, desc);
873 }
874 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
875 SessionDescriptionInterface* desc) {
876 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
877 expected_error, desc);
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
880 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
881 }
882 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700883 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 SetRemoteDescriptionWithoutError(desc);
885 EXPECT_EQ(expected_state, session_->state());
886 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000887 void SetRemoteDescriptionExpectError(const std::string& action,
888 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 SessionDescriptionInterface* desc) {
890 std::string error;
891 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000892 std::string sdp_type = "remote ";
893 sdp_type.append(action);
894 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_NE(std::string::npos, error.find(expected_error));
896 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000897 void SetRemoteDescriptionOfferExpectError(
898 const std::string& expected_error, SessionDescriptionInterface* desc) {
899 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
900 expected_error, desc);
901 }
902 void SetRemoteDescriptionPranswerExpectError(
903 const std::string& expected_error, SessionDescriptionInterface* desc) {
904 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
905 expected_error, desc);
906 }
907 void SetRemoteDescriptionAnswerExpectError(
908 const std::string& expected_error, SessionDescriptionInterface* desc) {
909 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
910 expected_error, desc);
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
913 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
914 SessionDescriptionInterface** nocrypto_answer) {
915 // Create a SDP without Crypto.
916 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000917 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 options.bundle_enabled = true;
919 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
920 ASSERT_TRUE(*offer != NULL);
921 VerifyCryptoParams((*offer)->description());
922
923 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
924 cricket::SEC_DISABLED);
925 EXPECT_TRUE(*nocrypto_answer != NULL);
926 }
927
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000928 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
929 SessionDescriptionInterface** nodtls_answer) {
930 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000931 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000932 options.bundle_enabled = true;
933
kwibergd1fe2812016-04-27 06:47:29 -0700934 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000935 CreateRemoteOffer(options, cricket::SEC_ENABLED));
936
937 *nodtls_answer =
938 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
939 EXPECT_TRUE(*nodtls_answer != NULL);
940 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
941 VerifyCryptoParams((*nodtls_answer)->description());
942
943 SetFactoryDtlsSrtp();
944 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
945 ASSERT_TRUE(*offer != NULL);
946 VerifyFingerprintStatus((*offer)->description(), true);
947 VerifyCryptoParams((*offer)->description());
948 }
949
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 JsepSessionDescription* CreateRemoteOfferWithVersion(
951 cricket::MediaSessionOptions options,
952 cricket::SecurePolicy secure_policy,
953 const std::string& session_version,
954 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000955 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 const cricket::SessionDescription* cricket_desc = NULL;
957 if (current_desc) {
958 cricket_desc = current_desc->description();
959 session_id = current_desc->session_id();
960 }
961
962 desc_factory_->set_secure(secure_policy);
963 JsepSessionDescription* offer(
964 new JsepSessionDescription(JsepSessionDescription::kOffer));
965 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
966 session_id, session_version)) {
967 delete offer;
968 offer = NULL;
969 }
970 return offer;
971 }
972 JsepSessionDescription* CreateRemoteOffer(
973 cricket::MediaSessionOptions options) {
974 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
975 kSessionVersion, NULL);
976 }
977 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000978 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
979 return CreateRemoteOfferWithVersion(
980 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 }
982 JsepSessionDescription* CreateRemoteOffer(
983 cricket::MediaSessionOptions options,
984 const SessionDescriptionInterface* current_desc) {
985 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
986 kSessionVersion, current_desc);
987 }
988
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000989 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
990 const char* sctp_stream_name, int new_port,
991 cricket::MediaSessionOptions options) {
992 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000993 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
994 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000995 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
996 }
997
998 // Takes ownership of offer_basis (and deletes it).
999 JsepSessionDescription* ChangeSDPSctpPort(
1000 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1001 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1002 // SessionDescription from the mutated string.
1003 const char* default_port_str = "5000";
1004 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001005 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001006 std::string offer_str;
1007 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001008 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001009 new_port_str, strlen(new_port_str),
1010 &offer_str);
1011 JsepSessionDescription* offer = new JsepSessionDescription(
1012 offer_basis->type());
1013 delete offer_basis;
1014 offer->Initialize(offer_str, NULL);
1015 return offer;
1016 }
1017
deadbeefab9b2d12015-10-14 11:33:11 -07001018 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // before this function to decide which streams to create.
1020 JsepSessionDescription* CreateRemoteOffer() {
1021 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001022 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 return CreateRemoteOffer(options, session_->remote_description());
1024 }
1025
1026 JsepSessionDescription* CreateRemoteAnswer(
1027 const SessionDescriptionInterface* offer,
1028 cricket::MediaSessionOptions options,
1029 cricket::SecurePolicy policy) {
1030 desc_factory_->set_secure(policy);
1031 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001032 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 JsepSessionDescription* answer(
1034 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1035 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1036 options, NULL),
1037 session_id, kSessionVersion)) {
1038 delete answer;
1039 answer = NULL;
1040 }
1041 return answer;
1042 }
1043
1044 JsepSessionDescription* CreateRemoteAnswer(
1045 const SessionDescriptionInterface* offer,
1046 cricket::MediaSessionOptions options) {
1047 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1048 }
1049
deadbeefab9b2d12015-10-14 11:33:11 -07001050 // Creates an answer session description.
1051 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 // to decide which streams to create.
1053 JsepSessionDescription* CreateRemoteAnswer(
1054 const SessionDescriptionInterface* offer) {
1055 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001056 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1058 }
1059
1060 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001062 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001063 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001064
1065 PeerConnectionInterface::RTCOfferAnswerOptions options;
1066 options.use_rtp_mux = bundle;
1067
1068 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1070 // and answer.
1071 SetLocalDescriptionWithoutError(offer);
1072
kwibergd1fe2812016-04-27 06:47:29 -07001073 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001074 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 std::string sdp;
1076 EXPECT_TRUE(answer->ToString(&sdp));
1077
1078 size_t expected_candidate_num = 2;
1079 if (!rtcp_mux) {
1080 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1081 // for rtp and rtcp.
1082 expected_candidate_num = 4;
1083 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 const std::string kRtcpMux = "a=rtcp-mux";
1085 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 kXRtcpMux.c_str(), kXRtcpMux.length(),
1088 &sdp);
1089 }
1090
1091 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1092 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093
1094 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001095 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1097 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001098 if (bundle) {
1099 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1100 } else {
1101 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 }
1103 }
1104 // Tests that we can only send DTMF when the dtmf codec is supported.
1105 void TestCanInsertDtmf(bool can) {
1106 if (can) {
1107 InitWithDtmfCodec();
1108 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001109 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 }
deadbeefab9b2d12015-10-14 11:33:11 -07001111 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 CreateAndSetRemoteOfferAndLocalAnswer();
1113 EXPECT_FALSE(session_->CanInsertDtmf(""));
1114 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1115 }
1116
zhihuang3a334652016-05-05 18:37:49 -07001117 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1118 const std::string& codec_name) {
1119 for (const auto& content : desc->description()->contents()) {
1120 if (static_cast<cricket::MediaContentDescription*>(content.description)
1121 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1122 const auto* mdesc =
1123 static_cast<cricket::VideoContentDescription*>(content.description);
1124 for (const auto& codec : mdesc->codecs()) {
1125 if (codec.name == codec_name) {
1126 return true;
1127 }
1128 }
1129 }
1130 }
1131 return false;
1132 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001133 // Helper class to configure loopback network and verify Best
1134 // Connection using right IP protocol for TestLoopbackCall
1135 // method. LoopbackNetworkManager applies firewall rules to block
1136 // all ping traffic once ICE completed, and remove them to observe
1137 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1138 // verifies the best connection is using the right IP protocol after
1139 // initial ICE convergences.
1140
1141 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001142 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001143 LoopbackNetworkConfiguration()
1144 : test_ipv6_network_(false),
1145 test_extra_ipv4_network_(false),
1146 best_connection_after_initial_ice_converged_(1, 0) {}
1147
1148 // Used to track the expected best connection count in each IP protocol.
1149 struct ExpectedBestConnection {
1150 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1151 : ipv4_count_(ipv4_count),
1152 ipv6_count_(ipv6_count) {}
1153
1154 int ipv4_count_;
1155 int ipv6_count_;
1156 };
1157
1158 bool test_ipv6_network_;
1159 bool test_extra_ipv4_network_;
1160 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1161
1162 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001163 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001164 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1165 }
1166
1167 private:
jbauchac8869e2015-07-03 01:36:14 -07001168 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001169 const ExpectedBestConnection& expected) const {
1170 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001171 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1172 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001173 expected.ipv4_count_);
1174 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001175 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1176 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001177 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001178 // This is used in the loopback call so there is only single host to host
1179 // candidate pair.
1180 EXPECT_EQ(metrics_observer->GetEnumCounter(
1181 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1182 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001183 0);
1184 EXPECT_EQ(metrics_observer->GetEnumCounter(
1185 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1186 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001187 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001188 }
1189 };
1190
1191 class LoopbackNetworkManager {
1192 public:
1193 LoopbackNetworkManager(WebRtcSessionTest* session,
1194 const LoopbackNetworkConfiguration& config)
1195 : config_(config) {
1196 session->AddInterface(
1197 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1198 if (config_.test_extra_ipv4_network_) {
1199 session->AddInterface(
1200 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1201 }
1202 if (config_.test_ipv6_network_) {
1203 session->AddInterface(
1204 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1205 }
1206 }
1207
1208 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1209 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1210 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1211 if (config_.test_extra_ipv4_network_) {
1212 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1213 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1214 }
1215 if (config_.test_ipv6_network_) {
1216 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1217 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1218 }
1219 }
1220
1221 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1222
1223 private:
1224 LoopbackNetworkConfiguration config_;
1225 };
1226
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227 // The method sets up a call from the session to itself, in a loopback
1228 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001229 // disconnection, and then a permanent disconnection.
1230 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1232 // While running the call, this method also checks if the session goes through
1233 // the correct sequence of ICE states when a connection is established,
1234 // broken, and re-established.
1235 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001236 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1237 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001239
stefanc1aeaf02015-10-15 07:26:07 -07001240 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001241 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001242 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001243 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244
1245 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1246 observer_.ice_gathering_state_);
1247 SetLocalDescriptionWithoutError(offer);
1248 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1249 observer_.ice_connection_state_);
1250 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001251 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1253 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001254 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255
1256 std::string sdp;
1257 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001258 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1259 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 ASSERT_TRUE(desc != NULL);
1261 SetRemoteDescriptionWithoutError(desc);
1262
1263 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001264 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001265
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001266 // The ice connection state is "Connected" too briefly to catch in a test.
1267 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001268 observer_.ice_connection_state_, kIceCandidatesTimeout);
1269 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270
stefanc1aeaf02015-10-15 07:26:07 -07001271 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1272 LoopbackNetworkManager loopback_network_manager(this, config);
1273 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001274 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 // Adding firewall rule to block ping requests, which should cause
1276 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001277
1278 loopback_network_manager.ApplyFirewallRules(fss_.get());
1279
1280 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1282 observer_.ice_connection_state_,
1283 kIceCandidatesTimeout);
1284
jbauchac8869e2015-07-03 01:36:14 -07001285 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001286
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001288 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001290 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001291 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 observer_.ice_connection_state_,
1293 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001294
1295 // Now we block ping requests and wait until the ICE connection transitions
1296 // to the Failed state. This will take at least 30 seconds because it must
1297 // wait for the Port to timeout.
1298 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001299
1300 loopback_network_manager.ApplyFirewallRules(fss_.get());
1301 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001302 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001303 observer_.ice_connection_state_,
1304 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 }
1306
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001307 void TestLoopbackCall() {
1308 LoopbackNetworkConfiguration config;
1309 TestLoopbackCall(config);
1310 }
1311
stefanc1aeaf02015-10-15 07:26:07 -07001312 void TestPacketOptions() {
1313 media_controller_.reset(
1314 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1315 LoopbackNetworkConfiguration config;
1316 LoopbackNetworkManager loopback_network_manager(this, config);
1317
1318 SetupLoopbackCall();
1319
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001320 // Wait for channel to be ready for sending.
1321 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001322 uint8_t test_packet[15] = {0};
1323 rtc::PacketOptions options;
1324 options.packet_id = 10;
1325 media_engine_->GetVideoChannel(0)
1326 ->SendRtp(test_packet, sizeof(test_packet), options);
1327
1328 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001329 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1330 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001331 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1332 }
1333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1335 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001336 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1337 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001338
1339 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001340 std::vector<cricket::AudioCodec> codecs =
1341 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 codecs.push_back(kCNCodec1);
1343 codecs.push_back(kCNCodec2);
1344 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001345 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 }
1347
1348 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1349 const cricket::ContentDescription* description = content->description;
1350 ASSERT(description != NULL);
1351 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001352 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353 ASSERT(audio_content_desc != NULL);
1354 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1355 if (audio_content_desc->codecs()[i].name == "CN")
1356 return false;
1357 }
1358 return true;
1359 }
1360
deadbeefab9b2d12015-10-14 11:33:11 -07001361 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001362 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001363 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001364 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1365 data_channel_ = DataChannel::Create(
1366 session_.get(), session_->data_channel_type(), "datachannel", dci);
1367 }
1368
1369 void SetLocalDescriptionWithDataChannel() {
1370 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001371 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 SetLocalDescriptionWithoutError(offer);
1373 }
1374
wu@webrtc.org91053e72013-08-10 07:18:04 +00001375 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001376 RTCCertificateGenerationMethod cert_gen_method,
1377 CreateSessionDescriptionRequest::Type type) {
1378 InitWithDtls(cert_gen_method);
1379 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1380 }
1381
1382 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1383 CreateSessionDescriptionRequest::Type type) {
1384 InitWithDtlsIdentityGenFail();
1385 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1386 }
1387
1388 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001390 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001391 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001392 if (type == CreateSessionDescriptionRequest::kAnswer) {
1393 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001394 std::unique_ptr<JsepSessionDescription> offer(
1395 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001396 ASSERT_TRUE(offer.get() != NULL);
1397 SetRemoteDescriptionWithoutError(offer.release());
1398 }
1399
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001400 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001401 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001402 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001403 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001404 observers[kNumber];
1405 for (int i = 0; i < kNumber; ++i) {
1406 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1407 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001408 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001409 } else {
htaa2a49d92016-03-04 02:51:39 -08001410 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001411 }
1412 }
1413
1414 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1415 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1416 WebRtcSessionCreateSDPObserverForTest::kFailed;
1417
1418 for (int i = 0; i < kNumber; ++i) {
1419 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1420 if (success) {
1421 EXPECT_TRUE(observers[i]->description() != NULL);
1422 } else {
1423 EXPECT_TRUE(observers[i]->description() == NULL);
1424 }
1425 }
1426 }
1427
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001428 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001429 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001430 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001431 turn_server.credentials = credentials;
1432 turn_server.ports.push_back(
1433 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1434 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001435 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001436 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001437 }
1438
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 cricket::FakeMediaEngine* media_engine_;
1440 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001441 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001442 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001443 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1444 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1445 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1446 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1447 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1448 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001449 rtc::SocketServerScope ss_scope_;
1450 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001451 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001452 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001453 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001454 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001455 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001456 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001457 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 MockIceObserver observer_;
1459 cricket::FakeVideoMediaChannel* video_channel_;
1460 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001461 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001462 // The following flags affect options created for CreateOffer/CreateAnswer.
1463 bool send_stream_1_ = false;
1464 bool send_stream_2_ = false;
1465 bool send_audio_ = false;
1466 bool send_video_ = false;
1467 rtc::scoped_refptr<DataChannel> data_channel_;
1468 // Last values received from data channel creation signal.
1469 std::string last_data_channel_label_;
1470 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001471 bool session_destroyed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472};
1473
Henrik Boström87713d02015-08-25 09:53:21 +02001474TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1475 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001476 // SDES is disabled when DTLS is on.
1477 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478}
1479
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001480TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001481 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001482 // SDES is required if DTLS is off.
1483 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001484}
1485
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1487 TestSessionCandidatesWithBundleRtcpMux(false, false);
1488}
1489
1490// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1491// with rtcp-mux and/or bundle.
1492TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1493 TestSessionCandidatesWithBundleRtcpMux(false, true);
1494}
1495
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1497 TestSessionCandidatesWithBundleRtcpMux(true, true);
1498}
1499
1500TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001501 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1502 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001503 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001504 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 InitiateCall();
1506 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1507 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1508 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1509}
1510
deadbeeff5f03e82016-06-06 11:16:06 -07001511TEST_F(WebRtcSessionTest, TestStunError) {
1512 rtc::ScopedFakeClock clock;
1513
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001514 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1515 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001516 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001517 rtc::FP_UDP,
1518 rtc::FD_ANY,
1519 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001520 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001521 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001523 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001524 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1526 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001527 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1528 // warning.
1529 session_->Close();
1530 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531}
1532
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001533TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001534 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001535 SessionDescriptionInterface* offer = NULL;
1536 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1537 std::string unknown_action;
1538 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1539 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1540}
1541
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542// Test creating offers and receive answers and make sure the
1543// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001544TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001545 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001546 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001547 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 const std::string session_id_orig = offer->session_id();
1549 const std::string session_version_orig = offer->session_version();
1550 SetLocalDescriptionWithoutError(offer);
1551
deadbeefab9b2d12015-10-14 11:33:11 -07001552 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 SessionDescriptionInterface* answer =
1554 CreateRemoteAnswer(session_->local_description());
1555 SetRemoteDescriptionWithoutError(answer);
1556
1557 video_channel_ = media_engine_->GetVideoChannel(0);
1558 voice_channel_ = media_engine_->GetVoiceChannel(0);
1559
1560 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1561 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1562
1563 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1564 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1565
1566 ASSERT_EQ(1u, video_channel_->send_streams().size());
1567 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1568 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1569 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1570
1571 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001572 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001573 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574
1575 // Verify the session id is the same and the session version is
1576 // increased.
1577 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001578 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1579 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580
1581 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001582 EXPECT_EQ(0u, video_channel_->send_streams().size());
1583 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584
deadbeefab9b2d12015-10-14 11:33:11 -07001585 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 answer = CreateRemoteAnswer(session_->local_description());
1587 SetRemoteDescriptionWithoutError(answer);
1588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 // Make sure the receive streams have not changed.
1590 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1591 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1592 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1593 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1594}
1595
1596// Test receiving offers and creating answers and make sure the
1597// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001599 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001600 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001601 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001602 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 SetRemoteDescriptionWithoutError(offer);
1604
deadbeefab9b2d12015-10-14 11:33:11 -07001605 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001606 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001607 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 SetLocalDescriptionWithoutError(answer);
1609
1610 const std::string session_id_orig = answer->session_id();
1611 const std::string session_version_orig = answer->session_version();
1612
1613 video_channel_ = media_engine_->GetVideoChannel(0);
1614 voice_channel_ = media_engine_->GetVoiceChannel(0);
1615
htaa2a49d92016-03-04 02:51:39 -08001616 ASSERT_TRUE(video_channel_);
1617 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1619 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1620
1621 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1622 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1623
1624 ASSERT_EQ(1u, video_channel_->send_streams().size());
1625 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1626 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1627 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1628
deadbeefab9b2d12015-10-14 11:33:11 -07001629 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001630 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 SetRemoteDescriptionWithoutError(offer);
1632
1633 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001634 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001635 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636
1637 // Verify the session id is the same and the session version is
1638 // increased.
1639 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001640 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1641 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 SetLocalDescriptionWithoutError(answer);
1643
1644 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1645 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1646 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1647 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1648 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1649 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1650
1651 // Make sure we have no send streams.
1652 EXPECT_EQ(0u, video_channel_->send_streams().size());
1653 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1654}
1655
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001656TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001657 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001658 media_engine_->set_fail_create_channel(true);
1659
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001661 ASSERT_TRUE(offer != NULL);
1662 // SetRemoteDescription and SetLocalDescription will take the ownership of
1663 // the offer.
1664 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001665 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001666 ASSERT_TRUE(offer != NULL);
1667 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1668}
1669
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670//
1671// Tests for creating/setting SDP under different SDES/DTLS polices:
1672//
1673// --DTLS off and SDES on
1674// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1675// set local/remote offer/answer with crypto --> success
1676// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1677// failure
1678// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1679// failure
1680// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1681// failure
1682//
1683// --DTLS on and SDES off
1684// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1685// set local/remote offer/answer with DTLS fingerprint --> success
1686// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1687// fingerprint --> failure
1688// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1689// --> failure
1690// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1691// --> failure
1692//
1693// --Encryption disabled: DTLS off and SDES off
1694// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1695// answer without SDES or DTLS --> success
1696// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1697// answer without SDES or DTLS --> success
1698//
1699
1700// Test that we return a failure when applying a remote/local offer that doesn't
1701// have cryptos enabled when DTLS is off.
1702TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001703 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001705 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 JsepSessionDescription* offer = CreateRemoteOffer(
1707 options, cricket::SEC_DISABLED);
1708 ASSERT_TRUE(offer != NULL);
1709 VerifyNoCryptoParams(offer->description(), false);
1710 // SetRemoteDescription and SetLocalDescription will take the ownership of
1711 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001712 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1714 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001715 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716}
1717
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001718// Test that we return a failure when applying a local answer that doesn't have
1719// cryptos enabled when DTLS is off.
1720TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001721 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 SessionDescriptionInterface* offer = NULL;
1723 SessionDescriptionInterface* answer = NULL;
1724 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1725 // SetRemoteDescription and SetLocalDescription will take the ownership of
1726 // the offer.
1727 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001728 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729}
1730
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731// Test we will return fail when apply an remote answer that doesn't have
1732// crypto enabled when DTLS is off.
1733TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001734 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 SessionDescriptionInterface* offer = NULL;
1736 SessionDescriptionInterface* answer = NULL;
1737 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1738 // SetRemoteDescription and SetLocalDescription will take the ownership of
1739 // the offer.
1740 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742}
1743
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1745// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001746TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001747 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001748 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001749 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 SetFactoryDtlsSrtp();
1751 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001752 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001753 JsepSessionDescription* offer =
1754 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 ASSERT_TRUE(offer != NULL);
1756 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
1759 // SetRemoteDescription will take the ownership of the offer.
1760 SetRemoteDescriptionWithoutError(offer);
1761
1762 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001763 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 ASSERT_TRUE(answer != NULL);
1765 VerifyFingerprintStatus(answer->description(), true);
1766 // Check that we don't have an a=crypto line in the answer.
1767 VerifyNoCryptoParams(answer->description(), true);
1768
1769 // Now set the local description, which should work, even without a=crypto.
1770 SetLocalDescriptionWithoutError(answer);
1771}
1772
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001773// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1774// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001775TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001776 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001777 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001778 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001779 SetFactoryDtlsSrtp();
1780
1781 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001782 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 ASSERT_TRUE(offer != NULL);
1784 VerifyFingerprintStatus(offer->description(), true);
1785 // Check that we don't have an a=crypto line in the offer.
1786 VerifyNoCryptoParams(offer->description(), true);
1787
1788 // Now set the local description, which should work, even without a=crypto.
1789 SetLocalDescriptionWithoutError(offer);
1790
1791 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001792 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001793 JsepSessionDescription* answer =
1794 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1795 ASSERT_TRUE(answer != NULL);
1796 VerifyFingerprintStatus(answer->description(), true);
1797 VerifyNoCryptoParams(answer->description(), true);
1798
1799 // SetRemoteDescription will take the ownership of the answer.
1800 SetRemoteDescriptionWithoutError(answer);
1801}
1802
1803// Test that if we support DTLS and the other side didn't offer a fingerprint,
1804// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001805TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001806 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001807 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001809 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001810 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 JsepSessionDescription* offer = CreateRemoteOffer(
1812 options, cricket::SEC_REQUIRED);
1813 ASSERT_TRUE(offer != NULL);
1814 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001815 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001817 // SetRemoteDescription will take the ownership of the offer.
1818 SetRemoteDescriptionOfferExpectError(
1819 kSdpWithoutDtlsFingerprint, offer);
1820
1821 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1822 // SetLocalDescription will take the ownership of the offer.
1823 SetLocalDescriptionOfferExpectError(
1824 kSdpWithoutDtlsFingerprint, offer);
1825}
1826
1827// Test that we return a failure when applying a local answer that doesn't have
1828// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001829TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001830 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001831 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 SessionDescriptionInterface* offer = NULL;
1833 SessionDescriptionInterface* answer = NULL;
1834 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1835
1836 // SetRemoteDescription and SetLocalDescription will take the ownership of
1837 // the offer and answer.
1838 SetRemoteDescriptionWithoutError(offer);
1839 SetLocalDescriptionAnswerExpectError(
1840 kSdpWithoutDtlsFingerprint, answer);
1841}
1842
1843// Test that we return a failure when applying a remote answer that doesn't have
1844// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001845TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001846 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001847 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001848 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001850 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001851 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001852 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001853 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001854 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855
1856 // SetRemoteDescription and SetLocalDescription will take the ownership of
1857 // the offer and answer.
1858 SetLocalDescriptionWithoutError(offer);
1859 SetRemoteDescriptionAnswerExpectError(
1860 kSdpWithoutDtlsFingerprint, answer);
1861}
1862
1863// Test that we create a local offer without SDES or DTLS and accept a remote
1864// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001865TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001866 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001868 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001869
1870 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001871 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001872 ASSERT_TRUE(offer != NULL);
1873 VerifyFingerprintStatus(offer->description(), false);
1874 // Check that we don't have an a=crypto line in the offer.
1875 VerifyNoCryptoParams(offer->description(), false);
1876
1877 // Now set the local description, which should work, even without a=crypto.
1878 SetLocalDescriptionWithoutError(offer);
1879
1880 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001881 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 JsepSessionDescription* answer =
1883 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1884 ASSERT_TRUE(answer != NULL);
1885 VerifyFingerprintStatus(answer->description(), false);
1886 VerifyNoCryptoParams(answer->description(), false);
1887
1888 // SetRemoteDescription will take the ownership of the answer.
1889 SetRemoteDescriptionWithoutError(answer);
1890}
1891
1892// Test that we create a local answer without SDES or DTLS and accept a remote
1893// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001894TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001895 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001896 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001897
1898 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001899 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900 JsepSessionDescription* offer =
1901 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1902 ASSERT_TRUE(offer != NULL);
1903 VerifyFingerprintStatus(offer->description(), false);
1904 VerifyNoCryptoParams(offer->description(), false);
1905
1906 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 SetRemoteDescriptionWithoutError(offer);
1908
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001909 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001910 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 ASSERT_TRUE(answer != NULL);
1912 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001913 // Check that we don't have an a=crypto line in the answer.
1914 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 SetLocalDescriptionWithoutError(answer);
1918}
1919
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001920// Test that we can create and set an answer correctly when different
1921// SSL roles have been negotiated for different transports.
1922// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1923TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1924 SendAudioVideoStream1();
1925 InitWithDtls(GetParam());
1926 SetFactoryDtlsSrtp();
1927
1928 SessionDescriptionInterface* offer = CreateOffer();
1929 SetLocalDescriptionWithoutError(offer);
1930
1931 cricket::MediaSessionOptions options;
1932 options.recv_video = true;
1933
1934 // First, negotiate different SSL roles.
1935 SessionDescriptionInterface* answer =
1936 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1937 TransportInfo* audio_transport_info =
1938 answer->description()->GetTransportInfoByName("audio");
1939 audio_transport_info->description.connection_role =
1940 cricket::CONNECTIONROLE_ACTIVE;
1941 TransportInfo* video_transport_info =
1942 answer->description()->GetTransportInfoByName("video");
1943 video_transport_info->description.connection_role =
1944 cricket::CONNECTIONROLE_PASSIVE;
1945 SetRemoteDescriptionWithoutError(answer);
1946
1947 // Now create an offer in the reverse direction, and ensure the initial
1948 // offerer responds with an answer with correct SSL roles.
1949 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1950 kSessionVersion,
1951 session_->remote_description());
1952 SetRemoteDescriptionWithoutError(offer);
1953
htaa2a49d92016-03-04 02:51:39 -08001954 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001955 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1956 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1957 audio_transport_info->description.connection_role);
1958 video_transport_info = answer->description()->GetTransportInfoByName("video");
1959 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1960 video_transport_info->description.connection_role);
1961 SetLocalDescriptionWithoutError(answer);
1962
1963 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1964 // audio is transferred over to video in the answer that completes the BUNDLE
1965 // negotiation.
1966 options.bundle_enabled = true;
1967 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1968 kSessionVersion,
1969 session_->remote_description());
1970 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001971 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001972 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1973 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1974 audio_transport_info->description.connection_role);
1975 video_transport_info = answer->description()->GetTransportInfoByName("video");
1976 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1977 video_transport_info->description.connection_role);
1978 SetLocalDescriptionWithoutError(answer);
1979}
1980
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001982 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001983 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetLocalDescriptionWithoutError(offer);
1987
1988 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001989 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 SetLocalDescriptionWithoutError(offer2);
1991}
1992
1993TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001994 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001995 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001997 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 SetRemoteDescriptionWithoutError(offer);
1999
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 SetRemoteDescriptionWithoutError(offer2);
2002}
2003
2004TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002005 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002006 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002007 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002009 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002010 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2011 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012}
2013
2014TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002015 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002016 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002017 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002019 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002020 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002021 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022}
2023
2024TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002025 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002026 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002028 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029
htaa2a49d92016-03-04 02:51:39 -08002030 JsepSessionDescription* pranswer =
2031 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002033 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034
deadbeefab9b2d12015-10-14 11:33:11 -07002035 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002036 JsepSessionDescription* pranswer2 =
2037 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2039
deadbeefd59daf82015-10-14 15:02:44 -07002040 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041
deadbeefab9b2d12015-10-14 11:33:11 -07002042 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002043 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002044 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045}
2046
2047TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002050 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002051 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052
2053 JsepSessionDescription* pranswer =
2054 CreateRemoteAnswer(session_->local_description());
2055 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2056
2057 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002058 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059
deadbeefab9b2d12015-10-14 11:33:11 -07002060 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 JsepSessionDescription* pranswer2 =
2062 CreateRemoteAnswer(session_->local_description());
2063 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2064
2065 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002066 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067
deadbeefab9b2d12015-10-14 11:33:11 -07002068 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 SessionDescriptionInterface* answer =
2070 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002071 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
2074TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002075 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002076 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002077 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 SessionDescriptionInterface* answer =
2080 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002081 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2082 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083}
2084
2085TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002086 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002087 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002088 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002089
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 SessionDescriptionInterface* answer =
2091 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002092 SetRemoteDescriptionAnswerExpectError(
2093 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094}
2095
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002096// Tests that the remote candidates are added and removed successfully.
2097TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002101 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2102 "", "", "host", 0, "");
2103 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2105
deadbeefd59daf82015-10-14 15:02:44 -07002106 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2108
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002109 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002111
2112 // Fail since we have not set a remote description.
2113 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2116 session_->local_description());
2117 SetRemoteDescriptionWithoutError(answer);
2118
deadbeefd59daf82015-10-14 15:02:44 -07002119 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2120 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002121 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002122 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2123 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 // Verifying the candidates are copied properly from internal vector.
2126 const SessionDescriptionInterface* remote_desc =
2127 session_->remote_description();
2128 ASSERT_TRUE(remote_desc != NULL);
2129 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2130 const IceCandidateCollection* candidates =
2131 remote_desc->candidates(kMediaContentIndex0);
2132 ASSERT_EQ(2u, candidates->count());
2133 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2134 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2135 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2136 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2137
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002138 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2139 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 candidate.set_component(2);
2141 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002143 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144
2145 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2146 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002147
2148 // Remove candidate1 and candidate2
2149 std::vector<cricket::Candidate> remote_candidates;
2150 remote_candidates.push_back(ice_candidate1.candidate());
2151 remote_candidates.push_back(ice_candidate2.candidate());
2152 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2153 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154}
2155
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002156// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157// that it is retained if the remote session description is changed.
2158TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002159 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 cricket::Candidate candidate1;
2161 candidate1.set_component(1);
2162 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2163 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002164 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 CreateAndSetRemoteOfferAndLocalAnswer();
2166
2167 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2168 const SessionDescriptionInterface* remote_desc =
2169 session_->remote_description();
2170 ASSERT_TRUE(remote_desc != NULL);
2171 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2172 const IceCandidateCollection* candidates =
2173 remote_desc->candidates(kMediaContentIndex0);
2174 ASSERT_EQ(1u, candidates->count());
2175 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2176
2177 // Update the RemoteSessionDescription with a new session description and
2178 // a candidate and check that the new remote session description contains both
2179 // candidates.
2180 SessionDescriptionInterface* offer = CreateRemoteOffer();
2181 cricket::Candidate candidate2;
2182 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2183 candidate2);
2184 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2185 SetRemoteDescriptionWithoutError(offer);
2186
2187 remote_desc = session_->remote_description();
2188 ASSERT_TRUE(remote_desc != NULL);
2189 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2190 candidates = remote_desc->candidates(kMediaContentIndex0);
2191 ASSERT_EQ(2u, candidates->count());
2192 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2193 // Username and password have be updated with the TransportInfo of the
2194 // SessionDescription, won't be equal to the original one.
2195 candidate2.set_username(candidates->at(0)->candidate().username());
2196 candidate2.set_password(candidates->at(0)->candidate().password());
2197 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2198 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2199 // No need to verify the username and password.
2200 candidate1.set_username(candidates->at(1)->candidate().username());
2201 candidate1.set_password(candidates->at(1)->candidate().password());
2202 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2203
2204 // Test that the candidate is ignored if we can add the same candidate again.
2205 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2206}
2207
2208// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002209// that they are retained if the local session description is changed. And if
2210// continual gathering is enabled, they are removed from the local session
2211// description when the network is down.
2212TEST_F(WebRtcSessionTest,
2213 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002214 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002215 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002216 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 CreateAndSetRemoteOfferAndLocalAnswer();
2218
2219 const SessionDescriptionInterface* local_desc = session_->local_description();
2220 const IceCandidateCollection* candidates =
2221 local_desc->candidates(kMediaContentIndex0);
2222 ASSERT_TRUE(candidates != NULL);
2223 EXPECT_EQ(0u, candidates->count());
2224
2225 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2226
2227 local_desc = session_->local_description();
2228 candidates = local_desc->candidates(kMediaContentIndex0);
2229 ASSERT_TRUE(candidates != NULL);
2230 EXPECT_LT(0u, candidates->count());
2231 candidates = local_desc->candidates(1);
2232 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002233 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234
2235 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002236 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 CreateAndSetRemoteOfferAndLocalAnswer();
2238
2239 local_desc = session_->local_description();
2240 candidates = local_desc->candidates(kMediaContentIndex0);
2241 ASSERT_TRUE(candidates != NULL);
2242 EXPECT_LT(0u, candidates->count());
2243 candidates = local_desc->candidates(1);
2244 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002245 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002246
2247 candidates = local_desc->candidates(kMediaContentIndex0);
2248 size_t num_local_candidates = candidates->count();
2249 // Enable Continual Gathering
2250 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2251 // Bring down the network interface to trigger candidate removals.
2252 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2253 // Verify that all local candidates are removed.
2254 EXPECT_EQ(0, observer_.num_candidates_removed_);
2255 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2256 kIceCandidatesTimeout);
2257 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2258}
2259
2260// Tests that if continual gathering is disabled, local candidates won't be
2261// removed when the interface is turned down.
2262TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2263 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2264 Init();
2265 SendAudioVideoStream1();
2266 CreateAndSetRemoteOfferAndLocalAnswer();
2267
2268 const SessionDescriptionInterface* local_desc = session_->local_description();
2269 const IceCandidateCollection* candidates =
2270 local_desc->candidates(kMediaContentIndex0);
2271 ASSERT_TRUE(candidates != NULL);
2272 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2273
2274 size_t num_local_candidates = candidates->count();
2275 EXPECT_LT(0u, num_local_candidates);
2276 // By default, Continual Gathering is disabled.
2277 // Bring down the network interface.
2278 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2279 // Verify that the local candidates are not removed.
2280 rtc::Thread::Current()->ProcessMessages(1000);
2281 EXPECT_EQ(0, observer_.num_candidates_removed_);
2282 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283}
2284
2285// Test that we can set a remote session description with remote candidates.
2286TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002287 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288
2289 cricket::Candidate candidate1;
2290 candidate1.set_component(1);
2291 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2292 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002293 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002294 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295
2296 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2297 SetRemoteDescriptionWithoutError(offer);
2298
2299 const SessionDescriptionInterface* remote_desc =
2300 session_->remote_description();
2301 ASSERT_TRUE(remote_desc != NULL);
2302 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2303 const IceCandidateCollection* candidates =
2304 remote_desc->candidates(kMediaContentIndex0);
2305 ASSERT_EQ(1u, candidates->count());
2306 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2307
htaa2a49d92016-03-04 02:51:39 -08002308 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 SetLocalDescriptionWithoutError(answer);
2310}
2311
2312// Test that offers and answers contains ice candidates when Ice candidates have
2313// been gathered.
2314TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002315 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002316 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002317 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 // Ice is started but candidates are not provided until SetLocalDescription
2319 // is called.
2320 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2321 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2322 CreateAndSetRemoteOfferAndLocalAnswer();
2323 // Wait until at least one local candidate has been collected.
2324 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2325 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326
kwibergd1fe2812016-04-27 06:47:29 -07002327 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2330 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331
2332 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2333 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002334 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2336 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 SetLocalDescriptionWithoutError(answer);
2338}
2339
2340// Verifies TransportProxy and media channels are created with content names
2341// present in the SessionDescription.
2342TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002343 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002344 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002345 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346
2347 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002348 // "video". Goal is to modify these content names and verify transport
2349 // channels
2350 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 // present in SDP.
2352 std::string sdp;
2353 EXPECT_TRUE(offer->ToString(&sdp));
2354 const std::string kAudioMid = "a=mid:audio";
2355 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2356 const std::string kVideoMid = "a=mid:video";
2357 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2358
2359 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002360 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 kAudioMidReplaceStr.c_str(),
2362 kAudioMidReplaceStr.length(),
2363 &sdp);
2364 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002365 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 kVideoMidReplaceStr.c_str(),
2367 kVideoMidReplaceStr.length(),
2368 &sdp);
2369
2370 SessionDescriptionInterface* modified_offer =
2371 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2372
2373 SetRemoteDescriptionWithoutError(modified_offer);
2374
htaa2a49d92016-03-04 02:51:39 -08002375 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 SetLocalDescriptionWithoutError(answer);
2377
deadbeefcbecd352015-09-23 11:50:27 -07002378 cricket::TransportChannel* voice_transport_channel =
2379 session_->voice_rtp_transport_channel();
2380 EXPECT_TRUE(voice_transport_channel != NULL);
2381 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2382 cricket::TransportChannel* video_transport_channel =
2383 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002384 ASSERT_TRUE(video_transport_channel != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002385 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2387 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2388}
2389
2390// Test that an offer contains the correct media content descriptions based on
2391// the send streams when no constraints have been set.
2392TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002393 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002394 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 ASSERT_TRUE(offer != NULL);
2397 const cricket::ContentInfo* content =
2398 cricket::GetFirstAudioContent(offer->description());
2399 EXPECT_TRUE(content != NULL);
2400 content = cricket::GetFirstVideoContent(offer->description());
2401 EXPECT_TRUE(content == NULL);
2402}
2403
2404// Test that an offer contains the correct media content descriptions based on
2405// the send streams when no constraints have been set.
2406TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002407 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002409 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002410 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002411
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 const cricket::ContentInfo* content =
2413 cricket::GetFirstAudioContent(offer->description());
2414 EXPECT_TRUE(content != NULL);
2415 content = cricket::GetFirstVideoContent(offer->description());
2416 EXPECT_TRUE(content == NULL);
2417
2418 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002419 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002420 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 content = cricket::GetFirstAudioContent(offer->description());
2422 EXPECT_TRUE(content != NULL);
2423 content = cricket::GetFirstVideoContent(offer->description());
2424 EXPECT_TRUE(content != NULL);
2425}
2426
2427// Test that an offer contains no media content descriptions if
2428// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2429TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002430 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002431 PeerConnectionInterface::RTCOfferAnswerOptions options;
2432 options.offer_to_receive_audio = 0;
2433 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434
kwibergd1fe2812016-04-27 06:47:29 -07002435 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002436
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 ASSERT_TRUE(offer != NULL);
2438 const cricket::ContentInfo* content =
2439 cricket::GetFirstAudioContent(offer->description());
2440 EXPECT_TRUE(content == NULL);
2441 content = cricket::GetFirstVideoContent(offer->description());
2442 EXPECT_TRUE(content == NULL);
2443}
2444
2445// Test that an offer contains only audio media content descriptions if
2446// kOfferToReceiveAudio constraints are set to true.
2447TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002448 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002449 PeerConnectionInterface::RTCOfferAnswerOptions options;
2450 options.offer_to_receive_audio =
2451 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2452
kwibergd1fe2812016-04-27 06:47:29 -07002453 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454
2455 const cricket::ContentInfo* content =
2456 cricket::GetFirstAudioContent(offer->description());
2457 EXPECT_TRUE(content != NULL);
2458 content = cricket::GetFirstVideoContent(offer->description());
2459 EXPECT_TRUE(content == NULL);
2460}
2461
2462// Test that an offer contains audio and video media content descriptions if
2463// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2464TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002465 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002467 PeerConnectionInterface::RTCOfferAnswerOptions options;
2468 options.offer_to_receive_audio =
2469 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2470 options.offer_to_receive_video =
2471 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2472
kwibergd1fe2812016-04-27 06:47:29 -07002473 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 const cricket::ContentInfo* content =
2476 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002477 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 content = cricket::GetFirstVideoContent(offer->description());
2480 EXPECT_TRUE(content != NULL);
2481
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002482 // Sets constraints to false and verifies that audio/video contents are
2483 // removed.
2484 options.offer_to_receive_audio = 0;
2485 options.offer_to_receive_video = 0;
2486 offer.reset(CreateOffer(options));
2487
2488 content = cricket::GetFirstAudioContent(offer->description());
2489 EXPECT_TRUE(content == NULL);
2490 content = cricket::GetFirstVideoContent(offer->description());
2491 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492}
2493
2494// Test that an answer can not be created if the last remote description is not
2495// an offer.
2496TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002497 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002498 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 SetLocalDescriptionWithoutError(offer);
2500 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2501 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002502 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503}
2504
2505// Test that an answer contains the correct media content descriptions when no
2506// constraints have been set.
2507TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002508 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002510 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002512 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 const cricket::ContentInfo* content =
2514 cricket::GetFirstAudioContent(answer->description());
2515 ASSERT_TRUE(content != NULL);
2516 EXPECT_FALSE(content->rejected);
2517
2518 content = cricket::GetFirstVideoContent(answer->description());
2519 ASSERT_TRUE(content != NULL);
2520 EXPECT_FALSE(content->rejected);
2521}
2522
2523// Test that an answer contains the correct media content descriptions when no
2524// constraints have been set and the offer only contain audio.
2525TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002526 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 // Create a remote offer with audio only.
2528 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002529
kwibergd1fe2812016-04-27 06:47:29 -07002530 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2532 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2533
2534 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002535 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 const cricket::ContentInfo* content =
2537 cricket::GetFirstAudioContent(answer->description());
2538 ASSERT_TRUE(content != NULL);
2539 EXPECT_FALSE(content->rejected);
2540
2541 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2542}
2543
2544// Test that an answer contains the correct media content descriptions when no
2545// constraints have been set.
2546TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002547 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 SetRemoteDescriptionWithoutError(offer.release());
2551 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002552 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002553 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 const cricket::ContentInfo* content =
2555 cricket::GetFirstAudioContent(answer->description());
2556 ASSERT_TRUE(content != NULL);
2557 EXPECT_FALSE(content->rejected);
2558
2559 content = cricket::GetFirstVideoContent(answer->description());
2560 ASSERT_TRUE(content != NULL);
2561 EXPECT_FALSE(content->rejected);
2562}
2563
2564// Test that an answer contains the correct media content descriptions when
2565// constraints have been set but no stream is sent.
2566TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002567 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002569 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 SetRemoteDescriptionWithoutError(offer.release());
2571
htaa2a49d92016-03-04 02:51:39 -08002572 cricket::MediaSessionOptions session_options;
2573 session_options.recv_audio = false;
2574 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002575 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002576 CreateAnswer(session_options));
2577
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 const cricket::ContentInfo* content =
2579 cricket::GetFirstAudioContent(answer->description());
2580 ASSERT_TRUE(content != NULL);
2581 EXPECT_TRUE(content->rejected);
2582
2583 content = cricket::GetFirstVideoContent(answer->description());
2584 ASSERT_TRUE(content != NULL);
2585 EXPECT_TRUE(content->rejected);
2586}
2587
2588// Test that an answer contains the correct media content descriptions when
2589// constraints have been set and streams are sent.
2590TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002591 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002593 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 SetRemoteDescriptionWithoutError(offer.release());
2595
htaa2a49d92016-03-04 02:51:39 -08002596 cricket::MediaSessionOptions options;
2597 options.recv_audio = false;
2598 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599
2600 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002601 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002602 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603
2604 // TODO(perkj): Should the direction be set to SEND_ONLY?
2605 const cricket::ContentInfo* content =
2606 cricket::GetFirstAudioContent(answer->description());
2607 ASSERT_TRUE(content != NULL);
2608 EXPECT_FALSE(content->rejected);
2609
2610 // TODO(perkj): Should the direction be set to SEND_ONLY?
2611 content = cricket::GetFirstVideoContent(answer->description());
2612 ASSERT_TRUE(content != NULL);
2613 EXPECT_FALSE(content->rejected);
2614}
2615
2616TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2617 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002618 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002619 PeerConnectionInterface::RTCOfferAnswerOptions options;
2620 options.offer_to_receive_audio =
2621 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2622 options.voice_activity_detection = false;
2623
kwibergd1fe2812016-04-27 06:47:29 -07002624 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002625
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 const cricket::ContentInfo* content =
2627 cricket::GetFirstAudioContent(offer->description());
2628 EXPECT_TRUE(content != NULL);
2629 EXPECT_TRUE(VerifyNoCNCodecs(content));
2630}
2631
2632TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2633 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002634 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002636 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 SetRemoteDescriptionWithoutError(offer.release());
2638
htaa2a49d92016-03-04 02:51:39 -08002639 cricket::MediaSessionOptions options;
2640 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002641 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 const cricket::ContentInfo* content =
2643 cricket::GetFirstAudioContent(answer->description());
2644 ASSERT_TRUE(content != NULL);
2645 EXPECT_TRUE(VerifyNoCNCodecs(content));
2646}
2647
2648// This test verifies the call setup when remote answer with audio only and
2649// later updates with video.
2650TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002651 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2653 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2654
deadbeefab9b2d12015-10-14 11:33:11 -07002655 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002656 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002657
2658 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2660
2661 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2662 // and answer;
2663 SetLocalDescriptionWithoutError(offer);
2664 SetRemoteDescriptionWithoutError(answer);
2665
2666 video_channel_ = media_engine_->GetVideoChannel(0);
2667 voice_channel_ = media_engine_->GetVoiceChannel(0);
2668
2669 ASSERT_TRUE(video_channel_ == NULL);
2670
2671 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2672 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2673 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2674
2675 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002676 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677 CreateAndSetRemoteOfferAndLocalAnswer();
2678
2679 video_channel_ = media_engine_->GetVideoChannel(0);
2680 voice_channel_ = media_engine_->GetVoiceChannel(0);
2681
2682 ASSERT_TRUE(video_channel_ != NULL);
2683 ASSERT_TRUE(voice_channel_ != NULL);
2684
2685 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2686 ASSERT_EQ(1u, video_channel_->send_streams().size());
2687 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2688 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2689 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2690 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2691 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2692 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2693
2694 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002695 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696 CreateAndSetRemoteOfferAndLocalAnswer();
2697
2698 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2699 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2700 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2701 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2702 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2703}
2704
2705// This test verifies the call setup when remote answer with video only and
2706// later updates with audio.
2707TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002708 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2710 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002711 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002712 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713
2714 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002715 options.recv_audio = false;
2716 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2718 offer, options, cricket::SEC_ENABLED);
2719
2720 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2721 // and answer.
2722 SetLocalDescriptionWithoutError(offer);
2723 SetRemoteDescriptionWithoutError(answer);
2724
2725 video_channel_ = media_engine_->GetVideoChannel(0);
2726 voice_channel_ = media_engine_->GetVoiceChannel(0);
2727
2728 ASSERT_TRUE(voice_channel_ == NULL);
2729 ASSERT_TRUE(video_channel_ != NULL);
2730
2731 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2732 ASSERT_EQ(1u, video_channel_->send_streams().size());
2733 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2734
2735 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002736 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 CreateAndSetRemoteOfferAndLocalAnswer();
2738
2739 voice_channel_ = media_engine_->GetVoiceChannel(0);
2740 ASSERT_TRUE(voice_channel_ != NULL);
2741
2742 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2743 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2744 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2745 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2746
2747 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002748 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 CreateAndSetRemoteOfferAndLocalAnswer();
2750
2751 video_channel_ = media_engine_->GetVideoChannel(0);
2752 voice_channel_ = media_engine_->GetVoiceChannel(0);
2753
2754 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2755 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2756 ASSERT_EQ(1u, video_channel_->send_streams().size());
2757 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2758}
2759
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002760TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002761 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002762 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002763 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002764 VerifyCryptoParams(offer->description());
2765 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002766 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 VerifyCryptoParams(answer->description());
2768}
2769
2770TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002771 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002772 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002773 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002774 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 VerifyNoCryptoParams(offer->description(), false);
2776}
2777
2778TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002779 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002780 VerifyAnswerFromNonCryptoOffer();
2781}
2782
2783TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785 VerifyAnswerFromCryptoOffer();
2786}
2787
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002788// This test verifies that setLocalDescription fails if
2789// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2790TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002791 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002792 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002793 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002794
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002795 std::string sdp;
2796 RemoveIceUfragPwdLines(offer.get(), &sdp);
2797 SessionDescriptionInterface* modified_offer =
2798 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002799 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002800}
2801
2802// This test verifies that setRemoteDescription fails if
2803// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2804TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002805 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002806 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002807 std::string sdp;
2808 RemoveIceUfragPwdLines(offer.get(), &sdp);
2809 SessionDescriptionInterface* modified_offer =
2810 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002811 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002812}
2813
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002814// This test verifies that setLocalDescription fails if local offer has
2815// too short ice ufrag and pwd strings.
2816TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002817 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002818 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002819 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002820 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2821 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002822 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002823 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002824 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002825
2826 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002827 offer.reset(CreateOffer());
2828 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2829 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002830}
2831
2832// This test verifies that setRemoteDescription fails if remote offer has
2833// too short ice ufrag and pwd strings.
2834TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002835 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002837 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2838 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002839 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002840 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002841 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002842
deadbeef0ed85b22016-02-23 17:24:52 -08002843 offer.reset(CreateRemoteOffer());
2844 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2845 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002846}
2847
Honghai Zhang04e91462015-12-11 14:26:22 -08002848// Test that if the remote offer indicates the peer requested ICE restart (via
2849// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2850TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002851 Init();
honghaiz503726c2015-07-31 12:37:38 -07002852
2853 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002854 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002855 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002856 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2857 0, "", "", "relay", 0, "");
2858 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2859 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002860 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2861 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002862 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2863
2864 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002865 offer.reset(CreateRemoteOffer());
2866 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002867 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2868 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2869 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002870 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2871 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002872 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2873
2874 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002875 offer.reset(CreateRemoteOffer());
2876 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002877 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2878 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2879 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002880 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2881 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002882 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2883
2884 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002885 offer.reset(CreateRemoteOffer());
2886 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2887 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002888 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2889}
2890
Honghai Zhang04e91462015-12-11 14:26:22 -08002891// Test that if the remote answer indicates the peer requested ICE restart (via
2892// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2893TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2894 Init();
2895 SessionDescriptionInterface* offer = CreateOffer();
2896 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002897
2898 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002899 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002900 answer->set_type(JsepSessionDescription::kPrAnswer);
2901 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002902 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2903 0, "", "", "relay", 0, "");
2904 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2905 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002906 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2907 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002908 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2909
2910 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002911 answer.reset(CreateRemoteAnswer(offer));
2912 answer->set_type(JsepSessionDescription::kPrAnswer);
2913 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002914 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2915 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2916 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002917 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2918 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002919 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2920
2921 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002922 answer.reset(CreateRemoteAnswer(offer));
2923 answer->set_type(JsepSessionDescription::kPrAnswer);
2924 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002925 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2926 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2927 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002928 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2929 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002930 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2931
2932 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002933 answer.reset(CreateRemoteAnswer(offer));
2934 answer->set_type(JsepSessionDescription::kPrAnswer);
2935 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2936 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002937 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2938}
2939
Donald Curtisd4f769d2015-05-28 09:48:21 -07002940// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002941// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002942TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2943 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2944
2945 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002946 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002947
2948 PeerConnectionInterface::RTCOfferAnswerOptions options;
2949 options.use_rtp_mux = true;
2950
2951 SessionDescriptionInterface* offer = CreateRemoteOffer();
2952 SetRemoteDescriptionWithoutError(offer);
2953
htaa2a49d92016-03-04 02:51:39 -08002954 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002955 SetLocalDescriptionWithoutError(answer);
2956
deadbeefcbecd352015-09-23 11:50:27 -07002957 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2958 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002959
deadbeefcbecd352015-09-23 11:50:27 -07002960 cricket::BaseChannel* voice_channel = session_->voice_channel();
2961 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002962
2963 // Checks if one of the transport channels contains a connection using a given
2964 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002965 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002966 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002967 session_->GetChannelTransportStats(voice_channel, &stats);
2968 for (auto& kv : stats.transport_stats) {
2969 for (auto& chan_stat : kv.second.channel_stats) {
2970 for (auto& conn_info : chan_stat.connection_infos) {
2971 if (conn_info.remote_candidate.address().port() == port) {
2972 return true;
2973 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002974 }
2975 }
2976 }
2977 return false;
2978 };
2979
2980 EXPECT_FALSE(connection_with_remote_port(5000));
2981 EXPECT_FALSE(connection_with_remote_port(5001));
2982 EXPECT_FALSE(connection_with_remote_port(6000));
2983
2984 // The way the *_WAIT checks work is they only wait if the condition fails,
2985 // which does not help in the case where state is not changing. This is
2986 // problematic in this test since we want to verify that adding a video
2987 // candidate does _not_ change state. So we interleave candidates and assume
2988 // that messages are executed in the order they were posted.
2989
2990 // First audio candidate.
2991 cricket::Candidate candidate0;
2992 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2993 candidate0.set_component(1);
2994 candidate0.set_protocol("udp");
2995 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2996 candidate0);
2997 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2998
2999 // Video candidate.
3000 cricket::Candidate candidate1;
3001 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3002 candidate1.set_component(1);
3003 candidate1.set_protocol("udp");
3004 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3005 candidate1);
3006 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3007
3008 // Second audio candidate.
3009 cricket::Candidate candidate2;
3010 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3011 candidate2.set_component(1);
3012 candidate2.set_protocol("udp");
3013 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3014 candidate2);
3015 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3016
3017 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3018 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3019
3020 // No need here for a _WAIT check since we are checking that state hasn't
3021 // changed: if this is false we would be doing waits for nothing and if this
3022 // is true then there will be no messages processed anyways.
3023 EXPECT_FALSE(connection_with_remote_port(6000));
3024}
3025
deadbeefcbecd352015-09-23 11:50:27 -07003026// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003027TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3028 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003029 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003030
3031 PeerConnectionInterface::RTCOfferAnswerOptions options;
3032 options.use_rtp_mux = true;
3033
3034 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003036
deadbeefcbecd352015-09-23 11:50:27 -07003037 EXPECT_NE(session_->voice_rtp_transport_channel(),
3038 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003039
deadbeefab9b2d12015-10-14 11:33:11 -07003040 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003041 SessionDescriptionInterface* answer =
3042 CreateRemoteAnswer(session_->local_description());
3043 SetRemoteDescriptionWithoutError(answer);
3044
deadbeefcbecd352015-09-23 11:50:27 -07003045 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3046 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003047}
3048
deadbeefcbecd352015-09-23 11:50:27 -07003049// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003050TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3051 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003052 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003053
Donald Curtis0e209b02015-03-24 09:29:54 -07003054 PeerConnectionInterface::RTCOfferAnswerOptions options;
3055 options.use_rtp_mux = true;
3056
3057 SessionDescriptionInterface* offer = CreateOffer(options);
3058 SetLocalDescriptionWithoutError(offer);
3059
deadbeefcbecd352015-09-23 11:50:27 -07003060 EXPECT_NE(session_->voice_rtp_transport_channel(),
3061 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003062
deadbeefab9b2d12015-10-14 11:33:11 -07003063 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003064
3065 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003066 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003067 CreateRemoteAnswer(session_->local_description()));
3068 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3069 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3070 JsepSessionDescription* modified_answer =
3071 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3072 modified_answer->Initialize(answer_copy, "1", "1");
3073 SetRemoteDescriptionWithoutError(modified_answer); //
3074
deadbeefcbecd352015-09-23 11:50:27 -07003075 EXPECT_NE(session_->voice_rtp_transport_channel(),
3076 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003077}
3078
3079// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3080TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3081 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003082 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003083
3084 PeerConnectionInterface::RTCOfferAnswerOptions options;
3085 options.use_rtp_mux = true;
3086
3087 SessionDescriptionInterface* offer = CreateOffer(options);
3088 SetLocalDescriptionWithoutError(offer);
3089
deadbeefcbecd352015-09-23 11:50:27 -07003090 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3091 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003092
deadbeefab9b2d12015-10-14 11:33:11 -07003093 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003094 SessionDescriptionInterface* answer =
3095 CreateRemoteAnswer(session_->local_description());
3096 SetRemoteDescriptionWithoutError(answer);
3097
deadbeefcbecd352015-09-23 11:50:27 -07003098 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3099 session_->video_rtp_transport_channel());
3100}
3101
3102// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3103// audio content in the answer.
3104TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3105 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003106 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003107
3108 PeerConnectionInterface::RTCOfferAnswerOptions options;
3109 options.use_rtp_mux = true;
3110
3111 SessionDescriptionInterface* offer = CreateOffer(options);
3112 SetLocalDescriptionWithoutError(offer);
3113
3114 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3115 session_->video_rtp_transport_channel());
3116
deadbeefab9b2d12015-10-14 11:33:11 -07003117 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003118 cricket::MediaSessionOptions recv_options;
3119 recv_options.recv_audio = false;
3120 recv_options.recv_video = true;
3121 SessionDescriptionInterface* answer =
3122 CreateRemoteAnswer(session_->local_description(), recv_options);
3123 SetRemoteDescriptionWithoutError(answer);
3124
deadbeefd59daf82015-10-14 15:02:44 -07003125 EXPECT_TRUE(nullptr == session_->voice_channel());
3126 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003127
deadbeefd59daf82015-10-14 15:02:44 -07003128 session_->Close();
3129 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3130 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3131 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3132 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003133}
3134
3135// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3136TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3137 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003138 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003139
Donald Curtis0e209b02015-03-24 09:29:54 -07003140 PeerConnectionInterface::RTCOfferAnswerOptions options;
3141 options.use_rtp_mux = true;
3142
3143 SessionDescriptionInterface* offer = CreateOffer(options);
3144 SetLocalDescriptionWithoutError(offer);
3145
deadbeefcbecd352015-09-23 11:50:27 -07003146 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3147 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003148
deadbeefab9b2d12015-10-14 11:33:11 -07003149 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003150
3151 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003152 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153 CreateRemoteAnswer(session_->local_description()));
3154 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3155 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3156 JsepSessionDescription* modified_answer =
3157 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3158 modified_answer->Initialize(answer_copy, "1", "1");
3159 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003160
deadbeefcbecd352015-09-23 11:50:27 -07003161 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3162 session_->video_rtp_transport_channel());
3163}
3164
3165// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3166TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3167 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003168 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003169
3170 SessionDescriptionInterface* offer = CreateRemoteOffer();
3171 SetRemoteDescriptionWithoutError(offer);
3172
3173 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3174 session_->video_rtp_transport_channel());
3175
deadbeefab9b2d12015-10-14 11:33:11 -07003176 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003177 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003178 SetLocalDescriptionWithoutError(answer);
3179
3180 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
3182}
3183
3184// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3185TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3186 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003187 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003188
3189 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003190 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003191 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3192 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3193 JsepSessionDescription* modified_offer =
3194 new JsepSessionDescription(JsepSessionDescription::kOffer);
3195 modified_offer->Initialize(offer_copy, "1", "1");
3196
3197 // Expect an error when applying the remote description
3198 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3199 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003200}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003201
Peter Thatcher4eddf182015-04-30 10:55:59 -07003202// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003203TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3204 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003205 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003206
Donald Curtis0e209b02015-03-24 09:29:54 -07003207 PeerConnectionInterface::RTCOfferAnswerOptions options;
3208 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209
Donald Curtis0e209b02015-03-24 09:29:54 -07003210 SessionDescriptionInterface* offer = CreateOffer(options);
3211 SetLocalDescriptionWithoutError(offer);
3212
deadbeefcbecd352015-09-23 11:50:27 -07003213 EXPECT_NE(session_->voice_rtp_transport_channel(),
3214 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003215
deadbeefab9b2d12015-10-14 11:33:11 -07003216 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003217 SessionDescriptionInterface* answer =
3218 CreateRemoteAnswer(session_->local_description());
3219 SetRemoteDescriptionWithoutError(answer);
3220
3221 // This should lead to an audio-only call but isn't implemented
3222 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003223 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3224 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003225}
3226
deadbeefcbecd352015-09-23 11:50:27 -07003227// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003228TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3229 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003230 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003231 PeerConnectionInterface::RTCOfferAnswerOptions options;
3232 options.use_rtp_mux = true;
3233
3234 SessionDescriptionInterface* offer = CreateOffer(options);
3235 SetLocalDescriptionWithoutError(offer);
3236
deadbeefcbecd352015-09-23 11:50:27 -07003237 EXPECT_NE(session_->voice_rtp_transport_channel(),
3238 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003239
deadbeefab9b2d12015-10-14 11:33:11 -07003240 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003241
3242 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003243 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003244 CreateRemoteAnswer(session_->local_description()));
3245 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3246 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3247 JsepSessionDescription* modified_answer =
3248 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3249 modified_answer->Initialize(answer_copy, "1", "1");
3250 SetRemoteDescriptionWithoutError(modified_answer); //
3251
deadbeefcbecd352015-09-23 11:50:27 -07003252 EXPECT_NE(session_->voice_rtp_transport_channel(),
3253 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254}
3255
Peter Thatcher4eddf182015-04-30 10:55:59 -07003256// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3257TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3258 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003259 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003260
3261 PeerConnectionInterface::RTCOfferAnswerOptions options;
3262 options.use_rtp_mux = true;
3263
3264 SessionDescriptionInterface* offer = CreateOffer(options);
3265 SetRemoteDescriptionWithoutError(offer);
3266
deadbeefcbecd352015-09-23 11:50:27 -07003267 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3268 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003269}
3270
skvlad6c87a672016-05-17 17:49:52 -07003271// Adding a new channel to a BUNDLE which is already connected should directly
3272// assign the bundle transport to the channel, without first setting a
3273// disconnected non-bundle transport and then replacing it. The application
3274// should not receive any changes in the ICE state.
3275TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3276 LoopbackNetworkConfiguration config;
3277 LoopbackNetworkManager loopback_network_manager(this, config);
3278 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3279 // connected. Disabling either of these two means that we need to wait for the
3280 // answer to find out if more transports are needed.
3281 configuration_.bundle_policy =
3282 PeerConnectionInterface::kBundlePolicyMaxBundle;
3283 configuration_.rtcp_mux_policy =
3284 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3285 options_.disable_encryption = true;
3286 Init();
3287
3288 // Negotiate an audio channel with MAX_BUNDLE enabled.
3289 SendAudioOnlyStream2();
3290 SessionDescriptionInterface* offer = CreateOffer();
3291 SetLocalDescriptionWithoutError(offer);
3292 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3293 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3294 std::string sdp;
3295 offer->ToString(&sdp);
3296 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3297 JsepSessionDescription::kAnswer, sdp, nullptr);
3298 ASSERT_TRUE(answer != NULL);
3299 SetRemoteDescriptionWithoutError(answer);
3300
3301 // Wait for the ICE state to stabilize.
3302 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3303 observer_.ice_connection_state_, kIceCandidatesTimeout);
3304 observer_.ice_connection_state_history_.clear();
3305
3306 // Now add a video channel which should be using the same bundle transport.
3307 SendAudioVideoStream2();
3308 offer = CreateOffer();
3309 offer->ToString(&sdp);
3310 SetLocalDescriptionWithoutError(offer);
3311 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3312 sdp, nullptr);
3313 ASSERT_TRUE(answer != NULL);
3314 SetRemoteDescriptionWithoutError(answer);
3315
3316 // Wait for ICE state to stabilize
3317 rtc::Thread::Current()->ProcessMessages(0);
3318 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3319 observer_.ice_connection_state_, kIceCandidatesTimeout);
3320
3321 // No ICE state changes are expected to happen.
3322 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3323}
3324
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003325TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3326 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003327 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003328
3329 PeerConnectionInterface::RTCOfferAnswerOptions options;
3330 SessionDescriptionInterface* offer = CreateOffer(options);
3331 SetLocalDescriptionWithoutError(offer);
3332
deadbeefcbecd352015-09-23 11:50:27 -07003333 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3334 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003335
deadbeefab9b2d12015-10-14 11:33:11 -07003336 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003337 SessionDescriptionInterface* answer =
3338 CreateRemoteAnswer(session_->local_description());
3339 SetRemoteDescriptionWithoutError(answer);
3340
deadbeefcbecd352015-09-23 11:50:27 -07003341 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3342 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003343}
3344
3345TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3346 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003347 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003348
3349 PeerConnectionInterface::RTCOfferAnswerOptions options;
3350 SessionDescriptionInterface* offer = CreateOffer(options);
3351 SetLocalDescriptionWithoutError(offer);
3352
deadbeefcbecd352015-09-23 11:50:27 -07003353 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3354 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003355
deadbeefab9b2d12015-10-14 11:33:11 -07003356 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003357 SessionDescriptionInterface* answer =
3358 CreateRemoteAnswer(session_->local_description());
3359 SetRemoteDescriptionWithoutError(answer);
3360
deadbeefcbecd352015-09-23 11:50:27 -07003361 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3362 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003363}
3364
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003365// This test verifies that SetLocalDescription and SetRemoteDescription fails
3366// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3367TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003368 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003369 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003370
3371 PeerConnectionInterface::RTCOfferAnswerOptions options;
3372 options.use_rtp_mux = true;
3373
3374 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003375 std::string offer_str;
3376 offer->ToString(&offer_str);
3377 // Disable rtcp-mux
3378 const std::string rtcp_mux = "rtcp-mux";
3379 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003380 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003381 xrtcp_mux.c_str(), xrtcp_mux.length(),
3382 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003383 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003384 new JsepSessionDescription(JsepSessionDescription::kOffer);
3385 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003386 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003387 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003388 new JsepSessionDescription(JsepSessionDescription::kOffer);
3389 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003390 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003391 // Trying unmodified SDP.
3392 SetLocalDescriptionWithoutError(offer);
3393}
3394
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003396 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003397 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 CreateAndSetRemoteOfferAndLocalAnswer();
3399 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3400 ASSERT_TRUE(channel != NULL);
3401 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003402 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003403 double volume;
3404 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3405 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003406 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003407 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3408 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003409 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003410 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3411 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412}
3413
skvlade0d46372016-04-07 22:59:22 -07003414TEST_F(WebRtcSessionTest, SetAudioMaxSendBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003415 Init();
3416 SendAudioVideoStream1();
3417 CreateAndSetRemoteOfferAndLocalAnswer();
3418 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3419 ASSERT_TRUE(channel != NULL);
3420 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
skvlade0d46372016-04-07 22:59:22 -07003421 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003422 webrtc::RtpParameters params = session_->GetAudioRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003423 EXPECT_EQ(1, params.encodings.size());
3424 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3425 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003426 EXPECT_TRUE(session_->SetAudioRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003427
skvlade0d46372016-04-07 22:59:22 -07003428 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003429 params = session_->GetAudioRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003430 EXPECT_EQ(1, params.encodings.size());
3431 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3432
3433 // Verify that the audio channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003434 params = channel->GetRtpSendParameters(send_ssrc);
skvlade0d46372016-04-07 22:59:22 -07003435 EXPECT_EQ(1, params.encodings.size());
3436 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3437
3438 // Verify that the global bitrate limit has not been changed.
3439 EXPECT_EQ(-1, channel->max_bps());
skvladdc1c62c2016-03-16 19:07:43 -07003440}
3441
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003443 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003444 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 CreateAndSetRemoteOfferAndLocalAnswer();
3446 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3447 ASSERT_TRUE(channel != NULL);
3448 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003449 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3451
3452 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003453 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454
kwibergd1fe2812016-04-27 06:47:29 -07003455 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003456 session_->SetAudioSend(send_ssrc, false, options, source.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003458 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003459 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003461 // This will trigger SetSink(nullptr) to the |source|.
3462 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003464 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003465 EXPECT_TRUE(source->sink() == nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003466}
3467
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003468TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003469 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003470 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003471 CreateAndSetRemoteOfferAndLocalAnswer();
3472 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3473 ASSERT_TRUE(channel != NULL);
3474 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003475 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003476
kwibergd1fe2812016-04-27 06:47:29 -07003477 std::unique_ptr<FakeAudioSource> source(new FakeAudioSource());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003478 cricket::AudioOptions options;
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003479 session_->SetAudioSend(send_ssrc, true, options, source.get());
3480 EXPECT_TRUE(source->sink() != nullptr);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003481
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003482 // Delete the |source| and it will trigger OnClose() to the sink, and this
3483 // will invalidate the |source_| pointer in the sink and prevent getting a
3484 // SetSink(nullptr) callback afterwards.
3485 source.reset();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003486
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08003487 // This will trigger SetSink(nullptr) if no OnClose() callback.
3488 session_->SetAudioSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489}
3490
3491TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003492 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003493 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 CreateAndSetRemoteOfferAndLocalAnswer();
3495 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3496 ASSERT_TRUE(channel != NULL);
nisse08582ff2016-02-04 01:24:52 -08003497 ASSERT_LT(0u, channel->sinks().size());
3498 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003500 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 cricket::FakeVideoRenderer renderer;
3502 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003503 EXPECT_TRUE(channel->sinks().begin()->second == &renderer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
nisse08582ff2016-02-04 01:24:52 -08003505 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506}
3507
skvladdc1c62c2016-03-16 19:07:43 -07003508TEST_F(WebRtcSessionTest, SetVideoMaxSendBitrate) {
3509 Init();
3510 SendAudioVideoStream1();
3511 CreateAndSetRemoteOfferAndLocalAnswer();
3512 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3513 ASSERT_TRUE(channel != NULL);
3514 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3515 EXPECT_EQ(-1, channel->max_bps());
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003516 webrtc::RtpParameters params = session_->GetVideoRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003517 EXPECT_EQ(1, params.encodings.size());
3518 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
3519 params.encodings[0].max_bitrate_bps = 1000;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003520 EXPECT_TRUE(session_->SetVideoRtpSendParameters(send_ssrc, params));
skvladdc1c62c2016-03-16 19:07:43 -07003521
3522 // Read back the parameters and verify they have been changed.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003523 params = session_->GetVideoRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003524 EXPECT_EQ(1, params.encodings.size());
3525 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3526
3527 // Verify that the video channel received the new parameters.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07003528 params = channel->GetRtpSendParameters(send_ssrc);
skvladdc1c62c2016-03-16 19:07:43 -07003529 EXPECT_EQ(1, params.encodings.size());
3530 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
3531
3532 // Verify that the global bitrate limit has not been changed.
3533 EXPECT_EQ(-1, channel->max_bps());
3534}
3535
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003536TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003537 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003538 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 CreateAndSetRemoteOfferAndLocalAnswer();
3540 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3541 ASSERT_TRUE(channel != NULL);
3542 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003543 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003544 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3545 cricket::VideoOptions* options = NULL;
deadbeef5a4a75a2016-06-02 16:23:38 -07003546 session_->SetVideoSend(send_ssrc, false, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
deadbeef5a4a75a2016-06-02 16:23:38 -07003548 session_->SetVideoSend(send_ssrc, true, options, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3550}
3551
3552TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3553 TestCanInsertDtmf(false);
3554}
3555
3556TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3557 TestCanInsertDtmf(true);
3558}
3559
3560TEST_F(WebRtcSessionTest, InsertDtmf) {
3561 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003562 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003563 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 CreateAndSetRemoteOfferAndLocalAnswer();
3565 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3566 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3567
3568 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003569 const int expected_duration = 90;
3570 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3571 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3572 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3573
3574 // Verify
3575 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003576 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003578 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003580 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003582 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583}
3584
deadbeefd59daf82015-10-14 15:02:44 -07003585// This test verifies the |initial_offerer| flag when session initiates the
3586// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003588 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003589 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003590 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003591 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3592 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003593 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003595 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596}
3597
deadbeefd59daf82015-10-14 15:02:44 -07003598// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003600 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003601 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 SessionDescriptionInterface* offer = CreateRemoteOffer();
3603 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003604 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605
deadbeefd59daf82015-10-14 15:02:44 -07003606 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003608 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609}
3610
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3612TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003613 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003614 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003615 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003616 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003617 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003618 CreateRemoteAnswer(session_->local_description()));
3619
3620 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3621 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003622 JsepSessionDescription* modified_answer =
3623 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624
3625 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3626 answer->session_id(),
3627 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003628 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629
wu@webrtc.org4e393072014-04-07 17:04:35 +00003630 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631 std::string sdp;
3632 EXPECT_TRUE(answer->ToString(&sdp));
3633 const std::string kAudioMid = "a=mid:audio";
3634 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003635 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003636 kAudioMidReplaceStr.c_str(),
3637 kAudioMidReplaceStr.length(),
3638 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003639 SessionDescriptionInterface* modified_answer1 =
3640 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003641 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642
wu@webrtc.org4e393072014-04-07 17:04:35 +00003643 // Different media types.
3644 EXPECT_TRUE(answer->ToString(&sdp));
3645 const std::string kAudioMline = "m=audio";
3646 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003647 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003648 kAudioMlineReplaceStr.c_str(),
3649 kAudioMlineReplaceStr.length(),
3650 &sdp);
3651 SessionDescriptionInterface* modified_answer2 =
3652 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3653 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3654
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003655 SetRemoteDescriptionWithoutError(answer.release());
3656}
3657
3658// Verifying remote offer and local answer have matching m-lines as per
3659// RFC 3264.
3660TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003661 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003662 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SessionDescriptionInterface* offer = CreateRemoteOffer();
3664 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003665 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666
3667 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3668 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003669 JsepSessionDescription* modified_answer =
3670 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671
3672 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3673 answer->session_id(),
3674 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003675 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 SetLocalDescriptionWithoutError(answer);
3677}
3678
3679// This test verifies that WebRtcSession does not start candidate allocation
3680// before SetLocalDescription is called.
3681TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003682 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003683 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684 SessionDescriptionInterface* offer = CreateRemoteOffer();
3685 cricket::Candidate candidate;
3686 candidate.set_component(1);
3687 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3688 candidate);
3689 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3690 cricket::Candidate candidate1;
3691 candidate1.set_component(1);
3692 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3693 candidate1);
3694 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3695 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003696 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3697 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003698
3699 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003700 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003701 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3702 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3703
htaa2a49d92016-03-04 02:51:39 -08003704 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003705 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3707}
3708
3709// This test verifies that crypto parameter is updated in local session
3710// description as per security policy set in MediaSessionDescriptionFactory.
3711TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003712 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003713 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003714 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003715
3716 // Making sure SetLocalDescription correctly sets crypto value in
3717 // SessionDescription object after de-serialization of sdp string. The value
3718 // will be set as per MediaSessionDescriptionFactory.
3719 std::string offer_str;
3720 offer->ToString(&offer_str);
3721 SessionDescriptionInterface* jsep_offer_str =
3722 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3723 SetLocalDescriptionWithoutError(jsep_offer_str);
3724 EXPECT_TRUE(session_->voice_channel()->secure_required());
3725 EXPECT_TRUE(session_->video_channel()->secure_required());
3726}
3727
3728// This test verifies the crypto parameter when security is disabled.
3729TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003730 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003731 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003732 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003733 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734
3735 // Making sure SetLocalDescription correctly sets crypto value in
3736 // SessionDescription object after de-serialization of sdp string. The value
3737 // will be set as per MediaSessionDescriptionFactory.
3738 std::string offer_str;
3739 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003740 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003741 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3742 SetLocalDescriptionWithoutError(jsep_offer_str);
3743 EXPECT_FALSE(session_->voice_channel()->secure_required());
3744 EXPECT_FALSE(session_->video_channel()->secure_required());
3745}
3746
3747// This test verifies that an answer contains new ufrag and password if an offer
3748// with new ufrag and password is received.
3749TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003750 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003752 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003753 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754 SetRemoteDescriptionWithoutError(offer.release());
3755
deadbeefab9b2d12015-10-14 11:33:11 -07003756 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003757 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003758 SetLocalDescriptionWithoutError(answer.release());
3759
3760 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003761 for (const cricket::ContentInfo& content :
3762 session_->local_description()->description()->contents()) {
3763 options.transport_options[content.name].ice_restart = true;
3764 }
kwibergd1fe2812016-04-27 06:47:29 -07003765 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003766 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003767 SetRemoteDescriptionWithoutError(updated_offer1.release());
3768
kwibergd1fe2812016-04-27 06:47:29 -07003769 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003770
deadbeef0ed85b22016-02-23 17:24:52 -08003771 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3772 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003773
deadbeef0ed85b22016-02-23 17:24:52 -08003774 // Even a second answer (created before the description is set) should have
3775 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003776 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003777
3778 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3779 session_->local_description()->description()));
3780
3781 SetLocalDescriptionWithoutError(updated_answer2.release());
3782}
3783
3784// This test verifies that an answer contains new ufrag and password if an offer
3785// that changes either the ufrag or password (but not both) is received.
3786// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3787// a=ice-pwd attributes compared to the previous SDP from the peer, it
3788// indicates that ICE is restarting for this media stream."
3789TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3790 Init();
3791 cricket::MediaSessionOptions options;
3792 options.recv_audio = true;
3793 options.recv_video = true;
3794 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003795 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003796 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3797 SetRemoteDescriptionWithoutError(offer.release());
3798
3799 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003800 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003801 SetLocalDescriptionWithoutError(answer.release());
3802
3803 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003804 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003805 CreateRemoteOffer(options, session_->remote_description()));
3806 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3807 "original_password12345");
3808 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3809
kwibergd1fe2812016-04-27 06:47:29 -07003810 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003811 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3812 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003814
3815 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003816 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003817 CreateRemoteOffer(options, session_->remote_description()));
3818 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3819 "modified_password12345");
3820 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3821
kwibergd1fe2812016-04-27 06:47:29 -07003822 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003823 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3824 session_->local_description()->description()));
3825 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003826}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003827
wu@webrtc.org91053e72013-08-10 07:18:04 +00003828// This test verifies that an answer contains old ufrag and password if an offer
3829// with old ufrag and password is received.
3830TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003831 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003832 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003833 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003834 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003835 SetRemoteDescriptionWithoutError(offer.release());
3836
deadbeefab9b2d12015-10-14 11:33:11 -07003837 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003838 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003839 SetLocalDescriptionWithoutError(answer.release());
3840
3841 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003842 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003843 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003844 SetRemoteDescriptionWithoutError(updated_offer2.release());
3845
kwibergd1fe2812016-04-27 06:47:29 -07003846 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003847
deadbeef0ed85b22016-02-23 17:24:52 -08003848 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3849 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850
3851 SetLocalDescriptionWithoutError(updated_answer2.release());
3852}
3853
deadbeef0ed85b22016-02-23 17:24:52 -08003854// This test verifies that if an offer does an ICE restart on some, but not all
3855// media sections, the answer will change the ufrag/password in the correct
3856// media sections.
3857TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3858 Init();
3859 cricket::MediaSessionOptions options;
3860 options.recv_video = true;
3861 options.recv_audio = true;
3862 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003863 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003864
3865 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3866 "aaaaaaaaaaaaaaaaaaaaaa");
3867 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3868 "bbbbbbbbbbbbbbbbbbbbbb");
3869 SetRemoteDescriptionWithoutError(offer.release());
3870
3871 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003872 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003873 SetLocalDescriptionWithoutError(answer.release());
3874
3875 // Receive an offer with new ufrag and password, but only for the video media
3876 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003877 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003878 CreateRemoteOffer(options, session_->remote_description()));
3879 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3880 "cccccccccccccccccccccc");
3881 SetRemoteDescriptionWithoutError(updated_offer.release());
3882
kwibergd1fe2812016-04-27 06:47:29 -07003883 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003884
3885 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3886 session_->local_description()->description(),
3887 cricket::MEDIA_TYPE_AUDIO));
3888
3889 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3890 session_->local_description()->description(),
3891 cricket::MEDIA_TYPE_VIDEO));
3892
3893 SetLocalDescriptionWithoutError(updated_answer.release());
3894}
3895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003896TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003897 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003898 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003899 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003900 const std::string session_id_orig = offer->session_id();
3901 const std::string session_version_orig = offer->session_version();
3902 SetLocalDescriptionWithoutError(offer);
3903
3904 video_channel_ = media_engine_->GetVideoChannel(0);
3905 video_channel_->set_fail_set_send_codecs(true);
3906
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003907 SessionDescriptionInterface* answer =
3908 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003909 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003910
3911 // Test that after a content error, setting any description will
3912 // result in an error.
3913 video_channel_->set_fail_set_send_codecs(false);
3914 answer = CreateRemoteAnswer(session_->local_description());
3915 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3916 offer = CreateRemoteOffer();
3917 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003918}
3919
3920// Runs the loopback call test with BUNDLE and STUN disabled.
3921TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3922 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003923 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003924 cricket::PORTALLOCATOR_DISABLE_STUN |
3925 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003926 TestLoopbackCall();
3927}
3928
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003929TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003930 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003931 cricket::PORTALLOCATOR_DISABLE_STUN |
3932 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3933 cricket::PORTALLOCATOR_DISABLE_RELAY);
3934
3935 // best connection is IPv6 since it has higher network preference.
3936 LoopbackNetworkConfiguration config;
3937 config.test_ipv6_network_ = true;
3938 config.best_connection_after_initial_ice_converged_ =
3939 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3940
3941 TestLoopbackCall(config);
3942}
3943
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003944// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003945TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003946 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3947 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003948 TestLoopbackCall();
3949}
3950
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003951TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003952 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003953 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003954 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003955 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003956 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3957}
3958
Henrik Boström87713d02015-08-25 09:53:21 +02003959TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003960 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003961
htaa2a49d92016-03-04 02:51:39 -08003962 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003963 options_.disable_sctp_data_channels = false;
3964
Henrik Boström87713d02015-08-25 09:53:21 +02003965 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003966
3967 SetLocalDescriptionWithDataChannel();
3968 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3969}
3970
Henrik Boström87713d02015-08-25 09:53:21 +02003971TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003972 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003973
Henrik Boström87713d02015-08-25 09:53:21 +02003974 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003975
kwibergd1fe2812016-04-27 06:47:29 -07003976 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003977 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003978 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3979}
3980
Henrik Boström87713d02015-08-25 09:53:21 +02003981TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003982 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003983 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003984 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003985
3986 // Create remote offer with SCTP.
3987 cricket::MediaSessionOptions options;
3988 options.data_channel_type = cricket::DCT_SCTP;
3989 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003990 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003991 SetRemoteDescriptionWithoutError(offer);
3992
3993 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003994 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003995 EXPECT_TRUE(answer != NULL);
3996 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3997 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003998}
3999
Henrik Boström87713d02015-08-25 09:53:21 +02004000TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004001 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004002 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004003
4004 SetLocalDescriptionWithDataChannel();
4005 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4006}
4007
Henrik Boström87713d02015-08-25 09:53:21 +02004008TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004009 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004010
Henrik Boström87713d02015-08-25 09:53:21 +02004011 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004012
4013 SetLocalDescriptionWithDataChannel();
4014 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4015}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004016
Henrik Boström87713d02015-08-25 09:53:21 +02004017TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004018 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004019 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004020 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004021
4022 SetLocalDescriptionWithDataChannel();
4023 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
4024}
4025
Henrik Boström87713d02015-08-25 09:53:21 +02004026TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004027 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004028 const int new_send_port = 9998;
4029 const int new_recv_port = 7775;
4030
Henrik Boström87713d02015-08-25 09:53:21 +02004031 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004032 SetFactoryDtlsSrtp();
4033
4034 // By default, don't actually add the codecs to desc_factory_; they don't
4035 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4036 // let the session description get parsed. That'll get the proper codecs
4037 // into the stream.
4038 cricket::MediaSessionOptions options;
4039 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4040 "stream1", new_send_port, options);
4041
4042 // SetRemoteDescription will take the ownership of the offer.
4043 SetRemoteDescriptionWithoutError(offer);
4044
htaa2a49d92016-03-04 02:51:39 -08004045 SessionDescriptionInterface* answer =
4046 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004047 ASSERT_TRUE(answer != NULL);
4048
4049 // Now set the local description, which'll take ownership of the answer.
4050 SetLocalDescriptionWithoutError(answer);
4051
4052 // TEST PLAN: Set the port number to something new, set it in the SDP,
4053 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004054 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004055 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004056
4057 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
4058 int portnum = -1;
4059 ASSERT_TRUE(ch != NULL);
4060 ASSERT_EQ(1UL, ch->send_codecs().size());
4061 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004062 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004063 ch->send_codecs()[0].name.c_str()));
4064 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
4065 &portnum));
4066 EXPECT_EQ(new_send_port, portnum);
4067
4068 ASSERT_EQ(1UL, ch->recv_codecs().size());
4069 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07004070 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004071 ch->recv_codecs()[0].name.c_str()));
4072 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
4073 &portnum));
4074 EXPECT_EQ(new_recv_port, portnum);
4075}
4076
deadbeefab9b2d12015-10-14 11:33:11 -07004077// Verifies that when a session's DataChannel receives an OPEN message,
4078// WebRtcSession signals the DataChannel creation request with the expected
4079// config.
4080TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4081 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4082
4083 InitWithDtls(GetParam());
4084
4085 SetLocalDescriptionWithDataChannel();
4086 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4087
4088 webrtc::DataChannelInit config;
4089 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004090 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004091 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4092 cricket::ReceiveDataParams params;
4093 params.ssrc = config.id;
4094 params.type = cricket::DMT_CONTROL;
4095
4096 cricket::DataChannel* data_channel = session_->data_channel();
4097 data_channel->SignalDataReceived(data_channel, params, payload);
4098
4099 EXPECT_EQ("a", last_data_channel_label_);
4100 EXPECT_EQ(config.id, last_data_channel_config_.id);
4101 EXPECT_FALSE(last_data_channel_config_.negotiated);
4102 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4103 last_data_channel_config_.open_handshake_role);
4104}
4105
4106TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004107 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004108 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004109
htaa2a49d92016-03-04 02:51:39 -08004110 configuration_.certificates.push_back(certificate);
4111 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004112 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4113
4114 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4115}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116
Henrik Boström87713d02015-08-25 09:53:21 +02004117// Verifies that CreateOffer succeeds when CreateOffer is called before async
4118// identity generation is finished (even if a certificate is provided this is
4119// an async op).
4120TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4121 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4122 InitWithDtls(GetParam());
4123
Henrik Boströmd8281982015-08-27 10:12:24 +02004124 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004125 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004126 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004127
wu@webrtc.org91053e72013-08-10 07:18:04 +00004128 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004129 VerifyNoCryptoParams(offer->description(), true);
4130 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004131}
4132
4133// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004134// identity generation is finished (even if a certificate is provided this is
4135// an async op).
4136TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004137 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004138 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004139 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004140
4141 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004142 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004143 std::unique_ptr<JsepSessionDescription> offer(
4144 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004145 ASSERT_TRUE(offer.get() != NULL);
4146 SetRemoteDescriptionWithoutError(offer.release());
4147
kwibergd1fe2812016-04-27 06:47:29 -07004148 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004149 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004150 VerifyNoCryptoParams(answer->description(), true);
4151 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004152}
4153
4154// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004155// identity generation is finished (even if a certificate is provided this is
4156// an async op).
4157TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004158 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004159 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004160
Henrik Boströmd8281982015-08-27 10:12:24 +02004161 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004162
kwibergd1fe2812016-04-27 06:47:29 -07004163 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004164 EXPECT_TRUE(offer != NULL);
4165}
4166
4167// Verifies that CreateOffer fails when CreateOffer is called after async
4168// identity generation fails.
4169TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004171 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004172
Henrik Boströmd8281982015-08-27 10:12:24 +02004173 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004174
kwibergd1fe2812016-04-27 06:47:29 -07004175 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004176 EXPECT_TRUE(offer == NULL);
4177}
4178
4179// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4180// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004181TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004182 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004183 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004184 VerifyMultipleAsyncCreateDescription(GetParam(),
4185 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004186}
4187
4188// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4189// before async identity generation fails.
4190TEST_F(WebRtcSessionTest,
4191 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004192 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004193 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4194 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004195}
4196
4197// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4198// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004199TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004200 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004201 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004202 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004203 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004204}
4205
4206// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4207// before async identity generation fails.
4208TEST_F(WebRtcSessionTest,
4209 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004210 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004211 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4212 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004213}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004214
4215// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4216// offer has no SDES crypto but only DTLS fingerprint.
4217TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4218 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004219 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004220 // Create a remote offer with secured transport disabled.
4221 cricket::MediaSessionOptions options;
4222 JsepSessionDescription* offer(CreateRemoteOffer(
4223 options, cricket::SEC_DISABLED));
4224 // Adds a DTLS fingerprint to the remote offer.
4225 cricket::SessionDescription* sdp = offer->description();
4226 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4227 ASSERT_TRUE(audio != NULL);
4228 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4229 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004230 rtc::SSLFingerprint::CreateFromRfc4572(
4231 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004232 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004233 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004234}
4235
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004236TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004237 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004238 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004239 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004240 SessionDescriptionInterface* offer = CreateOffer();
4241
4242 SetLocalDescriptionWithoutError(offer);
4243
4244 voice_channel_ = media_engine_->GetVoiceChannel(0);
4245
4246 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004247 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004248 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004249}
4250
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004251// Tests that we can renegotiate new media content with ICE candidates in the
4252// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004253TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004254 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004255 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004256 SetFactoryDtlsSrtp();
4257
deadbeefab9b2d12015-10-14 11:33:11 -07004258 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004259 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260 SetLocalDescriptionWithoutError(offer);
4261
4262 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4263 SetRemoteDescriptionWithoutError(answer);
4264
4265 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004266 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4268
4269 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004270 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004271 candidate1.set_component(1);
4272 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4273 candidate1);
4274 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4275 SetRemoteDescriptionWithoutError(offer);
4276
htaa2a49d92016-03-04 02:51:39 -08004277 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004278 SetLocalDescriptionWithoutError(answer);
4279}
4280
4281// Tests that we can renegotiate new media content with ICE candidates separated
4282// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004283TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004284 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004285 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004286 SetFactoryDtlsSrtp();
4287
deadbeefab9b2d12015-10-14 11:33:11 -07004288 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004289 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004290 SetLocalDescriptionWithoutError(offer);
4291
4292 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4293 SetRemoteDescriptionWithoutError(answer);
4294
4295 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004296 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004297 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4298 SetRemoteDescriptionWithoutError(offer);
4299
4300 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004301 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004302 candidate1.set_component(1);
4303 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4304 candidate1);
4305 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4306
htaa2a49d92016-03-04 02:51:39 -08004307 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004308 SetLocalDescriptionWithoutError(answer);
4309}
honghaiz7f777492016-02-02 21:54:01 -08004310
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004311// Tests that RTX codec is removed from the answer when it isn't supported
4312// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004313TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004314 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004315 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004316 std::string offer_sdp(kSdpWithRtx);
4317
4318 SessionDescriptionInterface* offer =
4319 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4320 EXPECT_TRUE(offer->ToString(&offer_sdp));
4321
4322 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004323 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004324 SetRemoteDescriptionWithoutError(offer);
4325
htaa2a49d92016-03-04 02:51:39 -08004326 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004327 // Answer SDP does not contain the RTX codec.
4328 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004329 SetLocalDescriptionWithoutError(answer);
4330}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004331
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004332// This verifies that the voice channel after bundle has both options from video
4333// and voice channels.
4334TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4335 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004336 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004337
4338 PeerConnectionInterface::RTCOfferAnswerOptions options;
4339 options.use_rtp_mux = true;
4340
4341 SessionDescriptionInterface* offer = CreateOffer(options);
4342 SetLocalDescriptionWithoutError(offer);
4343
4344 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4345 rtc::Socket::Option::OPT_SNDBUF, 4000);
4346
4347 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4348 rtc::Socket::Option::OPT_RCVBUF, 8000);
4349
4350 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004351 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004352 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4353 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004354 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004355 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4356
deadbeefcbecd352015-09-23 11:50:27 -07004357 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004358 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4359 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004360 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004361 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4362
deadbeefcbecd352015-09-23 11:50:27 -07004363 EXPECT_NE(session_->voice_rtp_transport_channel(),
4364 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004365
deadbeefab9b2d12015-10-14 11:33:11 -07004366 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004367 SessionDescriptionInterface* answer =
4368 CreateRemoteAnswer(session_->local_description());
4369 SetRemoteDescriptionWithoutError(answer);
4370
deadbeefcbecd352015-09-23 11:50:27 -07004371 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004372 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4373 EXPECT_EQ(4000, option_val);
4374
deadbeefcbecd352015-09-23 11:50:27 -07004375 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004376 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4377 EXPECT_EQ(8000, option_val);
4378}
4379
tommi0f620f42015-07-09 03:25:02 -07004380// Test creating a session, request multiple offers, destroy the session
4381// and make sure we got success/failure callbacks for all of the requests.
4382// Background: crbug.com/507307
4383TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4384 Init();
4385
4386 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4387 PeerConnectionInterface::RTCOfferAnswerOptions options;
4388 options.offer_to_receive_audio =
4389 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004390 cricket::MediaSessionOptions session_options;
4391 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004392
4393 for (auto& o : observers) {
4394 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004395 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004396 }
4397
4398 session_.reset();
4399
tommi0f620f42015-07-09 03:25:02 -07004400 for (auto& o : observers) {
4401 // We expect to have received a notification now even if the session was
4402 // terminated. The offer creation may or may not have succeeded, but we
4403 // must have received a notification which, so the only invalid state
4404 // is kInit.
4405 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4406 }
4407}
4408
stefanc1aeaf02015-10-15 07:26:07 -07004409TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4410 TestPacketOptions();
4411}
4412
deadbeef057ecf02016-01-20 14:30:43 -08004413// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4414// is destroyed.
4415TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4416 Init();
4417 session_.reset();
4418 EXPECT_TRUE(session_destroyed_);
4419}
4420
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004421// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4422// currently fails because upon disconnection and reconnection OnIceComplete is
4423// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004424
deadbeefcbecd352015-09-23 11:50:27 -07004425INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4426 WebRtcSessionTest,
4427 testing::Values(ALREADY_GENERATED,
4428 DTLS_IDENTITY_STORE));