blob: f739c16abec962795df2e1fe06fe330c5c021473 [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"
nissec80e7412017-01-11 05:56:46 -080026#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/fakenetwork.h"
28#include "webrtc/base/firewallsocketserver.h"
29#include "webrtc/base/gunit.h"
30#include "webrtc/base/logging.h"
31#include "webrtc/base/network.h"
32#include "webrtc/base/physicalsocketserver.h"
33#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020034#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/sslstreamadapter.h"
36#include "webrtc/base/stringutils.h"
37#include "webrtc/base/thread.h"
38#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070039#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080040#include "webrtc/media/base/fakemediaengine.h"
41#include "webrtc/media/base/fakevideorenderer.h"
42#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010043#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080044#include "webrtc/media/sctp/sctptransportinternal.h"
johan669d69b2016-11-08 14:14:08 -080045#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080046#include "webrtc/p2p/base/stunserver.h"
47#include "webrtc/p2p/base/teststunserver.h"
48#include "webrtc/p2p/base/testturnserver.h"
49#include "webrtc/p2p/base/transportchannel.h"
50#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010051#include "webrtc/pc/channelmanager.h"
52#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
54#define MAYBE_SKIP_TEST(feature) \
55 if (!(feature())) { \
56 LOG(LS_INFO) << "Feature disabled... skipping"; \
57 return; \
58 }
59
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000065using webrtc::CreateSessionDescriptionObserver;
66using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070067using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070068using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070070using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071using webrtc::JsepIceCandidate;
72using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000073using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::PeerConnectionInterface;
75using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070076using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000079using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kCreateChannelFailed;
81using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000083using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000084using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000085using webrtc::kSdpWithoutDtlsFingerprint;
86using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000088using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000089using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000091typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
92
wu@webrtc.org364f2042013-11-20 21:49:41 +000093static const int kClientAddrPort = 0;
94static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000095static const char kClientIPv6AddrHost1[] =
96 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000097static const char kClientAddrHost2[] = "22.22.22.22";
98static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000099static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
100static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000101static const char kTurnUsername[] = "test";
102static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
104static const char kSessionVersion[] = "1";
105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106// Media index of candidates belonging to the first media content.
107static const int kMediaContentIndex0 = 0;
108static const char kMediaContentName0[] = "audio";
109
110// Media index of candidates belonging to the second media content.
111static const int kMediaContentIndex1 = 1;
112static const char kMediaContentName1[] = "video";
113
deadbeef953c2ce2017-01-09 14:53:41 -0800114static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700116// STUN timeout with all retransmissions is a total of 9500ms.
117static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000119static const char kFakeDtlsFingerprint[] =
120 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
121 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
122
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000123static const char kTooLongIceUfragPwd[] =
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
125 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
126 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
127 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
128
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000129static const char kSdpWithRtx[] =
130 "v=0\r\n"
131 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
132 "s=-\r\n"
133 "t=0 0\r\n"
134 "a=msid-semantic: WMS stream1\r\n"
135 "m=video 9 RTP/SAVPF 0 96\r\n"
136 "c=IN IP4 0.0.0.0\r\n"
137 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
138 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
139 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
140 "a=mid:video\r\n"
141 "a=sendrecv\r\n"
142 "a=rtcp-mux\r\n"
143 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
144 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
145 "a=rtpmap:0 fake_video_codec/90000\r\n"
146 "a=rtpmap:96 rtx/90000\r\n"
147 "a=fmtp:96 apt=0\r\n";
148
deadbeefab9b2d12015-10-14 11:33:11 -0700149static const char kStream1[] = "stream1";
150static const char kVideoTrack1[] = "video1";
151static const char kAudioTrack1[] = "audio1";
152
153static const char kStream2[] = "stream2";
154static const char kVideoTrack2[] = "video2";
155static const char kAudioTrack2[] = "audio2";
156
Henrik Boström87713d02015-08-25 09:53:21 +0200157enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159class MockIceObserver : public webrtc::IceObserver {
160 public:
161 MockIceObserver()
162 : oncandidatesready_(false),
163 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
164 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
165 }
166
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200167 virtual ~MockIceObserver() = default;
168
perkjdfb769d2016-02-09 03:09:43 -0800169 void OnIceConnectionChange(
170 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700172 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
perkjdfb769d2016-02-09 03:09:43 -0800174 void OnIceGatheringChange(
175 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 // We can never transition back to "new".
177 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
178 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800179 oncandidatesready_ =
180 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182
183 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800184 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000185 switch (candidate->sdp_mline_index()) {
186 case kMediaContentIndex0:
187 mline_0_candidates_.push_back(candidate->candidate());
188 break;
189 case kMediaContentIndex1:
190 mline_1_candidates_.push_back(candidate->candidate());
191 break;
192 default:
nissec80e7412017-01-11 05:56:46 -0800193 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // The ICE gathering state should always be Gathering when a candidate is
197 // received (or possibly Completed in the case of the final candidate).
198 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
199 }
200
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700201 // Some local candidates are removed.
202 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700203 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700204 num_candidates_removed_ += candidates.size();
205 }
206
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 bool oncandidatesready_;
208 std::vector<cricket::Candidate> mline_0_candidates_;
209 std::vector<cricket::Candidate> mline_1_candidates_;
210 PeerConnectionInterface::IceConnectionState ice_connection_state_;
211 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700212 std::vector<PeerConnectionInterface::IceConnectionState>
213 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700214 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215};
216
deadbeef953c2ce2017-01-09 14:53:41 -0800217// Used for tests in this file to verify that WebRtcSession responds to signals
218// from the SctpTransport correctly, and calls Start with the correct
219// local/remote ports.
220class FakeSctpTransport : public cricket::SctpTransportInternal {
221 public:
222 void SetTransportChannel(cricket::TransportChannel* channel) override {}
223 bool Start(int local_port, int remote_port) override {
224 local_port_ = local_port;
225 remote_port_ = remote_port;
226 return true;
227 }
228 bool OpenStream(int sid) override { return true; }
229 bool ResetStream(int sid) override { return true; }
230 bool SendData(const cricket::SendDataParams& params,
231 const rtc::CopyOnWriteBuffer& payload,
232 cricket::SendDataResult* result = nullptr) override {
233 return true;
234 }
235 bool ReadyToSendData() override { return true; }
236 void set_debug_name_for_testing(const char* debug_name) override {}
237
238 int local_port() const { return local_port_; }
239 int remote_port() const { return remote_port_; }
240
241 private:
242 int local_port_ = -1;
243 int remote_port_ = -1;
244};
245
246class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
247 public:
248 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
249 cricket::TransportChannel*) override {
250 last_fake_sctp_transport_ = new FakeSctpTransport();
251 return std::unique_ptr<cricket::SctpTransportInternal>(
252 last_fake_sctp_transport_);
253 }
254
255 FakeSctpTransport* last_fake_sctp_transport() {
256 return last_fake_sctp_transport_;
257 }
258
259 private:
260 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
261};
262
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263class WebRtcSessionForTest : public webrtc::WebRtcSession {
264 public:
zhihuang29ff8442016-07-27 11:07:25 -0700265 WebRtcSessionForTest(
266 webrtc::MediaControllerInterface* media_controller,
267 rtc::Thread* network_thread,
268 rtc::Thread* worker_thread,
269 rtc::Thread* signaling_thread,
270 cricket::PortAllocator* port_allocator,
271 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800272 std::unique_ptr<cricket::TransportController> transport_controller,
273 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
stefanc1aeaf02015-10-15 07:26:07 -0700274 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700275 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700276 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700277 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700278 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800279 std::move(transport_controller),
280 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 RegisterIceObserver(ice_observer);
282 }
283 virtual ~WebRtcSessionForTest() {}
284
deadbeefcbecd352015-09-23 11:50:27 -0700285 // Note that these methods are only safe to use if the signaling thread
286 // is the same as the worker thread
johan669d69b2016-11-08 14:14:08 -0800287 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700288 return rtp_transport_channel(voice_channel());
289 }
290
johan669d69b2016-11-08 14:14:08 -0800291 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return rtcp_transport_channel(voice_channel());
293 }
294
johan669d69b2016-11-08 14:14:08 -0800295 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700296 return rtp_transport_channel(video_channel());
297 }
298
johan669d69b2016-11-08 14:14:08 -0800299 rtc::PacketTransportInterface* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700300 return rtcp_transport_channel(video_channel());
301 }
302
deadbeefcbecd352015-09-23 11:50:27 -0700303 private:
johan669d69b2016-11-08 14:14:08 -0800304 rtc::PacketTransportInterface* rtp_transport_channel(
305 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700306 if (!ch) {
307 return nullptr;
308 }
309 return ch->transport_channel();
310 }
311
johan669d69b2016-11-08 14:14:08 -0800312 rtc::PacketTransportInterface* rtcp_transport_channel(
313 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700314 if (!ch) {
315 return nullptr;
316 }
317 return ch->rtcp_transport_channel();
318 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319};
320
wu@webrtc.org91053e72013-08-10 07:18:04 +0000321class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000322 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000324 enum State {
325 kInit,
326 kFailed,
327 kSucceeded,
328 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000329 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000330
331 // CreateSessionDescriptionObserver implementation.
332 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000333 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000334 state_ = kSucceeded;
335 }
336 virtual void OnFailure(const std::string& error) {
337 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
339
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000340 SessionDescriptionInterface* description() { return description_.get(); }
341
342 SessionDescriptionInterface* ReleaseDescription() {
343 return description_.release();
344 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345
wu@webrtc.org91053e72013-08-10 07:18:04 +0000346 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347
wu@webrtc.org91053e72013-08-10 07:18:04 +0000348 protected:
349 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350
351 private:
kwibergd1fe2812016-04-27 06:47:29 -0700352 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000353 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354};
355
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800356class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000357 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800358 FakeAudioSource() : sink_(NULL) {}
359 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000360 if (sink_)
361 sink_->OnClose();
362 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000363
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000364 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000365
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800366 const cricket::AudioSource::Sink* sink() const { return sink_; }
367
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000368 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800369 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000370};
371
Henrik Boström87713d02015-08-25 09:53:21 +0200372class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700373 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
374 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 protected:
376 // TODO Investigate why ChannelManager crashes, if it's created
377 // after stun_server.
378 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700379 : media_engine_(new cricket::FakeMediaEngine()),
380 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700381 channel_manager_(new cricket::ChannelManager(media_engine_,
382 data_engine_,
383 rtc::Thread::Current())),
384 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700385 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800386 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
387 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700388 channel_manager_.get(),
389 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700390 tdesc_factory_(new cricket::TransportDescriptionFactory()),
391 desc_factory_(
392 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
393 tdesc_factory_.get())),
394 pss_(new rtc::PhysicalSocketServer),
395 vss_(new rtc::VirtualSocketServer(pss_.get())),
396 fss_(new rtc::FirewallSocketServer(vss_.get())),
397 ss_scope_(fss_.get()),
398 stun_socket_addr_(
399 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
400 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
401 stun_socket_addr_)),
402 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
403 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000404 cricket::ServerAddresses stun_servers;
405 stun_servers.insert(stun_socket_addr_);
406 allocator_.reset(new cricket::BasicPortAllocator(
407 &network_manager_,
408 stun_servers,
409 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000410 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700411 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 EXPECT_TRUE(channel_manager_->Init());
413 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000414 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 }
416
417 void AddInterface(const SocketAddress& addr) {
418 network_manager_.AddInterface(addr);
419 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700420 void RemoveInterface(const SocketAddress& addr) {
421 network_manager_.RemoveInterface(addr);
422 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
Henrik Boströmd79599d2016-06-01 13:58:50 +0200424 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
425 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
426 // options. When DTLS is enabled a certificate will be used if provided,
427 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000428 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800429 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
430 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800432 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700434 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700435 rtc::Thread::Current(), allocator_.get(), &observer_,
436 std::unique_ptr<cricket::TransportController>(
437 new cricket::TransportController(rtc::Thread::Current(),
438 rtc::Thread::Current(),
deadbeef953c2ce2017-01-09 14:53:41 -0800439 allocator_.get())),
440 std::unique_ptr<FakeSctpTransportFactory>(
441 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700442 session_->SignalDataChannelOpenMessage.connect(
443 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800444 session_->GetOnDestroyedSignal()->connect(
445 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446
zhihuang4dfb8ce2016-11-23 10:30:12 -0800447 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
449 observer_.ice_connection_state_);
450 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
451 observer_.ice_gathering_state_);
452
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200453 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800454 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700455 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 }
457
deadbeefab9b2d12015-10-14 11:33:11 -0700458 void OnDataChannelOpenMessage(const std::string& label,
459 const InternalDataChannelInit& config) {
460 last_data_channel_label_ = label;
461 last_data_channel_config_ = config;
462 }
463
deadbeef057ecf02016-01-20 14:30:43 -0800464 void OnSessionDestroyed() { session_destroyed_ = true; }
465
zhihuang4dfb8ce2016-11-23 10:30:12 -0800466 void Init() {
467 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
468 }
469
470 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
471 Init(nullptr, rtcp_mux_policy);
472 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000473
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000474 void InitWithBundlePolicy(
475 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800476 configuration_.bundle_policy = bundle_policy;
477 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700478 }
479
480 void InitWithRtcpMuxPolicy(
481 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
482 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800483 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000484 }
485
Henrik Boström87713d02015-08-25 09:53:21 +0200486 // Successfully init with DTLS; with a certificate generated and supplied or
487 // with a store that generates it for us.
488 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200489 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200490 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800491 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200492 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200493 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200494 cert_generator.reset(new FakeRTCCertificateGenerator());
495 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200496 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700497 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200498 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800499 Init(std::move(cert_generator),
500 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200501 }
502
503 // Init with DTLS with a store that will fail to generate a certificate.
504 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200505 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
506 new FakeRTCCertificateGenerator());
507 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800508 Init(std::move(cert_generator),
509 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000510 }
511
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 void InitWithDtmfCodec() {
513 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700514 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
515 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 std::vector<cricket::AudioCodec> codecs;
517 codecs.push_back(kTelephoneEventCodec);
518 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700519 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000520 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 }
522
jbauchcb560652016-08-04 05:20:32 -0700523 void InitWithGcm() {
524 rtc::CryptoOptions crypto_options;
525 crypto_options.enable_gcm_crypto_suites = true;
526 channel_manager_->SetCryptoOptions(crypto_options);
527 with_gcm_ = true;
528 Init();
529 }
530
deadbeefab9b2d12015-10-14 11:33:11 -0700531 void SendAudioVideoStream1() {
532 send_stream_1_ = true;
533 send_stream_2_ = false;
534 send_audio_ = true;
535 send_video_ = true;
536 }
537
538 void SendAudioVideoStream2() {
539 send_stream_1_ = false;
540 send_stream_2_ = true;
541 send_audio_ = true;
542 send_video_ = true;
543 }
544
545 void SendAudioVideoStream1And2() {
546 send_stream_1_ = true;
547 send_stream_2_ = true;
548 send_audio_ = true;
549 send_video_ = true;
550 }
551
552 void SendNothing() {
553 send_stream_1_ = false;
554 send_stream_2_ = false;
555 send_audio_ = false;
556 send_video_ = false;
557 }
558
559 void SendAudioOnlyStream2() {
560 send_stream_1_ = false;
561 send_stream_2_ = true;
562 send_audio_ = true;
563 send_video_ = false;
564 }
565
566 void SendVideoOnlyStream2() {
567 send_stream_1_ = false;
568 send_stream_2_ = true;
569 send_audio_ = false;
570 send_video_ = true;
571 }
572
573 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
574 if (send_stream_1_ && send_audio_) {
575 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
576 kStream1);
577 }
578 if (send_stream_1_ && send_video_) {
579 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
580 kStream1);
581 }
582 if (send_stream_2_ && send_audio_) {
583 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
584 kStream2);
585 }
586 if (send_stream_2_ && send_video_) {
587 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
588 kStream2);
589 }
590 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
591 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
592 data_channel_->label(),
593 data_channel_->label());
594 }
595 }
596
597 void GetOptionsForOffer(
598 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
599 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800600 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700601
deadbeefc80741f2015-10-22 13:14:45 -0700602 AddStreamsToOptions(session_options);
603 if (rtc_options.offer_to_receive_audio ==
604 RTCOfferAnswerOptions::kUndefined) {
605 session_options->recv_audio =
606 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
607 }
608 if (rtc_options.offer_to_receive_video ==
609 RTCOfferAnswerOptions::kUndefined) {
610 session_options->recv_video =
611 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
612 }
613 session_options->bundle_enabled =
614 session_options->bundle_enabled &&
615 (session_options->has_audio() || session_options->has_video() ||
616 session_options->has_data());
617
deadbeefab9b2d12015-10-14 11:33:11 -0700618 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
619 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700620 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
621 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700622 }
jbauchcb560652016-08-04 05:20:32 -0700623
624 if (with_gcm_) {
625 session_options->crypto_options.enable_gcm_crypto_suites = true;
626 }
deadbeefab9b2d12015-10-14 11:33:11 -0700627 }
628
htaa2a49d92016-03-04 02:51:39 -0800629 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
630 // ParseConstraintsForAnswer is used to set some defaults.
631 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700632
deadbeefc80741f2015-10-22 13:14:45 -0700633 AddStreamsToOptions(session_options);
634 session_options->bundle_enabled =
635 session_options->bundle_enabled &&
636 (session_options->has_audio() || session_options->has_video() ||
637 session_options->has_data());
638
zhihuang9763d562016-08-05 11:14:50 -0700639 if (session_->data_channel_type() != cricket::DCT_RTP) {
640 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700641 }
jbauchcb560652016-08-04 05:20:32 -0700642
643 if (with_gcm_) {
644 session_options->crypto_options.enable_gcm_crypto_suites = true;
645 }
deadbeefab9b2d12015-10-14 11:33:11 -0700646 }
647
648 // Creates a local offer and applies it. Starts ICE.
649 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 // to decide which streams to create.
651 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 SetLocalDescriptionWithoutError(offer);
654 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
655 observer_.ice_gathering_state_,
656 kIceCandidatesTimeout);
657 }
658
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000659 SessionDescriptionInterface* CreateOffer() {
660 PeerConnectionInterface::RTCOfferAnswerOptions options;
661 options.offer_to_receive_audio =
662 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
663
664 return CreateOffer(options);
665 }
666
wu@webrtc.org91053e72013-08-10 07:18:04 +0000667 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800668 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000669 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000670 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700671 cricket::MediaSessionOptions session_options;
672 GetOptionsForOffer(options, &session_options);
673 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000674 EXPECT_TRUE_WAIT(
675 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000676 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000677 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000678 }
679
680 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800681 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000682 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000683 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800684 cricket::MediaSessionOptions session_options = options;
685 GetOptionsForAnswer(&session_options);
686 // Overwrite recv_audio and recv_video with passed-in values.
687 session_options.recv_video = options.recv_video;
688 session_options.recv_audio = options.recv_audio;
689 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000690 EXPECT_TRUE_WAIT(
691 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000692 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000693 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000694 }
695
htaa2a49d92016-03-04 02:51:39 -0800696 SessionDescriptionInterface* CreateAnswer() {
697 cricket::MediaSessionOptions options;
698 options.recv_video = true;
699 options.recv_audio = true;
700 return CreateAnswer(options);
701 }
702
wu@webrtc.org364f2042013-11-20 21:49:41 +0000703 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 return (session_->voice_channel() != NULL &&
705 session_->video_channel() != NULL);
706 }
707
jbauchcb560652016-08-04 05:20:32 -0700708 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
709 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 ASSERT_TRUE(session_.get() != NULL);
711 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
712 ASSERT_TRUE(content != NULL);
713 const cricket::AudioContentDescription* audio_content =
714 static_cast<const cricket::AudioContentDescription*>(
715 content->description);
716 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700717 if (!gcm_enabled) {
718 ASSERT_EQ(1U, audio_content->cryptos().size());
719 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
720 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
721 audio_content->cryptos()[0].cipher_suite);
722 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
723 audio_content->protocol());
724 } else {
725 // The offer contains 3 possible crypto suites, the answer 1.
726 EXPECT_LE(1U, audio_content->cryptos().size());
727 EXPECT_NE(2U, audio_content->cryptos().size());
728 EXPECT_GE(3U, audio_content->cryptos().size());
729 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
730 ASSERT_EQ("AEAD_AES_256_GCM",
731 audio_content->cryptos()[0].cipher_suite);
732 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
733 audio_content->protocol());
734 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
736 content = cricket::GetFirstVideoContent(sdp);
737 ASSERT_TRUE(content != NULL);
738 const cricket::VideoContentDescription* video_content =
739 static_cast<const cricket::VideoContentDescription*>(
740 content->description);
741 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700742 if (!gcm_enabled) {
743 ASSERT_EQ(1U, video_content->cryptos().size());
744 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
745 video_content->cryptos()[0].cipher_suite);
746 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
747 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
748 video_content->protocol());
749 } else {
750 // The offer contains 3 possible crypto suites, the answer 1.
751 EXPECT_LE(1U, video_content->cryptos().size());
752 EXPECT_NE(2U, video_content->cryptos().size());
753 EXPECT_GE(3U, video_content->cryptos().size());
754 ASSERT_EQ("AEAD_AES_256_GCM",
755 video_content->cryptos()[0].cipher_suite);
756 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
757 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
758 video_content->protocol());
759 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 }
761
762 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
763 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
764 ASSERT_TRUE(content != NULL);
765 const cricket::AudioContentDescription* audio_content =
766 static_cast<const cricket::AudioContentDescription*>(
767 content->description);
768 ASSERT_TRUE(audio_content != NULL);
769 ASSERT_EQ(0U, audio_content->cryptos().size());
770
771 content = cricket::GetFirstVideoContent(sdp);
772 ASSERT_TRUE(content != NULL);
773 const cricket::VideoContentDescription* video_content =
774 static_cast<const cricket::VideoContentDescription*>(
775 content->description);
776 ASSERT_TRUE(video_content != NULL);
777 ASSERT_EQ(0U, video_content->cryptos().size());
778
779 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700780 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700782 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 video_content->protocol());
784 } else {
785 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
786 audio_content->protocol());
787 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
788 video_content->protocol());
789 }
790 }
791
792 // Set the internal fake description factories to do DTLS-SRTP.
793 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000794 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000796 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200797 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800798 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700799 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800800 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
802 }
803
804 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
805 bool expected) {
806 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
807 ASSERT_TRUE(audio != NULL);
808 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 const TransportInfo* video = sdp->GetTransportInfoByName("video");
810 ASSERT_TRUE(video != NULL);
811 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 }
813
814 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000815 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000817 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000818 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000820 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000822 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
823 offer);
htaa2a49d92016-03-04 02:51:39 -0800824 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 // Answer should be NULL as no crypto params in offer.
826 ASSERT_TRUE(answer == NULL);
827 }
828
829 void VerifyAnswerFromCryptoOffer() {
830 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000831 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700833 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
835 ASSERT_TRUE(offer.get() != NULL);
836 VerifyCryptoParams(offer->description());
837 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700838 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 ASSERT_TRUE(answer.get() != NULL);
840 VerifyCryptoParams(answer->description());
841 }
842
deadbeef0ed85b22016-02-23 17:24:52 -0800843 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
844 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800846 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848
849 const cricket::ContentInfos& contents = desc1->contents();
850 cricket::ContentInfos::const_iterator it = contents.begin();
851
852 for (; it != contents.end(); ++it) {
853 const cricket::TransportDescription* transport_desc1 =
854 desc1->GetTransportDescriptionByName(it->name);
855 const cricket::TransportDescription* transport_desc2 =
856 desc2->GetTransportDescriptionByName(it->name);
857 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800858 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 }
860 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
861 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800862 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 }
864 }
deadbeef0ed85b22016-02-23 17:24:52 -0800865 return true;
866 }
867
868 // Compares ufrag/password only for the specified |media_type|.
869 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
870 const cricket::SessionDescription* desc2,
871 cricket::MediaType media_type) {
872 if (desc1->contents().size() != desc2->contents().size()) {
873 return false;
874 }
875
876 const cricket::ContentInfo* cinfo =
877 cricket::GetFirstMediaContent(desc1->contents(), media_type);
878 const cricket::TransportDescription* transport_desc1 =
879 desc1->GetTransportDescriptionByName(cinfo->name);
880 const cricket::TransportDescription* transport_desc2 =
881 desc2->GetTransportDescriptionByName(cinfo->name);
882 if (!transport_desc1 || !transport_desc2) {
883 return false;
884 }
885 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
886 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
887 return false;
888 }
889 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000891
892 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
893 std::string *sdp) {
894 const cricket::SessionDescription* desc = current_desc->description();
895 EXPECT_TRUE(current_desc->ToString(sdp));
896
897 const cricket::ContentInfos& contents = desc->contents();
898 cricket::ContentInfos::const_iterator it = contents.begin();
899 // Replace ufrag and pwd lines with empty strings.
900 for (; it != contents.end(); ++it) {
901 const cricket::TransportDescription* transport_desc =
902 desc->GetTransportDescriptionByName(it->name);
903 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
904 + "\r\n";
905 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
906 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000907 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000908 "", 0,
909 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000910 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000911 "", 0,
912 sdp);
913 }
914 }
915
deadbeef0ed85b22016-02-23 17:24:52 -0800916 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
917 const std::string& ufrag,
918 const std::string& pwd) {
919 cricket::SessionDescription* desc = current_desc->description();
920 for (TransportInfo& transport_info : desc->transport_infos()) {
921 cricket::TransportDescription& transport_desc =
922 transport_info.description;
923 transport_desc.ice_ufrag = ufrag;
924 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000925 }
926 }
927
deadbeef0ed85b22016-02-23 17:24:52 -0800928 // Sets ufrag/pwd for specified |media_type|.
929 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
930 cricket::MediaType media_type,
931 const std::string& ufrag,
932 const std::string& pwd) {
933 cricket::SessionDescription* desc = current_desc->description();
934 const cricket::ContentInfo* cinfo =
935 cricket::GetFirstMediaContent(desc->contents(), media_type);
936 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
937 cricket::TransportDescription* transport_desc =
938 &transport_info->description;
939 transport_desc->ice_ufrag = ufrag;
940 transport_desc->ice_pwd = pwd;
941 }
942
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 // Creates a remote offer and and applies it as a remote description,
944 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700945 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 // to decide which local and remote streams to create.
947 void CreateAndSetRemoteOfferAndLocalAnswer() {
948 SessionDescriptionInterface* offer = CreateRemoteOffer();
949 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800950 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 SetLocalDescriptionWithoutError(answer);
952 }
953 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
954 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700955 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 }
957 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700958 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 SetLocalDescriptionWithoutError(desc);
960 EXPECT_EQ(expected_state, session_->state());
961 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000962 void SetLocalDescriptionExpectError(const std::string& action,
963 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 SessionDescriptionInterface* desc) {
965 std::string error;
966 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 std::string sdp_type = "local ";
968 sdp_type.append(action);
969 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_NE(std::string::npos, error.find(expected_error));
971 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000972 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
973 SessionDescriptionInterface* desc) {
974 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
975 expected_error, desc);
976 }
977 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
978 SessionDescriptionInterface* desc) {
979 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
980 expected_error, desc);
981 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
983 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
984 }
985 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700986 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 SetRemoteDescriptionWithoutError(desc);
988 EXPECT_EQ(expected_state, session_->state());
989 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000990 void SetRemoteDescriptionExpectError(const std::string& action,
991 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 SessionDescriptionInterface* desc) {
993 std::string error;
994 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000995 std::string sdp_type = "remote ";
996 sdp_type.append(action);
997 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 EXPECT_NE(std::string::npos, error.find(expected_error));
999 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001000 void SetRemoteDescriptionOfferExpectError(
1001 const std::string& expected_error, SessionDescriptionInterface* desc) {
1002 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
1003 expected_error, desc);
1004 }
1005 void SetRemoteDescriptionPranswerExpectError(
1006 const std::string& expected_error, SessionDescriptionInterface* desc) {
1007 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
1008 expected_error, desc);
1009 }
1010 void SetRemoteDescriptionAnswerExpectError(
1011 const std::string& expected_error, SessionDescriptionInterface* desc) {
1012 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
1013 expected_error, desc);
1014 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015
1016 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
1017 SessionDescriptionInterface** nocrypto_answer) {
1018 // Create a SDP without Crypto.
1019 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001020 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 options.bundle_enabled = true;
1022 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1023 ASSERT_TRUE(*offer != NULL);
1024 VerifyCryptoParams((*offer)->description());
1025
1026 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1027 cricket::SEC_DISABLED);
1028 EXPECT_TRUE(*nocrypto_answer != NULL);
1029 }
1030
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001031 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1032 SessionDescriptionInterface** nodtls_answer) {
1033 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001034 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001035 options.bundle_enabled = true;
1036
kwibergd1fe2812016-04-27 06:47:29 -07001037 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001038 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1039
1040 *nodtls_answer =
1041 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1042 EXPECT_TRUE(*nodtls_answer != NULL);
1043 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1044 VerifyCryptoParams((*nodtls_answer)->description());
1045
1046 SetFactoryDtlsSrtp();
1047 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1048 ASSERT_TRUE(*offer != NULL);
1049 VerifyFingerprintStatus((*offer)->description(), true);
1050 VerifyCryptoParams((*offer)->description());
1051 }
1052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 JsepSessionDescription* CreateRemoteOfferWithVersion(
1054 cricket::MediaSessionOptions options,
1055 cricket::SecurePolicy secure_policy,
1056 const std::string& session_version,
1057 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001058 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 const cricket::SessionDescription* cricket_desc = NULL;
1060 if (current_desc) {
1061 cricket_desc = current_desc->description();
1062 session_id = current_desc->session_id();
1063 }
1064
1065 desc_factory_->set_secure(secure_policy);
1066 JsepSessionDescription* offer(
1067 new JsepSessionDescription(JsepSessionDescription::kOffer));
1068 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1069 session_id, session_version)) {
1070 delete offer;
1071 offer = NULL;
1072 }
1073 return offer;
1074 }
1075 JsepSessionDescription* CreateRemoteOffer(
1076 cricket::MediaSessionOptions options) {
1077 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1078 kSessionVersion, NULL);
1079 }
1080 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001081 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1082 return CreateRemoteOfferWithVersion(
1083 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 }
1085 JsepSessionDescription* CreateRemoteOffer(
1086 cricket::MediaSessionOptions options,
1087 const SessionDescriptionInterface* current_desc) {
1088 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1089 kSessionVersion, current_desc);
1090 }
1091
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001092 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1093 const char* sctp_stream_name, int new_port,
1094 cricket::MediaSessionOptions options) {
1095 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001096 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1097 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001098 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1099 }
1100
1101 // Takes ownership of offer_basis (and deletes it).
1102 JsepSessionDescription* ChangeSDPSctpPort(
1103 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1104 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1105 // SessionDescription from the mutated string.
1106 const char* default_port_str = "5000";
1107 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001108 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001109 std::string offer_str;
1110 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001111 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001112 new_port_str, strlen(new_port_str),
1113 &offer_str);
1114 JsepSessionDescription* offer = new JsepSessionDescription(
1115 offer_basis->type());
1116 delete offer_basis;
1117 offer->Initialize(offer_str, NULL);
1118 return offer;
1119 }
1120
deadbeefab9b2d12015-10-14 11:33:11 -07001121 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 // before this function to decide which streams to create.
1123 JsepSessionDescription* CreateRemoteOffer() {
1124 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001125 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 return CreateRemoteOffer(options, session_->remote_description());
1127 }
1128
1129 JsepSessionDescription* CreateRemoteAnswer(
1130 const SessionDescriptionInterface* offer,
1131 cricket::MediaSessionOptions options,
1132 cricket::SecurePolicy policy) {
1133 desc_factory_->set_secure(policy);
1134 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001135 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 JsepSessionDescription* answer(
1137 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1138 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1139 options, NULL),
1140 session_id, kSessionVersion)) {
1141 delete answer;
1142 answer = NULL;
1143 }
1144 return answer;
1145 }
1146
1147 JsepSessionDescription* CreateRemoteAnswer(
1148 const SessionDescriptionInterface* offer,
1149 cricket::MediaSessionOptions options) {
1150 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1151 }
1152
deadbeefab9b2d12015-10-14 11:33:11 -07001153 // Creates an answer session description.
1154 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 // to decide which streams to create.
1156 JsepSessionDescription* CreateRemoteAnswer(
1157 const SessionDescriptionInterface* offer) {
1158 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001159 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1161 }
1162
1163 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001164 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001165 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001166 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001167
1168 PeerConnectionInterface::RTCOfferAnswerOptions options;
1169 options.use_rtp_mux = bundle;
1170
1171 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1173 // and answer.
1174 SetLocalDescriptionWithoutError(offer);
1175
kwibergd1fe2812016-04-27 06:47:29 -07001176 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001177 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 std::string sdp;
1179 EXPECT_TRUE(answer->ToString(&sdp));
1180
1181 size_t expected_candidate_num = 2;
1182 if (!rtcp_mux) {
1183 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1184 // for rtp and rtcp.
1185 expected_candidate_num = 4;
1186 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 const std::string kRtcpMux = "a=rtcp-mux";
1188 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001189 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 kXRtcpMux.c_str(), kXRtcpMux.length(),
1191 &sdp);
1192 }
1193
1194 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1195 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196
1197 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001198 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1200 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001201 if (bundle) {
1202 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1203 } else {
1204 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 }
1206 }
1207 // Tests that we can only send DTMF when the dtmf codec is supported.
1208 void TestCanInsertDtmf(bool can) {
1209 if (can) {
1210 InitWithDtmfCodec();
1211 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001212 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 }
deadbeefab9b2d12015-10-14 11:33:11 -07001214 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215 CreateAndSetRemoteOfferAndLocalAnswer();
1216 EXPECT_FALSE(session_->CanInsertDtmf(""));
1217 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1218 }
1219
zhihuang3a334652016-05-05 18:37:49 -07001220 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1221 const std::string& codec_name) {
1222 for (const auto& content : desc->description()->contents()) {
1223 if (static_cast<cricket::MediaContentDescription*>(content.description)
1224 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1225 const auto* mdesc =
1226 static_cast<cricket::VideoContentDescription*>(content.description);
1227 for (const auto& codec : mdesc->codecs()) {
1228 if (codec.name == codec_name) {
1229 return true;
1230 }
1231 }
1232 }
1233 }
1234 return false;
1235 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001236 // Helper class to configure loopback network and verify Best
1237 // Connection using right IP protocol for TestLoopbackCall
1238 // method. LoopbackNetworkManager applies firewall rules to block
1239 // all ping traffic once ICE completed, and remove them to observe
1240 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1241 // verifies the best connection is using the right IP protocol after
1242 // initial ICE convergences.
1243
1244 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001245 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001246 LoopbackNetworkConfiguration()
1247 : test_ipv6_network_(false),
1248 test_extra_ipv4_network_(false),
1249 best_connection_after_initial_ice_converged_(1, 0) {}
1250
1251 // Used to track the expected best connection count in each IP protocol.
1252 struct ExpectedBestConnection {
1253 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1254 : ipv4_count_(ipv4_count),
1255 ipv6_count_(ipv6_count) {}
1256
1257 int ipv4_count_;
1258 int ipv6_count_;
1259 };
1260
1261 bool test_ipv6_network_;
1262 bool test_extra_ipv4_network_;
1263 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1264
1265 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001266 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001267 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1268 }
1269
1270 private:
jbauchac8869e2015-07-03 01:36:14 -07001271 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001272 const ExpectedBestConnection& expected) const {
1273 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001274 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1275 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001276 expected.ipv4_count_);
1277 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001278 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1279 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001280 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001281 // This is used in the loopback call so there is only single host to host
1282 // candidate pair.
1283 EXPECT_EQ(metrics_observer->GetEnumCounter(
1284 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1285 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001286 0);
1287 EXPECT_EQ(metrics_observer->GetEnumCounter(
1288 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1289 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001290 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001291 }
1292 };
1293
1294 class LoopbackNetworkManager {
1295 public:
1296 LoopbackNetworkManager(WebRtcSessionTest* session,
1297 const LoopbackNetworkConfiguration& config)
1298 : config_(config) {
1299 session->AddInterface(
1300 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1301 if (config_.test_extra_ipv4_network_) {
1302 session->AddInterface(
1303 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1304 }
1305 if (config_.test_ipv6_network_) {
1306 session->AddInterface(
1307 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1308 }
1309 }
1310
1311 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1312 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1313 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1314 if (config_.test_extra_ipv4_network_) {
1315 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1316 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1317 }
1318 if (config_.test_ipv6_network_) {
1319 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1320 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1321 }
1322 }
1323
1324 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1325
1326 private:
1327 LoopbackNetworkConfiguration config_;
1328 };
1329
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 // The method sets up a call from the session to itself, in a loopback
1331 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001332 // disconnection, and then a permanent disconnection.
1333 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1335 // While running the call, this method also checks if the session goes through
1336 // the correct sequence of ICE states when a connection is established,
1337 // broken, and re-established.
1338 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001339 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1340 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001342
stefanc1aeaf02015-10-15 07:26:07 -07001343 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001344 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001345 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001346 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347
1348 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1349 observer_.ice_gathering_state_);
1350 SetLocalDescriptionWithoutError(offer);
1351 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1352 observer_.ice_connection_state_);
1353 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001354 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1356 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001357 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358
1359 std::string sdp;
1360 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001361 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1362 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 ASSERT_TRUE(desc != NULL);
1364 SetRemoteDescriptionWithoutError(desc);
1365
1366 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001367 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001368
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001369 // The ice connection state is "Connected" too briefly to catch in a test.
1370 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001371 observer_.ice_connection_state_, kIceCandidatesTimeout);
1372 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373
stefanc1aeaf02015-10-15 07:26:07 -07001374 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1375 LoopbackNetworkManager loopback_network_manager(this, config);
1376 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001377 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 // Adding firewall rule to block ping requests, which should cause
1379 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001380
1381 loopback_network_manager.ApplyFirewallRules(fss_.get());
1382
1383 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1385 observer_.ice_connection_state_,
1386 kIceCandidatesTimeout);
1387
jbauchac8869e2015-07-03 01:36:14 -07001388 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001391 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001393 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001394 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 observer_.ice_connection_state_,
1396 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001397
1398 // Now we block ping requests and wait until the ICE connection transitions
1399 // to the Failed state. This will take at least 30 seconds because it must
1400 // wait for the Port to timeout.
1401 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001402
1403 loopback_network_manager.ApplyFirewallRules(fss_.get());
1404 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001405 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001406 observer_.ice_connection_state_,
1407 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 }
1409
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001410 void TestLoopbackCall() {
1411 LoopbackNetworkConfiguration config;
1412 TestLoopbackCall(config);
1413 }
1414
stefanc1aeaf02015-10-15 07:26:07 -07001415 void TestPacketOptions() {
1416 media_controller_.reset(
1417 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1418 LoopbackNetworkConfiguration config;
1419 LoopbackNetworkManager loopback_network_manager(this, config);
1420
1421 SetupLoopbackCall();
1422
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001423 // Wait for channel to be ready for sending.
1424 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001425 uint8_t test_packet[15] = {0};
1426 rtc::PacketOptions options;
1427 options.packet_id = 10;
1428 media_engine_->GetVideoChannel(0)
1429 ->SendRtp(test_packet, sizeof(test_packet), options);
1430
1431 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001432 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1433 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001434 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1435 }
1436
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1438 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001439 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1440 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001441
1442 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001443 std::vector<cricket::AudioCodec> codecs =
1444 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 codecs.push_back(kCNCodec1);
1446 codecs.push_back(kCNCodec2);
1447 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001448 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 }
1450
1451 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1452 const cricket::ContentDescription* description = content->description;
1453 ASSERT(description != NULL);
1454 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001455 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 ASSERT(audio_content_desc != NULL);
1457 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1458 if (audio_content_desc->codecs()[i].name == "CN")
1459 return false;
1460 }
1461 return true;
1462 }
1463
deadbeefab9b2d12015-10-14 11:33:11 -07001464 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001465 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001466 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001467 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1468 data_channel_ = DataChannel::Create(
1469 session_.get(), session_->data_channel_type(), "datachannel", dci);
1470 }
1471
1472 void SetLocalDescriptionWithDataChannel() {
1473 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001474 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 SetLocalDescriptionWithoutError(offer);
1476 }
1477
wu@webrtc.org91053e72013-08-10 07:18:04 +00001478 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001479 RTCCertificateGenerationMethod cert_gen_method,
1480 CreateSessionDescriptionRequest::Type type) {
1481 InitWithDtls(cert_gen_method);
1482 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1483 }
1484
1485 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1486 CreateSessionDescriptionRequest::Type type) {
1487 InitWithDtlsIdentityGenFail();
1488 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1489 }
1490
1491 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001492 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001493 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001494 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001495 if (type == CreateSessionDescriptionRequest::kAnswer) {
1496 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001497 std::unique_ptr<JsepSessionDescription> offer(
1498 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001499 ASSERT_TRUE(offer.get() != NULL);
1500 SetRemoteDescriptionWithoutError(offer.release());
1501 }
1502
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001503 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001504 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001505 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001506 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001507 observers[kNumber];
1508 for (int i = 0; i < kNumber; ++i) {
1509 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1510 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001511 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001512 } else {
htaa2a49d92016-03-04 02:51:39 -08001513 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001514 }
1515 }
1516
1517 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1518 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1519 WebRtcSessionCreateSDPObserverForTest::kFailed;
1520
1521 for (int i = 0; i < kNumber; ++i) {
1522 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1523 if (success) {
1524 EXPECT_TRUE(observers[i]->description() != NULL);
1525 } else {
1526 EXPECT_TRUE(observers[i]->description() == NULL);
1527 }
1528 }
1529 }
1530
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001531 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001532 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001533 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001534 turn_server.credentials = credentials;
1535 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001536 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001537 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001538 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001539 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001540 }
1541
skvlad11a9cbf2016-10-07 11:53:05 -07001542 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 cricket::FakeMediaEngine* media_engine_;
1544 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001545 // Actually owned by session_.
1546 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001547 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001548 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001549 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1550 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1551 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1552 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1553 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1554 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001555 rtc::SocketServerScope ss_scope_;
1556 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001557 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001558 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001559 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001560 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001561 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001562 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001563 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 MockIceObserver observer_;
1565 cricket::FakeVideoMediaChannel* video_channel_;
1566 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001567 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001568 // The following flags affect options created for CreateOffer/CreateAnswer.
1569 bool send_stream_1_ = false;
1570 bool send_stream_2_ = false;
1571 bool send_audio_ = false;
1572 bool send_video_ = false;
1573 rtc::scoped_refptr<DataChannel> data_channel_;
1574 // Last values received from data channel creation signal.
1575 std::string last_data_channel_label_;
1576 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001577 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001578 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579};
1580
Henrik Boström87713d02015-08-25 09:53:21 +02001581TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1582 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001583 // SDES is disabled when DTLS is on.
1584 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585}
1586
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001587TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001588 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001589 // SDES is required if DTLS is off.
1590 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001591}
1592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1594 TestSessionCandidatesWithBundleRtcpMux(false, false);
1595}
1596
1597// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1598// with rtcp-mux and/or bundle.
1599TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1600 TestSessionCandidatesWithBundleRtcpMux(false, true);
1601}
1602
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1604 TestSessionCandidatesWithBundleRtcpMux(true, true);
1605}
1606
1607TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001608 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1609 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001610 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001611 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 InitiateCall();
1613 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1614 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1615 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1616}
1617
deadbeeff5f03e82016-06-06 11:16:06 -07001618TEST_F(WebRtcSessionTest, TestStunError) {
1619 rtc::ScopedFakeClock clock;
1620
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001621 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1622 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001623 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001624 rtc::FP_UDP,
1625 rtc::FD_ANY,
1626 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001627 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001630 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001631 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1633 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001634 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1635 // warning.
1636 session_->Close();
1637 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638}
1639
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001640TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001641 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001642 SessionDescriptionInterface* offer = NULL;
1643 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1644 std::string unknown_action;
1645 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1646 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1647}
1648
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649// Test creating offers and receive answers and make sure the
1650// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001652 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001653 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001654 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 const std::string session_id_orig = offer->session_id();
1656 const std::string session_version_orig = offer->session_version();
1657 SetLocalDescriptionWithoutError(offer);
1658
deadbeefab9b2d12015-10-14 11:33:11 -07001659 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 SessionDescriptionInterface* answer =
1661 CreateRemoteAnswer(session_->local_description());
1662 SetRemoteDescriptionWithoutError(answer);
1663
1664 video_channel_ = media_engine_->GetVideoChannel(0);
1665 voice_channel_ = media_engine_->GetVoiceChannel(0);
1666
1667 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1668 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1669
1670 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1671 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1672
1673 ASSERT_EQ(1u, video_channel_->send_streams().size());
1674 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1675 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1676 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1677
1678 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001679 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001680 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681
1682 // Verify the session id is the same and the session version is
1683 // increased.
1684 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001685 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1686 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001689 EXPECT_EQ(0u, video_channel_->send_streams().size());
1690 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691
deadbeefab9b2d12015-10-14 11:33:11 -07001692 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 answer = CreateRemoteAnswer(session_->local_description());
1694 SetRemoteDescriptionWithoutError(answer);
1695
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 // Make sure the receive streams have not changed.
1697 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1698 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1699 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1700 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1701}
1702
1703// Test receiving offers and creating answers and make sure the
1704// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001705TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001706 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001707 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001708 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 SetRemoteDescriptionWithoutError(offer);
1711
deadbeefab9b2d12015-10-14 11:33:11 -07001712 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001713 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001714 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 SetLocalDescriptionWithoutError(answer);
1716
1717 const std::string session_id_orig = answer->session_id();
1718 const std::string session_version_orig = answer->session_version();
1719
1720 video_channel_ = media_engine_->GetVideoChannel(0);
1721 voice_channel_ = media_engine_->GetVoiceChannel(0);
1722
htaa2a49d92016-03-04 02:51:39 -08001723 ASSERT_TRUE(video_channel_);
1724 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1726 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1727
1728 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1729 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1730
1731 ASSERT_EQ(1u, video_channel_->send_streams().size());
1732 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1733 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1734 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1735
deadbeefab9b2d12015-10-14 11:33:11 -07001736 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001737 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 SetRemoteDescriptionWithoutError(offer);
1739
1740 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001741 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001742 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
1744 // Verify the session id is the same and the session version is
1745 // increased.
1746 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001747 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1748 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 SetLocalDescriptionWithoutError(answer);
1750
1751 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1752 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1753 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1754 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1755 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1756 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1757
1758 // Make sure we have no send streams.
1759 EXPECT_EQ(0u, video_channel_->send_streams().size());
1760 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1761}
1762
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001763TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001764 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001765 media_engine_->set_fail_create_channel(true);
1766
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001767 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001768 ASSERT_TRUE(offer != NULL);
1769 // SetRemoteDescription and SetLocalDescription will take the ownership of
1770 // the offer.
1771 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001772 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001773 ASSERT_TRUE(offer != NULL);
1774 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1775}
1776
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777//
1778// Tests for creating/setting SDP under different SDES/DTLS polices:
1779//
1780// --DTLS off and SDES on
1781// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1782// set local/remote offer/answer with crypto --> success
1783// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1784// failure
1785// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1786// failure
1787// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1788// failure
1789//
1790// --DTLS on and SDES off
1791// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1792// set local/remote offer/answer with DTLS fingerprint --> success
1793// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1794// fingerprint --> failure
1795// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1796// --> failure
1797// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1798// --> failure
1799//
1800// --Encryption disabled: DTLS off and SDES off
1801// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1802// answer without SDES or DTLS --> success
1803// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1804// answer without SDES or DTLS --> success
1805//
1806
1807// Test that we return a failure when applying a remote/local offer that doesn't
1808// have cryptos enabled when DTLS is off.
1809TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001810 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001812 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 JsepSessionDescription* offer = CreateRemoteOffer(
1814 options, cricket::SEC_DISABLED);
1815 ASSERT_TRUE(offer != NULL);
1816 VerifyNoCryptoParams(offer->description(), false);
1817 // SetRemoteDescription and SetLocalDescription will take the ownership of
1818 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001819 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1821 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001822 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823}
1824
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001825// Test that we return a failure when applying a local answer that doesn't have
1826// cryptos enabled when DTLS is off.
1827TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001828 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 SessionDescriptionInterface* offer = NULL;
1830 SessionDescriptionInterface* answer = NULL;
1831 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1832 // SetRemoteDescription and SetLocalDescription will take the ownership of
1833 // the offer.
1834 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001835 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836}
1837
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001838// Test we will return fail when apply an remote answer that doesn't have
1839// crypto enabled when DTLS is off.
1840TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001841 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 SessionDescriptionInterface* offer = NULL;
1843 SessionDescriptionInterface* answer = NULL;
1844 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1845 // SetRemoteDescription and SetLocalDescription will take the ownership of
1846 // the offer.
1847 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849}
1850
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001851// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1852// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001853TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001854 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001855 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001856 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 SetFactoryDtlsSrtp();
1858 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001859 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 JsepSessionDescription* offer =
1861 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 ASSERT_TRUE(offer != NULL);
1863 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865
1866 // SetRemoteDescription will take the ownership of the offer.
1867 SetRemoteDescriptionWithoutError(offer);
1868
1869 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001870 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 ASSERT_TRUE(answer != NULL);
1872 VerifyFingerprintStatus(answer->description(), true);
1873 // Check that we don't have an a=crypto line in the answer.
1874 VerifyNoCryptoParams(answer->description(), true);
1875
1876 // Now set the local description, which should work, even without a=crypto.
1877 SetLocalDescriptionWithoutError(answer);
1878}
1879
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1881// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001882TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001883 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001884 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001885 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001886 SetFactoryDtlsSrtp();
1887
1888 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001889 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 ASSERT_TRUE(offer != NULL);
1891 VerifyFingerprintStatus(offer->description(), true);
1892 // Check that we don't have an a=crypto line in the offer.
1893 VerifyNoCryptoParams(offer->description(), true);
1894
1895 // Now set the local description, which should work, even without a=crypto.
1896 SetLocalDescriptionWithoutError(offer);
1897
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* answer =
1901 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1902 ASSERT_TRUE(answer != NULL);
1903 VerifyFingerprintStatus(answer->description(), true);
1904 VerifyNoCryptoParams(answer->description(), true);
1905
1906 // SetRemoteDescription will take the ownership of the answer.
1907 SetRemoteDescriptionWithoutError(answer);
1908}
1909
1910// Test that if we support DTLS and the other side didn't offer a fingerprint,
1911// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001912TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001913 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001914 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001916 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 JsepSessionDescription* offer = CreateRemoteOffer(
1919 options, cricket::SEC_REQUIRED);
1920 ASSERT_TRUE(offer != NULL);
1921 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924 // SetRemoteDescription will take the ownership of the offer.
1925 SetRemoteDescriptionOfferExpectError(
1926 kSdpWithoutDtlsFingerprint, offer);
1927
1928 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1929 // SetLocalDescription will take the ownership of the offer.
1930 SetLocalDescriptionOfferExpectError(
1931 kSdpWithoutDtlsFingerprint, offer);
1932}
1933
1934// Test that we return a failure when applying a local answer that doesn't have
1935// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001936TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001937 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001938 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 SessionDescriptionInterface* offer = NULL;
1940 SessionDescriptionInterface* answer = NULL;
1941 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1942
1943 // SetRemoteDescription and SetLocalDescription will take the ownership of
1944 // the offer and answer.
1945 SetRemoteDescriptionWithoutError(offer);
1946 SetLocalDescriptionAnswerExpectError(
1947 kSdpWithoutDtlsFingerprint, answer);
1948}
1949
1950// Test that we return a failure when applying a remote answer that doesn't have
1951// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001952TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001953 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001954 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001955 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001956 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001957 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001958 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001959 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001960 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001961 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001962
1963 // SetRemoteDescription and SetLocalDescription will take the ownership of
1964 // the offer and answer.
1965 SetLocalDescriptionWithoutError(offer);
1966 SetRemoteDescriptionAnswerExpectError(
1967 kSdpWithoutDtlsFingerprint, answer);
1968}
1969
1970// Test that we create a local offer without SDES or DTLS and accept a remote
1971// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001972TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001973 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001974 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001975 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001976
1977 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001978 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001979 ASSERT_TRUE(offer != NULL);
1980 VerifyFingerprintStatus(offer->description(), false);
1981 // Check that we don't have an a=crypto line in the offer.
1982 VerifyNoCryptoParams(offer->description(), false);
1983
1984 // Now set the local description, which should work, even without a=crypto.
1985 SetLocalDescriptionWithoutError(offer);
1986
1987 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001988 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001989 JsepSessionDescription* answer =
1990 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1991 ASSERT_TRUE(answer != NULL);
1992 VerifyFingerprintStatus(answer->description(), false);
1993 VerifyNoCryptoParams(answer->description(), false);
1994
1995 // SetRemoteDescription will take the ownership of the answer.
1996 SetRemoteDescriptionWithoutError(answer);
1997}
1998
1999// Test that we create a local answer without SDES or DTLS and accept a remote
2000// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002001TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002002 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002003 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002004
2005 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002006 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002007 JsepSessionDescription* offer =
2008 CreateRemoteOffer(options, cricket::SEC_DISABLED);
2009 ASSERT_TRUE(offer != NULL);
2010 VerifyFingerprintStatus(offer->description(), false);
2011 VerifyNoCryptoParams(offer->description(), false);
2012
2013 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 SetRemoteDescriptionWithoutError(offer);
2015
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002016 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08002017 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 ASSERT_TRUE(answer != NULL);
2019 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002020 // Check that we don't have an a=crypto line in the answer.
2021 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002023 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 SetLocalDescriptionWithoutError(answer);
2025}
2026
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002027// Test that we can create and set an answer correctly when different
2028// SSL roles have been negotiated for different transports.
2029// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
2030TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
2031 SendAudioVideoStream1();
2032 InitWithDtls(GetParam());
2033 SetFactoryDtlsSrtp();
2034
2035 SessionDescriptionInterface* offer = CreateOffer();
2036 SetLocalDescriptionWithoutError(offer);
2037
2038 cricket::MediaSessionOptions options;
2039 options.recv_video = true;
2040
2041 // First, negotiate different SSL roles.
2042 SessionDescriptionInterface* answer =
2043 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2044 TransportInfo* audio_transport_info =
2045 answer->description()->GetTransportInfoByName("audio");
2046 audio_transport_info->description.connection_role =
2047 cricket::CONNECTIONROLE_ACTIVE;
2048 TransportInfo* video_transport_info =
2049 answer->description()->GetTransportInfoByName("video");
2050 video_transport_info->description.connection_role =
2051 cricket::CONNECTIONROLE_PASSIVE;
2052 SetRemoteDescriptionWithoutError(answer);
2053
2054 // Now create an offer in the reverse direction, and ensure the initial
2055 // offerer responds with an answer with correct SSL roles.
2056 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2057 kSessionVersion,
2058 session_->remote_description());
2059 SetRemoteDescriptionWithoutError(offer);
2060
htaa2a49d92016-03-04 02:51:39 -08002061 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002062 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2063 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2064 audio_transport_info->description.connection_role);
2065 video_transport_info = answer->description()->GetTransportInfoByName("video");
2066 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2067 video_transport_info->description.connection_role);
2068 SetLocalDescriptionWithoutError(answer);
2069
2070 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2071 // audio is transferred over to video in the answer that completes the BUNDLE
2072 // negotiation.
2073 options.bundle_enabled = true;
2074 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2075 kSessionVersion,
2076 session_->remote_description());
2077 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002078 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002079 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2080 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2081 audio_transport_info->description.connection_role);
2082 video_transport_info = answer->description()->GetTransportInfoByName("video");
2083 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2084 video_transport_info->description.connection_role);
2085 SetLocalDescriptionWithoutError(answer);
2086}
2087
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002089 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002090 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002092 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 SetLocalDescriptionWithoutError(offer);
2094
2095 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002096 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 SetLocalDescriptionWithoutError(offer2);
2098}
2099
2100TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002101 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002102 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 SetRemoteDescriptionWithoutError(offer);
2106
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002107 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 SetRemoteDescriptionWithoutError(offer2);
2109}
2110
2111TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002112 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002113 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002114 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002117 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2118 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119}
2120
2121TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002122 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002123 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002124 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002126 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002127 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002128 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129}
2130
2131TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002132 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002133 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002135 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136
htaa2a49d92016-03-04 02:51:39 -08002137 JsepSessionDescription* pranswer =
2138 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002140 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141
deadbeefab9b2d12015-10-14 11:33:11 -07002142 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002143 JsepSessionDescription* pranswer2 =
2144 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2146
deadbeefd59daf82015-10-14 15:02:44 -07002147 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
deadbeefab9b2d12015-10-14 11:33:11 -07002149 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002150 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002151 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152}
2153
2154TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002156 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002157 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002158 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159
2160 JsepSessionDescription* pranswer =
2161 CreateRemoteAnswer(session_->local_description());
2162 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2163
2164 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002165 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
deadbeefab9b2d12015-10-14 11:33:11 -07002167 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 JsepSessionDescription* pranswer2 =
2169 CreateRemoteAnswer(session_->local_description());
2170 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2171
2172 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002173 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174
deadbeefab9b2d12015-10-14 11:33:11 -07002175 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 SessionDescriptionInterface* answer =
2177 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002178 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179}
2180
2181TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002182 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002183 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002184 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 SessionDescriptionInterface* answer =
2187 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002188 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2189 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190}
2191
2192TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002193 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002194 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002195 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002196
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197 SessionDescriptionInterface* answer =
2198 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002199 SetRemoteDescriptionAnswerExpectError(
2200 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201}
2202
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002203// Tests that the remote candidates are added and removed successfully.
2204TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002205 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002206 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002208 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2209 "", "", "host", 0, "");
2210 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2212
deadbeefd59daf82015-10-14 15:02:44 -07002213 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2215
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002216 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002218
2219 // Fail since we have not set a remote description.
2220 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221
2222 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2223 session_->local_description());
2224 SetRemoteDescriptionWithoutError(answer);
2225
deadbeefd59daf82015-10-14 15:02:44 -07002226 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2227 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002228 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002229 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2230 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2231
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 // Verifying the candidates are copied properly from internal vector.
2233 const SessionDescriptionInterface* remote_desc =
2234 session_->remote_description();
2235 ASSERT_TRUE(remote_desc != NULL);
2236 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2237 const IceCandidateCollection* candidates =
2238 remote_desc->candidates(kMediaContentIndex0);
2239 ASSERT_EQ(2u, candidates->count());
2240 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2241 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2242 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2243 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2244
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002245 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2246 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 candidate.set_component(2);
2248 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2249 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002250 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251
2252 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2253 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002254
2255 // Remove candidate1 and candidate2
2256 std::vector<cricket::Candidate> remote_candidates;
2257 remote_candidates.push_back(ice_candidate1.candidate());
2258 remote_candidates.push_back(ice_candidate2.candidate());
2259 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2260 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261}
2262
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002263// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264// that it is retained if the remote session description is changed.
2265TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002266 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 cricket::Candidate candidate1;
2268 candidate1.set_component(1);
2269 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2270 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002271 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 CreateAndSetRemoteOfferAndLocalAnswer();
2273
2274 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2275 const SessionDescriptionInterface* remote_desc =
2276 session_->remote_description();
2277 ASSERT_TRUE(remote_desc != NULL);
2278 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2279 const IceCandidateCollection* candidates =
2280 remote_desc->candidates(kMediaContentIndex0);
2281 ASSERT_EQ(1u, candidates->count());
2282 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2283
2284 // Update the RemoteSessionDescription with a new session description and
2285 // a candidate and check that the new remote session description contains both
2286 // candidates.
2287 SessionDescriptionInterface* offer = CreateRemoteOffer();
2288 cricket::Candidate candidate2;
2289 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2290 candidate2);
2291 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2292 SetRemoteDescriptionWithoutError(offer);
2293
2294 remote_desc = session_->remote_description();
2295 ASSERT_TRUE(remote_desc != NULL);
2296 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2297 candidates = remote_desc->candidates(kMediaContentIndex0);
2298 ASSERT_EQ(2u, candidates->count());
2299 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2300 // Username and password have be updated with the TransportInfo of the
2301 // SessionDescription, won't be equal to the original one.
2302 candidate2.set_username(candidates->at(0)->candidate().username());
2303 candidate2.set_password(candidates->at(0)->candidate().password());
2304 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2305 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2306 // No need to verify the username and password.
2307 candidate1.set_username(candidates->at(1)->candidate().username());
2308 candidate1.set_password(candidates->at(1)->candidate().password());
2309 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2310
2311 // Test that the candidate is ignored if we can add the same candidate again.
2312 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2313}
2314
2315// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002316// that they are retained if the local session description is changed. And if
2317// continual gathering is enabled, they are removed from the local session
2318// description when the network is down.
2319TEST_F(WebRtcSessionTest,
2320 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002321 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002322 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002323 // Enable Continual Gathering.
2324 cricket::IceConfig config;
2325 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2326 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002327 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 CreateAndSetRemoteOfferAndLocalAnswer();
2329
2330 const SessionDescriptionInterface* local_desc = session_->local_description();
2331 const IceCandidateCollection* candidates =
2332 local_desc->candidates(kMediaContentIndex0);
2333 ASSERT_TRUE(candidates != NULL);
2334 EXPECT_EQ(0u, candidates->count());
2335
deadbeefb60a8192016-08-24 15:15:00 -07002336 // Since we're using continual gathering, we won't get "gathering done".
2337 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338
2339 local_desc = session_->local_description();
2340 candidates = local_desc->candidates(kMediaContentIndex0);
2341 ASSERT_TRUE(candidates != NULL);
2342 EXPECT_LT(0u, candidates->count());
2343 candidates = local_desc->candidates(1);
2344 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002345 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346
2347 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002348 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 CreateAndSetRemoteOfferAndLocalAnswer();
2350
2351 local_desc = session_->local_description();
2352 candidates = local_desc->candidates(kMediaContentIndex0);
2353 ASSERT_TRUE(candidates != NULL);
2354 EXPECT_LT(0u, candidates->count());
2355 candidates = local_desc->candidates(1);
2356 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002357 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002358
2359 candidates = local_desc->candidates(kMediaContentIndex0);
2360 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002361 // Bring down the network interface to trigger candidate removals.
2362 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2363 // Verify that all local candidates are removed.
2364 EXPECT_EQ(0, observer_.num_candidates_removed_);
2365 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2366 kIceCandidatesTimeout);
2367 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2368}
2369
2370// Tests that if continual gathering is disabled, local candidates won't be
2371// removed when the interface is turned down.
2372TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2373 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2374 Init();
2375 SendAudioVideoStream1();
2376 CreateAndSetRemoteOfferAndLocalAnswer();
2377
2378 const SessionDescriptionInterface* local_desc = session_->local_description();
2379 const IceCandidateCollection* candidates =
2380 local_desc->candidates(kMediaContentIndex0);
2381 ASSERT_TRUE(candidates != NULL);
2382 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2383
2384 size_t num_local_candidates = candidates->count();
2385 EXPECT_LT(0u, num_local_candidates);
2386 // By default, Continual Gathering is disabled.
2387 // Bring down the network interface.
2388 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2389 // Verify that the local candidates are not removed.
2390 rtc::Thread::Current()->ProcessMessages(1000);
2391 EXPECT_EQ(0, observer_.num_candidates_removed_);
2392 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393}
2394
2395// Test that we can set a remote session description with remote candidates.
2396TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002397 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
2399 cricket::Candidate candidate1;
2400 candidate1.set_component(1);
2401 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2402 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002403 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002404 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405
2406 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2407 SetRemoteDescriptionWithoutError(offer);
2408
2409 const SessionDescriptionInterface* remote_desc =
2410 session_->remote_description();
2411 ASSERT_TRUE(remote_desc != NULL);
2412 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2413 const IceCandidateCollection* candidates =
2414 remote_desc->candidates(kMediaContentIndex0);
2415 ASSERT_EQ(1u, candidates->count());
2416 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2417
htaa2a49d92016-03-04 02:51:39 -08002418 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 SetLocalDescriptionWithoutError(answer);
2420}
2421
2422// Test that offers and answers contains ice candidates when Ice candidates have
2423// been gathered.
2424TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002425 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002426 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002427 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 // Ice is started but candidates are not provided until SetLocalDescription
2429 // is called.
2430 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2431 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2432 CreateAndSetRemoteOfferAndLocalAnswer();
2433 // Wait until at least one local candidate has been collected.
2434 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2435 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436
kwibergd1fe2812016-04-27 06:47:29 -07002437 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002438
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2440 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441
2442 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2443 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002444 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2446 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 SetLocalDescriptionWithoutError(answer);
2448}
2449
2450// Verifies TransportProxy and media channels are created with content names
2451// present in the SessionDescription.
2452TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002453 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002454 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002455 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456
2457 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002458 // "video". Goal is to modify these content names and verify transport
2459 // channels
2460 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 // present in SDP.
2462 std::string sdp;
2463 EXPECT_TRUE(offer->ToString(&sdp));
2464 const std::string kAudioMid = "a=mid:audio";
2465 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2466 const std::string kVideoMid = "a=mid:video";
2467 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2468
2469 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002470 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 kAudioMidReplaceStr.c_str(),
2472 kAudioMidReplaceStr.length(),
2473 &sdp);
2474 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002475 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 kVideoMidReplaceStr.c_str(),
2477 kVideoMidReplaceStr.length(),
2478 &sdp);
2479
2480 SessionDescriptionInterface* modified_offer =
2481 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2482
2483 SetRemoteDescriptionWithoutError(modified_offer);
2484
htaa2a49d92016-03-04 02:51:39 -08002485 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 SetLocalDescriptionWithoutError(answer);
2487
johan669d69b2016-11-08 14:14:08 -08002488 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002489 session_->voice_rtp_transport_channel();
2490 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002491 EXPECT_EQ(voice_transport_channel->debug_name(),
2492 "audio_content_name " +
2493 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2494 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002495 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002496 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002497 EXPECT_EQ(video_transport_channel->debug_name(),
2498 "video_content_name " +
2499 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2501 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2502}
2503
2504// Test that an offer contains the correct media content descriptions based on
2505// the send streams when no constraints have been set.
2506TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002507 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 ASSERT_TRUE(offer != NULL);
2511 const cricket::ContentInfo* content =
2512 cricket::GetFirstAudioContent(offer->description());
2513 EXPECT_TRUE(content != NULL);
2514 content = cricket::GetFirstVideoContent(offer->description());
2515 EXPECT_TRUE(content == NULL);
2516}
2517
2518// Test that an offer contains the correct media content descriptions based on
2519// the send streams when no constraints have been set.
2520TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002523 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002524 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526 const cricket::ContentInfo* content =
2527 cricket::GetFirstAudioContent(offer->description());
2528 EXPECT_TRUE(content != NULL);
2529 content = cricket::GetFirstVideoContent(offer->description());
2530 EXPECT_TRUE(content == NULL);
2531
2532 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002533 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002534 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 content = cricket::GetFirstAudioContent(offer->description());
2536 EXPECT_TRUE(content != NULL);
2537 content = cricket::GetFirstVideoContent(offer->description());
2538 EXPECT_TRUE(content != NULL);
2539}
2540
2541// Test that an offer contains no media content descriptions if
2542// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2543TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002544 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002545 PeerConnectionInterface::RTCOfferAnswerOptions options;
2546 options.offer_to_receive_audio = 0;
2547 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002550
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 ASSERT_TRUE(offer != NULL);
2552 const cricket::ContentInfo* content =
2553 cricket::GetFirstAudioContent(offer->description());
2554 EXPECT_TRUE(content == NULL);
2555 content = cricket::GetFirstVideoContent(offer->description());
2556 EXPECT_TRUE(content == NULL);
2557}
2558
2559// Test that an offer contains only audio media content descriptions if
2560// kOfferToReceiveAudio constraints are set to true.
2561TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002562 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002563 PeerConnectionInterface::RTCOfferAnswerOptions options;
2564 options.offer_to_receive_audio =
2565 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2566
kwibergd1fe2812016-04-27 06:47:29 -07002567 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568
2569 const cricket::ContentInfo* content =
2570 cricket::GetFirstAudioContent(offer->description());
2571 EXPECT_TRUE(content != NULL);
2572 content = cricket::GetFirstVideoContent(offer->description());
2573 EXPECT_TRUE(content == NULL);
2574}
2575
2576// Test that an offer contains audio and video media content descriptions if
2577// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2578TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002579 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002581 PeerConnectionInterface::RTCOfferAnswerOptions options;
2582 options.offer_to_receive_audio =
2583 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2584 options.offer_to_receive_video =
2585 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2586
kwibergd1fe2812016-04-27 06:47:29 -07002587 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 const cricket::ContentInfo* content =
2590 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002591 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 content = cricket::GetFirstVideoContent(offer->description());
2594 EXPECT_TRUE(content != NULL);
2595
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002596 // Sets constraints to false and verifies that audio/video contents are
2597 // removed.
2598 options.offer_to_receive_audio = 0;
2599 options.offer_to_receive_video = 0;
2600 offer.reset(CreateOffer(options));
2601
2602 content = cricket::GetFirstAudioContent(offer->description());
2603 EXPECT_TRUE(content == NULL);
2604 content = cricket::GetFirstVideoContent(offer->description());
2605 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606}
2607
2608// Test that an answer can not be created if the last remote description is not
2609// an offer.
2610TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002611 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002612 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 SetLocalDescriptionWithoutError(offer);
2614 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2615 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002616 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617}
2618
2619// Test that an answer contains the correct media content descriptions when no
2620// constraints have been set.
2621TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002622 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002624 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002626 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 const cricket::ContentInfo* content =
2628 cricket::GetFirstAudioContent(answer->description());
2629 ASSERT_TRUE(content != NULL);
2630 EXPECT_FALSE(content->rejected);
2631
2632 content = cricket::GetFirstVideoContent(answer->description());
2633 ASSERT_TRUE(content != NULL);
2634 EXPECT_FALSE(content->rejected);
2635}
2636
2637// Test that an answer contains the correct media content descriptions when no
2638// constraints have been set and the offer only contain audio.
2639TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002640 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641 // Create a remote offer with audio only.
2642 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002643
kwibergd1fe2812016-04-27 06:47:29 -07002644 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2646 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2647
2648 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002649 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650 const cricket::ContentInfo* content =
2651 cricket::GetFirstAudioContent(answer->description());
2652 ASSERT_TRUE(content != NULL);
2653 EXPECT_FALSE(content->rejected);
2654
2655 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2656}
2657
2658// Test that an answer contains the correct media content descriptions when no
2659// constraints have been set.
2660TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002661 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002663 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 SetRemoteDescriptionWithoutError(offer.release());
2665 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002666 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002667 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 const cricket::ContentInfo* content =
2669 cricket::GetFirstAudioContent(answer->description());
2670 ASSERT_TRUE(content != NULL);
2671 EXPECT_FALSE(content->rejected);
2672
2673 content = cricket::GetFirstVideoContent(answer->description());
2674 ASSERT_TRUE(content != NULL);
2675 EXPECT_FALSE(content->rejected);
2676}
2677
2678// Test that an answer contains the correct media content descriptions when
2679// constraints have been set but no stream is sent.
2680TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002681 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002683 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 SetRemoteDescriptionWithoutError(offer.release());
2685
htaa2a49d92016-03-04 02:51:39 -08002686 cricket::MediaSessionOptions session_options;
2687 session_options.recv_audio = false;
2688 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002689 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002690 CreateAnswer(session_options));
2691
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 const cricket::ContentInfo* content =
2693 cricket::GetFirstAudioContent(answer->description());
2694 ASSERT_TRUE(content != NULL);
2695 EXPECT_TRUE(content->rejected);
2696
2697 content = cricket::GetFirstVideoContent(answer->description());
2698 ASSERT_TRUE(content != NULL);
2699 EXPECT_TRUE(content->rejected);
2700}
2701
2702// Test that an answer contains the correct media content descriptions when
2703// constraints have been set and streams are sent.
2704TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002705 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002707 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 SetRemoteDescriptionWithoutError(offer.release());
2709
htaa2a49d92016-03-04 02:51:39 -08002710 cricket::MediaSessionOptions options;
2711 options.recv_audio = false;
2712 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713
2714 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002715 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002716 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717
2718 // TODO(perkj): Should the direction be set to SEND_ONLY?
2719 const cricket::ContentInfo* content =
2720 cricket::GetFirstAudioContent(answer->description());
2721 ASSERT_TRUE(content != NULL);
2722 EXPECT_FALSE(content->rejected);
2723
2724 // TODO(perkj): Should the direction be set to SEND_ONLY?
2725 content = cricket::GetFirstVideoContent(answer->description());
2726 ASSERT_TRUE(content != NULL);
2727 EXPECT_FALSE(content->rejected);
2728}
2729
2730TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2731 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002732 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002733 PeerConnectionInterface::RTCOfferAnswerOptions options;
2734 options.offer_to_receive_audio =
2735 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2736 options.voice_activity_detection = false;
2737
kwibergd1fe2812016-04-27 06:47:29 -07002738 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002739
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 const cricket::ContentInfo* content =
2741 cricket::GetFirstAudioContent(offer->description());
2742 EXPECT_TRUE(content != NULL);
2743 EXPECT_TRUE(VerifyNoCNCodecs(content));
2744}
2745
2746TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2747 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002748 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002750 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 SetRemoteDescriptionWithoutError(offer.release());
2752
htaa2a49d92016-03-04 02:51:39 -08002753 cricket::MediaSessionOptions options;
2754 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002755 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 const cricket::ContentInfo* content =
2757 cricket::GetFirstAudioContent(answer->description());
2758 ASSERT_TRUE(content != NULL);
2759 EXPECT_TRUE(VerifyNoCNCodecs(content));
2760}
2761
2762// This test verifies the call setup when remote answer with audio only and
2763// later updates with video.
2764TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002765 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2767 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2768
deadbeefab9b2d12015-10-14 11:33:11 -07002769 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002770 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771
2772 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2774
2775 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2776 // and answer;
2777 SetLocalDescriptionWithoutError(offer);
2778 SetRemoteDescriptionWithoutError(answer);
2779
2780 video_channel_ = media_engine_->GetVideoChannel(0);
2781 voice_channel_ = media_engine_->GetVoiceChannel(0);
2782
2783 ASSERT_TRUE(video_channel_ == NULL);
2784
2785 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2786 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2787 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2788
2789 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002790 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791 CreateAndSetRemoteOfferAndLocalAnswer();
2792
2793 video_channel_ = media_engine_->GetVideoChannel(0);
2794 voice_channel_ = media_engine_->GetVoiceChannel(0);
2795
2796 ASSERT_TRUE(video_channel_ != NULL);
2797 ASSERT_TRUE(voice_channel_ != NULL);
2798
2799 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2800 ASSERT_EQ(1u, video_channel_->send_streams().size());
2801 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2802 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2803 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2804 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2805 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2806 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2807
2808 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002809 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 CreateAndSetRemoteOfferAndLocalAnswer();
2811
2812 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2813 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2814 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2815 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2816 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2817}
2818
2819// This test verifies the call setup when remote answer with video only and
2820// later updates with audio.
2821TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002822 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2824 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002825 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002826 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827
2828 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002829 options.recv_audio = false;
2830 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2832 offer, options, cricket::SEC_ENABLED);
2833
2834 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2835 // and answer.
2836 SetLocalDescriptionWithoutError(offer);
2837 SetRemoteDescriptionWithoutError(answer);
2838
2839 video_channel_ = media_engine_->GetVideoChannel(0);
2840 voice_channel_ = media_engine_->GetVoiceChannel(0);
2841
2842 ASSERT_TRUE(voice_channel_ == NULL);
2843 ASSERT_TRUE(video_channel_ != NULL);
2844
2845 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2846 ASSERT_EQ(1u, video_channel_->send_streams().size());
2847 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2848
2849 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002850 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 CreateAndSetRemoteOfferAndLocalAnswer();
2852
2853 voice_channel_ = media_engine_->GetVoiceChannel(0);
2854 ASSERT_TRUE(voice_channel_ != NULL);
2855
2856 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2857 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2858 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2859 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2860
2861 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002862 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 CreateAndSetRemoteOfferAndLocalAnswer();
2864
2865 video_channel_ = media_engine_->GetVideoChannel(0);
2866 voice_channel_ = media_engine_->GetVoiceChannel(0);
2867
2868 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2869 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2870 ASSERT_EQ(1u, video_channel_->send_streams().size());
2871 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2872}
2873
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002875 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002876 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002878 VerifyCryptoParams(offer->description());
2879 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002880 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881 VerifyCryptoParams(answer->description());
2882}
2883
jbauchcb560652016-08-04 05:20:32 -07002884TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2885 InitWithGcm();
2886 SendAudioVideoStream1();
2887 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2888 VerifyCryptoParams(offer->description(), true);
2889 SetRemoteDescriptionWithoutError(offer.release());
2890 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2891 VerifyCryptoParams(answer->description(), true);
2892}
2893
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002895 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002896 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002897 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002898 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 VerifyNoCryptoParams(offer->description(), false);
2900}
2901
2902TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002903 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002904 VerifyAnswerFromNonCryptoOffer();
2905}
2906
2907TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002908 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 VerifyAnswerFromCryptoOffer();
2910}
2911
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002912// This test verifies that setLocalDescription fails if
2913// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2914TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002915 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002916 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002917 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002918
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002919 std::string sdp;
2920 RemoveIceUfragPwdLines(offer.get(), &sdp);
2921 SessionDescriptionInterface* modified_offer =
2922 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002923 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002924}
2925
2926// This test verifies that setRemoteDescription fails if
2927// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2928TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002929 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002930 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002931 std::string sdp;
2932 RemoveIceUfragPwdLines(offer.get(), &sdp);
2933 SessionDescriptionInterface* modified_offer =
2934 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002935 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002936}
2937
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002938// This test verifies that setLocalDescription fails if local offer has
2939// too short ice ufrag and pwd strings.
2940TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002941 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002942 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002943 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002944 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2945 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002946 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002947 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002948 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002949
2950 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002951 offer.reset(CreateOffer());
2952 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2953 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002954}
2955
2956// This test verifies that setRemoteDescription fails if remote offer has
2957// too short ice ufrag and pwd strings.
2958TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002959 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002960 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002961 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2962 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002963 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002964 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002965 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002966
deadbeef0ed85b22016-02-23 17:24:52 -08002967 offer.reset(CreateRemoteOffer());
2968 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2969 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002970}
2971
Honghai Zhang04e91462015-12-11 14:26:22 -08002972// Test that if the remote offer indicates the peer requested ICE restart (via
2973// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2974TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002975 Init();
honghaiz503726c2015-07-31 12:37:38 -07002976
2977 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002978 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002979 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002980 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2981 0, "", "", "relay", 0, "");
2982 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2983 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002984 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2985 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002986 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2987
2988 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002989 offer.reset(CreateRemoteOffer());
2990 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002991 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2992 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2993 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002994 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2995 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002996 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2997
2998 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002999 offer.reset(CreateRemoteOffer());
3000 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003001 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3002 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3003 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003004 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
3005 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003006 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3007
3008 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003009 offer.reset(CreateRemoteOffer());
3010 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3011 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003012 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3013}
3014
Honghai Zhang04e91462015-12-11 14:26:22 -08003015// Test that if the remote answer indicates the peer requested ICE restart (via
3016// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3017TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
3018 Init();
3019 SessionDescriptionInterface* offer = CreateOffer();
3020 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08003021
3022 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07003023 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08003024 answer->set_type(JsepSessionDescription::kPrAnswer);
3025 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003026 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3027 0, "", "", "relay", 0, "");
3028 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3029 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003030 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
3031 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003032 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3033
3034 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003035 answer.reset(CreateRemoteAnswer(offer));
3036 answer->set_type(JsepSessionDescription::kPrAnswer);
3037 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003038 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3039 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3040 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003041 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3042 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003043 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3044
3045 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003046 answer.reset(CreateRemoteAnswer(offer));
3047 answer->set_type(JsepSessionDescription::kPrAnswer);
3048 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003049 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3050 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3051 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003052 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3053 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003054 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3055
3056 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003057 answer.reset(CreateRemoteAnswer(offer));
3058 answer->set_type(JsepSessionDescription::kPrAnswer);
3059 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3060 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003061 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3062}
3063
Donald Curtisd4f769d2015-05-28 09:48:21 -07003064// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003065// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003066TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3067 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3068
3069 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003070 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003071
3072 PeerConnectionInterface::RTCOfferAnswerOptions options;
3073 options.use_rtp_mux = true;
3074
3075 SessionDescriptionInterface* offer = CreateRemoteOffer();
3076 SetRemoteDescriptionWithoutError(offer);
3077
htaa2a49d92016-03-04 02:51:39 -08003078 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003079 SetLocalDescriptionWithoutError(answer);
3080
deadbeefcbecd352015-09-23 11:50:27 -07003081 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3082 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003083
deadbeefcbecd352015-09-23 11:50:27 -07003084 cricket::BaseChannel* voice_channel = session_->voice_channel();
3085 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003086
3087 // Checks if one of the transport channels contains a connection using a given
3088 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003089 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003090 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3091 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003092 for (auto& chan_stat : kv.second.channel_stats) {
3093 for (auto& conn_info : chan_stat.connection_infos) {
3094 if (conn_info.remote_candidate.address().port() == port) {
3095 return true;
3096 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003097 }
3098 }
3099 }
3100 return false;
3101 };
3102
3103 EXPECT_FALSE(connection_with_remote_port(5000));
3104 EXPECT_FALSE(connection_with_remote_port(5001));
3105 EXPECT_FALSE(connection_with_remote_port(6000));
3106
3107 // The way the *_WAIT checks work is they only wait if the condition fails,
3108 // which does not help in the case where state is not changing. This is
3109 // problematic in this test since we want to verify that adding a video
3110 // candidate does _not_ change state. So we interleave candidates and assume
3111 // that messages are executed in the order they were posted.
3112
3113 // First audio candidate.
3114 cricket::Candidate candidate0;
3115 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3116 candidate0.set_component(1);
3117 candidate0.set_protocol("udp");
3118 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3119 candidate0);
3120 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3121
3122 // Video candidate.
3123 cricket::Candidate candidate1;
3124 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3125 candidate1.set_component(1);
3126 candidate1.set_protocol("udp");
3127 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3128 candidate1);
3129 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3130
3131 // Second audio candidate.
3132 cricket::Candidate candidate2;
3133 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3134 candidate2.set_component(1);
3135 candidate2.set_protocol("udp");
3136 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3137 candidate2);
3138 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3139
3140 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3141 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3142
3143 // No need here for a _WAIT check since we are checking that state hasn't
3144 // changed: if this is false we would be doing waits for nothing and if this
3145 // is true then there will be no messages processed anyways.
3146 EXPECT_FALSE(connection_with_remote_port(6000));
3147}
3148
deadbeefcbecd352015-09-23 11:50:27 -07003149// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003150TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3151 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003152 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003153
3154 PeerConnectionInterface::RTCOfferAnswerOptions options;
3155 options.use_rtp_mux = true;
3156
3157 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003158 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003159
deadbeefcbecd352015-09-23 11:50:27 -07003160 EXPECT_NE(session_->voice_rtp_transport_channel(),
3161 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003162
deadbeefab9b2d12015-10-14 11:33:11 -07003163 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003164 SessionDescriptionInterface* answer =
3165 CreateRemoteAnswer(session_->local_description());
3166 SetRemoteDescriptionWithoutError(answer);
3167
deadbeefcbecd352015-09-23 11:50:27 -07003168 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3169 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003170}
3171
deadbeefcbecd352015-09-23 11:50:27 -07003172// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003173TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3174 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003176
Donald Curtis0e209b02015-03-24 09:29:54 -07003177 PeerConnectionInterface::RTCOfferAnswerOptions options;
3178 options.use_rtp_mux = true;
3179
3180 SessionDescriptionInterface* offer = CreateOffer(options);
3181 SetLocalDescriptionWithoutError(offer);
3182
deadbeefcbecd352015-09-23 11:50:27 -07003183 EXPECT_NE(session_->voice_rtp_transport_channel(),
3184 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003185
deadbeefab9b2d12015-10-14 11:33:11 -07003186 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003187
3188 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003189 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003190 CreateRemoteAnswer(session_->local_description()));
3191 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3192 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3193 JsepSessionDescription* modified_answer =
3194 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3195 modified_answer->Initialize(answer_copy, "1", "1");
3196 SetRemoteDescriptionWithoutError(modified_answer); //
3197
deadbeefcbecd352015-09-23 11:50:27 -07003198 EXPECT_NE(session_->voice_rtp_transport_channel(),
3199 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003200}
3201
3202// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3203TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3204 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003205 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003206
3207 PeerConnectionInterface::RTCOfferAnswerOptions options;
3208 options.use_rtp_mux = true;
3209
3210 SessionDescriptionInterface* offer = CreateOffer(options);
3211 SetLocalDescriptionWithoutError(offer);
3212
deadbeefcbecd352015-09-23 11:50:27 -07003213 EXPECT_EQ(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
deadbeefcbecd352015-09-23 11:50:27 -07003221 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3222 session_->video_rtp_transport_channel());
3223}
3224
3225// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3226// audio content in the answer.
3227TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3228 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003229 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003230
3231 PeerConnectionInterface::RTCOfferAnswerOptions options;
3232 options.use_rtp_mux = true;
3233
3234 SessionDescriptionInterface* offer = CreateOffer(options);
3235 SetLocalDescriptionWithoutError(offer);
3236
3237 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3238 session_->video_rtp_transport_channel());
3239
deadbeefab9b2d12015-10-14 11:33:11 -07003240 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003241 cricket::MediaSessionOptions recv_options;
3242 recv_options.recv_audio = false;
3243 recv_options.recv_video = true;
3244 SessionDescriptionInterface* answer =
3245 CreateRemoteAnswer(session_->local_description(), recv_options);
3246 SetRemoteDescriptionWithoutError(answer);
3247
deadbeefd59daf82015-10-14 15:02:44 -07003248 EXPECT_TRUE(nullptr == session_->voice_channel());
3249 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003250
deadbeefd59daf82015-10-14 15:02:44 -07003251 session_->Close();
3252 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3253 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3254 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3255 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003256}
3257
3258// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3259TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3260 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003261 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003262
Donald Curtis0e209b02015-03-24 09:29:54 -07003263 PeerConnectionInterface::RTCOfferAnswerOptions options;
3264 options.use_rtp_mux = true;
3265
3266 SessionDescriptionInterface* offer = CreateOffer(options);
3267 SetLocalDescriptionWithoutError(offer);
3268
deadbeefcbecd352015-09-23 11:50:27 -07003269 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3270 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003271
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003273
3274 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003275 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 CreateRemoteAnswer(session_->local_description()));
3277 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3278 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3279 JsepSessionDescription* modified_answer =
3280 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3281 modified_answer->Initialize(answer_copy, "1", "1");
3282 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283
deadbeefcbecd352015-09-23 11:50:27 -07003284 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3285 session_->video_rtp_transport_channel());
3286}
3287
3288// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3289TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3290 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003291 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003292
3293 SessionDescriptionInterface* offer = CreateRemoteOffer();
3294 SetRemoteDescriptionWithoutError(offer);
3295
3296 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3297 session_->video_rtp_transport_channel());
3298
deadbeefab9b2d12015-10-14 11:33:11 -07003299 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003300 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003301 SetLocalDescriptionWithoutError(answer);
3302
3303 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3304 session_->video_rtp_transport_channel());
3305}
3306
3307// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3308TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3309 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003310 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003311
3312 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003313 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003314 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3315 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3316 JsepSessionDescription* modified_offer =
3317 new JsepSessionDescription(JsepSessionDescription::kOffer);
3318 modified_offer->Initialize(offer_copy, "1", "1");
3319
3320 // Expect an error when applying the remote description
3321 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3322 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003323}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324
Peter Thatcher4eddf182015-04-30 10:55:59 -07003325// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003326TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3327 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003328 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329
Donald Curtis0e209b02015-03-24 09:29:54 -07003330 PeerConnectionInterface::RTCOfferAnswerOptions options;
3331 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332
Donald Curtis0e209b02015-03-24 09:29:54 -07003333 SessionDescriptionInterface* offer = CreateOffer(options);
3334 SetLocalDescriptionWithoutError(offer);
3335
deadbeefcbecd352015-09-23 11:50:27 -07003336 EXPECT_NE(session_->voice_rtp_transport_channel(),
3337 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003338
deadbeefab9b2d12015-10-14 11:33:11 -07003339 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003340 SessionDescriptionInterface* answer =
3341 CreateRemoteAnswer(session_->local_description());
3342 SetRemoteDescriptionWithoutError(answer);
3343
3344 // This should lead to an audio-only call but isn't implemented
3345 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003346 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3347 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003348}
3349
deadbeefcbecd352015-09-23 11:50:27 -07003350// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003351TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3352 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003353 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003354 PeerConnectionInterface::RTCOfferAnswerOptions options;
3355 options.use_rtp_mux = true;
3356
3357 SessionDescriptionInterface* offer = CreateOffer(options);
3358 SetLocalDescriptionWithoutError(offer);
3359
deadbeefcbecd352015-09-23 11:50:27 -07003360 EXPECT_NE(session_->voice_rtp_transport_channel(),
3361 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003362
deadbeefab9b2d12015-10-14 11:33:11 -07003363 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003364
3365 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003366 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003367 CreateRemoteAnswer(session_->local_description()));
3368 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3369 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3370 JsepSessionDescription* modified_answer =
3371 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3372 modified_answer->Initialize(answer_copy, "1", "1");
3373 SetRemoteDescriptionWithoutError(modified_answer); //
3374
deadbeefcbecd352015-09-23 11:50:27 -07003375 EXPECT_NE(session_->voice_rtp_transport_channel(),
3376 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377}
3378
Peter Thatcher4eddf182015-04-30 10:55:59 -07003379// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3380TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3381 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003382 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003383
3384 PeerConnectionInterface::RTCOfferAnswerOptions options;
3385 options.use_rtp_mux = true;
3386
3387 SessionDescriptionInterface* offer = CreateOffer(options);
3388 SetRemoteDescriptionWithoutError(offer);
3389
deadbeefcbecd352015-09-23 11:50:27 -07003390 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3391 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003392}
3393
skvlad6c87a672016-05-17 17:49:52 -07003394// Adding a new channel to a BUNDLE which is already connected should directly
3395// assign the bundle transport to the channel, without first setting a
3396// disconnected non-bundle transport and then replacing it. The application
3397// should not receive any changes in the ICE state.
3398TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3399 LoopbackNetworkConfiguration config;
3400 LoopbackNetworkManager loopback_network_manager(this, config);
3401 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3402 // connected. Disabling either of these two means that we need to wait for the
3403 // answer to find out if more transports are needed.
3404 configuration_.bundle_policy =
3405 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003406 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003407 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003408
3409 // Negotiate an audio channel with MAX_BUNDLE enabled.
3410 SendAudioOnlyStream2();
3411 SessionDescriptionInterface* offer = CreateOffer();
3412 SetLocalDescriptionWithoutError(offer);
3413 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3414 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3415 std::string sdp;
3416 offer->ToString(&sdp);
3417 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3418 JsepSessionDescription::kAnswer, sdp, nullptr);
3419 ASSERT_TRUE(answer != NULL);
3420 SetRemoteDescriptionWithoutError(answer);
3421
3422 // Wait for the ICE state to stabilize.
3423 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3424 observer_.ice_connection_state_, kIceCandidatesTimeout);
3425 observer_.ice_connection_state_history_.clear();
3426
3427 // Now add a video channel which should be using the same bundle transport.
3428 SendAudioVideoStream2();
3429 offer = CreateOffer();
3430 offer->ToString(&sdp);
3431 SetLocalDescriptionWithoutError(offer);
3432 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3433 sdp, nullptr);
3434 ASSERT_TRUE(answer != NULL);
3435 SetRemoteDescriptionWithoutError(answer);
3436
3437 // Wait for ICE state to stabilize
3438 rtc::Thread::Current()->ProcessMessages(0);
3439 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3440 observer_.ice_connection_state_, kIceCandidatesTimeout);
3441
3442 // No ICE state changes are expected to happen.
3443 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3444}
3445
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003446TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3447 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003448 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003449
3450 PeerConnectionInterface::RTCOfferAnswerOptions options;
3451 SessionDescriptionInterface* offer = CreateOffer(options);
3452 SetLocalDescriptionWithoutError(offer);
3453
deadbeefcbecd352015-09-23 11:50:27 -07003454 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3455 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003456
deadbeefab9b2d12015-10-14 11:33:11 -07003457 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003458 SessionDescriptionInterface* answer =
3459 CreateRemoteAnswer(session_->local_description());
3460 SetRemoteDescriptionWithoutError(answer);
3461
deadbeefcbecd352015-09-23 11:50:27 -07003462 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3463 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003464}
3465
3466TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3467 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003468 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003469
3470 PeerConnectionInterface::RTCOfferAnswerOptions options;
3471 SessionDescriptionInterface* offer = CreateOffer(options);
3472 SetLocalDescriptionWithoutError(offer);
3473
deadbeefcbecd352015-09-23 11:50:27 -07003474 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3475 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003476
deadbeefab9b2d12015-10-14 11:33:11 -07003477 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003478 SessionDescriptionInterface* answer =
3479 CreateRemoteAnswer(session_->local_description());
3480 SetRemoteDescriptionWithoutError(answer);
3481
deadbeefcbecd352015-09-23 11:50:27 -07003482 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3483 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003484}
3485
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003486// This test verifies that SetLocalDescription and SetRemoteDescription fails
3487// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3488TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003489 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003490 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003491
3492 PeerConnectionInterface::RTCOfferAnswerOptions options;
3493 options.use_rtp_mux = true;
3494
3495 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003496 std::string offer_str;
3497 offer->ToString(&offer_str);
3498 // Disable rtcp-mux
3499 const std::string rtcp_mux = "rtcp-mux";
3500 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003501 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003502 xrtcp_mux.c_str(), xrtcp_mux.length(),
3503 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003504 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003505 new JsepSessionDescription(JsepSessionDescription::kOffer);
3506 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003507 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003508 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003509 new JsepSessionDescription(JsepSessionDescription::kOffer);
3510 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003511 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003512 // Trying unmodified SDP.
3513 SetLocalDescriptionWithoutError(offer);
3514}
3515
jbauchcb560652016-08-04 05:20:32 -07003516TEST_F(WebRtcSessionTest, SetSetupGcm) {
3517 InitWithGcm();
3518 SendAudioVideoStream1();
3519 CreateAndSetRemoteOfferAndLocalAnswer();
3520}
3521
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3523 TestCanInsertDtmf(false);
3524}
3525
3526TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3527 TestCanInsertDtmf(true);
3528}
3529
3530TEST_F(WebRtcSessionTest, InsertDtmf) {
3531 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003532 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003533 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 CreateAndSetRemoteOfferAndLocalAnswer();
3535 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3536 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3537
3538 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 const int expected_duration = 90;
3540 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3541 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3542 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3543
3544 // Verify
3545 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003546 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003548 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003550 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003552 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553}
3554
deadbeefd59daf82015-10-14 15:02:44 -07003555// This test verifies the |initial_offerer| flag when session initiates the
3556// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003557TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003558 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003559 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003560 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003561 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3562 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003563 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003565 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003566}
3567
deadbeefd59daf82015-10-14 15:02:44 -07003568// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003569TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003570 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003571 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 SessionDescriptionInterface* offer = CreateRemoteOffer();
3573 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003574 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575
deadbeefd59daf82015-10-14 15:02:44 -07003576 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003578 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579}
3580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3582TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003583 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003584 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003585 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003587 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 CreateRemoteAnswer(session_->local_description()));
3589
3590 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3591 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003592 JsepSessionDescription* modified_answer =
3593 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
3595 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3596 answer->session_id(),
3597 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003598 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599
wu@webrtc.org4e393072014-04-07 17:04:35 +00003600 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 std::string sdp;
3602 EXPECT_TRUE(answer->ToString(&sdp));
3603 const std::string kAudioMid = "a=mid:audio";
3604 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003605 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 kAudioMidReplaceStr.c_str(),
3607 kAudioMidReplaceStr.length(),
3608 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003609 SessionDescriptionInterface* modified_answer1 =
3610 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003611 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612
wu@webrtc.org4e393072014-04-07 17:04:35 +00003613 // Different media types.
3614 EXPECT_TRUE(answer->ToString(&sdp));
3615 const std::string kAudioMline = "m=audio";
3616 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003617 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003618 kAudioMlineReplaceStr.c_str(),
3619 kAudioMlineReplaceStr.length(),
3620 &sdp);
3621 SessionDescriptionInterface* modified_answer2 =
3622 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3623 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3624
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 SetRemoteDescriptionWithoutError(answer.release());
3626}
3627
3628// Verifying remote offer and local answer have matching m-lines as per
3629// RFC 3264.
3630TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003631 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003632 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633 SessionDescriptionInterface* offer = CreateRemoteOffer();
3634 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003635 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003636
3637 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3638 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003639 JsepSessionDescription* modified_answer =
3640 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641
3642 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3643 answer->session_id(),
3644 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003645 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003646 SetLocalDescriptionWithoutError(answer);
3647}
3648
3649// This test verifies that WebRtcSession does not start candidate allocation
3650// before SetLocalDescription is called.
3651TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003652 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003653 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003654 SessionDescriptionInterface* offer = CreateRemoteOffer();
3655 cricket::Candidate candidate;
3656 candidate.set_component(1);
3657 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3658 candidate);
3659 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3660 cricket::Candidate candidate1;
3661 candidate1.set_component(1);
3662 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3663 candidate1);
3664 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3665 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003666 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3667 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003668
3669 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003670 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3672 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3673
htaa2a49d92016-03-04 02:51:39 -08003674 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003675 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3677}
3678
3679// This test verifies that crypto parameter is updated in local session
3680// description as per security policy set in MediaSessionDescriptionFactory.
3681TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003682 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003683 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003684 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003685
3686 // Making sure SetLocalDescription correctly sets crypto value in
3687 // SessionDescription object after de-serialization of sdp string. The value
3688 // will be set as per MediaSessionDescriptionFactory.
3689 std::string offer_str;
3690 offer->ToString(&offer_str);
3691 SessionDescriptionInterface* jsep_offer_str =
3692 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3693 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003694 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3695 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003696}
3697
3698// This test verifies the crypto parameter when security is disabled.
3699TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003700 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003701 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003702 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003703 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003704
3705 // Making sure SetLocalDescription correctly sets crypto value in
3706 // SessionDescription object after de-serialization of sdp string. The value
3707 // will be set as per MediaSessionDescriptionFactory.
3708 std::string offer_str;
3709 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003710 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003711 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3712 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003713 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3714 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003715}
3716
3717// This test verifies that an answer contains new ufrag and password if an offer
3718// with new ufrag and password is received.
3719TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003720 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003721 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003722 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003724 SetRemoteDescriptionWithoutError(offer.release());
3725
deadbeefab9b2d12015-10-14 11:33:11 -07003726 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003727 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003728 SetLocalDescriptionWithoutError(answer.release());
3729
3730 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003731 for (const cricket::ContentInfo& content :
3732 session_->local_description()->description()->contents()) {
3733 options.transport_options[content.name].ice_restart = true;
3734 }
kwibergd1fe2812016-04-27 06:47:29 -07003735 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003736 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737 SetRemoteDescriptionWithoutError(updated_offer1.release());
3738
kwibergd1fe2812016-04-27 06:47:29 -07003739 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740
deadbeef0ed85b22016-02-23 17:24:52 -08003741 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3742 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
deadbeef0ed85b22016-02-23 17:24:52 -08003744 // Even a second answer (created before the description is set) should have
3745 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003746 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003747
3748 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3749 session_->local_description()->description()));
3750
3751 SetLocalDescriptionWithoutError(updated_answer2.release());
3752}
3753
3754// This test verifies that an answer contains new ufrag and password if an offer
3755// that changes either the ufrag or password (but not both) is received.
3756// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3757// a=ice-pwd attributes compared to the previous SDP from the peer, it
3758// indicates that ICE is restarting for this media stream."
3759TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3760 Init();
3761 cricket::MediaSessionOptions options;
3762 options.recv_audio = true;
3763 options.recv_video = true;
3764 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003765 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003766 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3767 SetRemoteDescriptionWithoutError(offer.release());
3768
3769 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003770 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003771 SetLocalDescriptionWithoutError(answer.release());
3772
3773 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003774 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003775 CreateRemoteOffer(options, session_->remote_description()));
3776 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3777 "original_password12345");
3778 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3779
kwibergd1fe2812016-04-27 06:47:29 -07003780 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003781 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3782 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003783 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003784
3785 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003786 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003787 CreateRemoteOffer(options, session_->remote_description()));
3788 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3789 "modified_password12345");
3790 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3791
kwibergd1fe2812016-04-27 06:47:29 -07003792 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003793 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3794 session_->local_description()->description()));
3795 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003796}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003797
wu@webrtc.org91053e72013-08-10 07:18:04 +00003798// This test verifies that an answer contains old ufrag and password if an offer
3799// with old ufrag and password is received.
3800TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003801 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003803 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003804 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003805 SetRemoteDescriptionWithoutError(offer.release());
3806
deadbeefab9b2d12015-10-14 11:33:11 -07003807 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003808 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003809 SetLocalDescriptionWithoutError(answer.release());
3810
3811 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003812 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003813 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814 SetRemoteDescriptionWithoutError(updated_offer2.release());
3815
kwibergd1fe2812016-04-27 06:47:29 -07003816 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817
deadbeef0ed85b22016-02-23 17:24:52 -08003818 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3819 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003820
3821 SetLocalDescriptionWithoutError(updated_answer2.release());
3822}
3823
deadbeef0ed85b22016-02-23 17:24:52 -08003824// This test verifies that if an offer does an ICE restart on some, but not all
3825// media sections, the answer will change the ufrag/password in the correct
3826// media sections.
3827TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3828 Init();
3829 cricket::MediaSessionOptions options;
3830 options.recv_video = true;
3831 options.recv_audio = true;
3832 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003833 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003834
3835 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3836 "aaaaaaaaaaaaaaaaaaaaaa");
3837 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3838 "bbbbbbbbbbbbbbbbbbbbbb");
3839 SetRemoteDescriptionWithoutError(offer.release());
3840
3841 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003842 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003843 SetLocalDescriptionWithoutError(answer.release());
3844
3845 // Receive an offer with new ufrag and password, but only for the video media
3846 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003847 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003848 CreateRemoteOffer(options, session_->remote_description()));
3849 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3850 "cccccccccccccccccccccc");
3851 SetRemoteDescriptionWithoutError(updated_offer.release());
3852
kwibergd1fe2812016-04-27 06:47:29 -07003853 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003854
3855 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3856 session_->local_description()->description(),
3857 cricket::MEDIA_TYPE_AUDIO));
3858
3859 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3860 session_->local_description()->description(),
3861 cricket::MEDIA_TYPE_VIDEO));
3862
3863 SetLocalDescriptionWithoutError(updated_answer.release());
3864}
3865
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003866TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003867 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003868 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003869 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870 const std::string session_id_orig = offer->session_id();
3871 const std::string session_version_orig = offer->session_version();
3872 SetLocalDescriptionWithoutError(offer);
3873
3874 video_channel_ = media_engine_->GetVideoChannel(0);
3875 video_channel_->set_fail_set_send_codecs(true);
3876
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003877 SessionDescriptionInterface* answer =
3878 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003879 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003880
3881 // Test that after a content error, setting any description will
3882 // result in an error.
3883 video_channel_->set_fail_set_send_codecs(false);
3884 answer = CreateRemoteAnswer(session_->local_description());
3885 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3886 offer = CreateRemoteOffer();
3887 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003888}
3889
3890// Runs the loopback call test with BUNDLE and STUN disabled.
3891TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3892 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003893 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003894 cricket::PORTALLOCATOR_DISABLE_STUN |
3895 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003896 TestLoopbackCall();
3897}
3898
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003899TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003900 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003901 cricket::PORTALLOCATOR_DISABLE_STUN |
3902 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3903 cricket::PORTALLOCATOR_DISABLE_RELAY);
3904
3905 // best connection is IPv6 since it has higher network preference.
3906 LoopbackNetworkConfiguration config;
3907 config.test_ipv6_network_ = true;
3908 config.best_connection_after_initial_ice_converged_ =
3909 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3910
3911 TestLoopbackCall(config);
3912}
3913
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003914// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003915TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003916 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3917 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003918 TestLoopbackCall();
3919}
3920
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003921TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003922 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003923 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003924 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003925 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003926 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003927}
3928
Henrik Boström87713d02015-08-25 09:53:21 +02003929TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003930 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003931
htaa2a49d92016-03-04 02:51:39 -08003932 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003933 options_.disable_sctp_data_channels = false;
3934
Henrik Boström87713d02015-08-25 09:53:21 +02003935 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003936
3937 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003938 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3939}
3940
3941// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3942// before and after BUNDLE is negotiated.
3943TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
3944 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3945 SetFactoryDtlsSrtp();
3946 InitWithDtls(GetParam());
3947
3948 // Initially these fields should be empty.
3949 EXPECT_FALSE(session_->sctp_content_name());
3950 EXPECT_FALSE(session_->sctp_transport_name());
3951
3952 // Create offer with audio/video/data.
3953 // Default bundle policy is "balanced", so data should be using its own
3954 // transport.
3955 SendAudioVideoStream1();
3956 CreateDataChannel();
3957 InitiateCall();
3958 ASSERT_TRUE(session_->sctp_content_name());
3959 ASSERT_TRUE(session_->sctp_transport_name());
3960 EXPECT_EQ("data", *session_->sctp_content_name());
3961 EXPECT_EQ("data", *session_->sctp_transport_name());
3962
3963 // Create answer that finishes BUNDLE negotiation, which means everything
3964 // should be bundled on the first transport (audio).
3965 cricket::MediaSessionOptions answer_options;
3966 answer_options.recv_video = true;
3967 answer_options.bundle_enabled = true;
3968 answer_options.data_channel_type = cricket::DCT_SCTP;
3969 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3970 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3971 ASSERT_TRUE(session_->sctp_content_name());
3972 ASSERT_TRUE(session_->sctp_transport_name());
3973 EXPECT_EQ("data", *session_->sctp_content_name());
3974 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003975}
3976
Henrik Boström87713d02015-08-25 09:53:21 +02003977TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003978 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003979
Henrik Boström87713d02015-08-25 09:53:21 +02003980 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003981
kwibergd1fe2812016-04-27 06:47:29 -07003982 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003983 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003984 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3985}
3986
Henrik Boström87713d02015-08-25 09:53:21 +02003987TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003988 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003989 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003990 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003991
3992 // Create remote offer with SCTP.
3993 cricket::MediaSessionOptions options;
3994 options.data_channel_type = cricket::DCT_SCTP;
3995 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003996 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003997 SetRemoteDescriptionWithoutError(offer);
3998
3999 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07004000 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004001 EXPECT_TRUE(answer != NULL);
4002 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
4003 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004004}
4005
deadbeef953c2ce2017-01-09 14:53:41 -08004006// Test that if DTLS is disabled, we don't end up with an SctpTransport
4007// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004008TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004009 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004010 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004011
4012 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004013 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4014 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004015}
4016
deadbeef953c2ce2017-01-09 14:53:41 -08004017// Test that if DTLS is enabled, we end up with an SctpTransport created
4018// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004019TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004021
Henrik Boström87713d02015-08-25 09:53:21 +02004022 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004023
4024 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004025 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4026 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004027}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004028
deadbeef953c2ce2017-01-09 14:53:41 -08004029// Test that if SCTP is disabled, we don't end up with an SctpTransport
4030// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004031TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004033 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004034 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004035
4036 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004037 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4038 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004039}
4040
Henrik Boström87713d02015-08-25 09:53:21 +02004041TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004042 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004043 const int new_send_port = 9998;
4044 const int new_recv_port = 7775;
4045
Henrik Boström87713d02015-08-25 09:53:21 +02004046 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004047 SetFactoryDtlsSrtp();
4048
4049 // By default, don't actually add the codecs to desc_factory_; they don't
4050 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4051 // let the session description get parsed. That'll get the proper codecs
4052 // into the stream.
4053 cricket::MediaSessionOptions options;
4054 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4055 "stream1", new_send_port, options);
4056
4057 // SetRemoteDescription will take the ownership of the offer.
4058 SetRemoteDescriptionWithoutError(offer);
4059
htaa2a49d92016-03-04 02:51:39 -08004060 SessionDescriptionInterface* answer =
4061 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004062 ASSERT_TRUE(answer != NULL);
4063
4064 // Now set the local description, which'll take ownership of the answer.
4065 SetLocalDescriptionWithoutError(answer);
4066
4067 // TEST PLAN: Set the port number to something new, set it in the SDP,
4068 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08004069 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07004070 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004071 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
4072 EXPECT_EQ(
4073 new_recv_port,
4074 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
4075 EXPECT_EQ(
4076 new_send_port,
4077 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004078}
4079
deadbeef953c2ce2017-01-09 14:53:41 -08004080// Verifies that when a session's SctpTransport receives an OPEN message,
4081// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004082// config.
4083TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4084 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4085
4086 InitWithDtls(GetParam());
4087
4088 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004089 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4090 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004091
deadbeef953c2ce2017-01-09 14:53:41 -08004092 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004093 webrtc::DataChannelInit config;
4094 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004095 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004096 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4097 cricket::ReceiveDataParams params;
4098 params.ssrc = config.id;
4099 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004100 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4101 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004102
deadbeef953c2ce2017-01-09 14:53:41 -08004103 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004104 EXPECT_EQ(config.id, last_data_channel_config_.id);
4105 EXPECT_FALSE(last_data_channel_config_.negotiated);
4106 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4107 last_data_channel_config_.open_handshake_role);
4108}
4109
4110TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004111 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004112 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004113
htaa2a49d92016-03-04 02:51:39 -08004114 configuration_.certificates.push_back(certificate);
4115 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004116 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4117
4118 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4119}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120
Henrik Boström87713d02015-08-25 09:53:21 +02004121// Verifies that CreateOffer succeeds when CreateOffer is called before async
4122// identity generation is finished (even if a certificate is provided this is
4123// an async op).
4124TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4125 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4126 InitWithDtls(GetParam());
4127
Henrik Boströmd8281982015-08-27 10:12:24 +02004128 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004129 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004130 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004131
wu@webrtc.org91053e72013-08-10 07:18:04 +00004132 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004133 VerifyNoCryptoParams(offer->description(), true);
4134 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004135}
4136
4137// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004138// identity generation is finished (even if a certificate is provided this is
4139// an async op).
4140TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004141 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004142 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004143 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004144
4145 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004146 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004147 std::unique_ptr<JsepSessionDescription> offer(
4148 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004149 ASSERT_TRUE(offer.get() != NULL);
4150 SetRemoteDescriptionWithoutError(offer.release());
4151
kwibergd1fe2812016-04-27 06:47:29 -07004152 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004153 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004154 VerifyNoCryptoParams(answer->description(), true);
4155 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004156}
4157
4158// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004159// identity generation is finished (even if a certificate is provided this is
4160// an async op).
4161TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004162 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004163 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004164
Henrik Boströmd8281982015-08-27 10:12:24 +02004165 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004166
kwibergd1fe2812016-04-27 06:47:29 -07004167 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004168 EXPECT_TRUE(offer != NULL);
4169}
4170
4171// Verifies that CreateOffer fails when CreateOffer is called after async
4172// identity generation fails.
4173TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004174 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004175 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004176
Henrik Boströmd8281982015-08-27 10:12:24 +02004177 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004178
kwibergd1fe2812016-04-27 06:47:29 -07004179 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004180 EXPECT_TRUE(offer == NULL);
4181}
4182
4183// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4184// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004185TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004186 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004187 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004188 VerifyMultipleAsyncCreateDescription(GetParam(),
4189 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004190}
4191
4192// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4193// before async identity generation fails.
4194TEST_F(WebRtcSessionTest,
4195 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004196 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004197 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4198 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004199}
4200
4201// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4202// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004203TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004204 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004205 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004206 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004207 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004208}
4209
4210// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4211// before async identity generation fails.
4212TEST_F(WebRtcSessionTest,
4213 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004214 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004215 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4216 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004217}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004218
4219// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4220// offer has no SDES crypto but only DTLS fingerprint.
4221TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4222 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004223 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004224 // Create a remote offer with secured transport disabled.
4225 cricket::MediaSessionOptions options;
4226 JsepSessionDescription* offer(CreateRemoteOffer(
4227 options, cricket::SEC_DISABLED));
4228 // Adds a DTLS fingerprint to the remote offer.
4229 cricket::SessionDescription* sdp = offer->description();
4230 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4231 ASSERT_TRUE(audio != NULL);
4232 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4233 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004234 rtc::SSLFingerprint::CreateFromRfc4572(
4235 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004236 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004237 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004238}
4239
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004240TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004241 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004243 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004244 SessionDescriptionInterface* offer = CreateOffer();
4245
4246 SetLocalDescriptionWithoutError(offer);
4247
4248 voice_channel_ = media_engine_->GetVoiceChannel(0);
4249
4250 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004251 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004252 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004253}
4254
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004255// Tests that we can renegotiate new media content with ICE candidates in the
4256// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004257TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004258 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004259 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260 SetFactoryDtlsSrtp();
4261
deadbeefab9b2d12015-10-14 11:33:11 -07004262 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004263 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004264 SetLocalDescriptionWithoutError(offer);
4265
4266 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4267 SetRemoteDescriptionWithoutError(answer);
4268
4269 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004270 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004271 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4272
4273 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004274 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004275 candidate1.set_component(1);
4276 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4277 candidate1);
4278 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4279 SetRemoteDescriptionWithoutError(offer);
4280
htaa2a49d92016-03-04 02:51:39 -08004281 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004282 SetLocalDescriptionWithoutError(answer);
4283}
4284
4285// Tests that we can renegotiate new media content with ICE candidates separated
4286// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004287TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004288 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004289 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004290 SetFactoryDtlsSrtp();
4291
deadbeefab9b2d12015-10-14 11:33:11 -07004292 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004293 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004294 SetLocalDescriptionWithoutError(offer);
4295
4296 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4297 SetRemoteDescriptionWithoutError(answer);
4298
4299 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004300 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004301 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4302 SetRemoteDescriptionWithoutError(offer);
4303
4304 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004305 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004306 candidate1.set_component(1);
4307 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4308 candidate1);
4309 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4310
htaa2a49d92016-03-04 02:51:39 -08004311 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004312 SetLocalDescriptionWithoutError(answer);
4313}
honghaiz7f777492016-02-02 21:54:01 -08004314
zhihuang9763d562016-08-05 11:14:50 -07004315#ifdef HAVE_QUIC
4316TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4317 configuration_.enable_quic = true;
4318 InitWithDtls(GetParam());
4319 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4320 SessionDescriptionInterface* offer = CreateOffer();
4321 ASSERT_TRUE(offer);
4322 ASSERT_TRUE(offer->description());
4323 SetLocalDescriptionWithoutError(offer);
4324 cricket::MediaSessionOptions options;
4325 options.recv_audio = true;
4326 options.recv_video = true;
4327 SessionDescriptionInterface* answer =
4328 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4329 ASSERT_TRUE(answer);
4330 ASSERT_TRUE(answer->description());
4331 SetRemoteDescriptionWithoutError(answer);
4332}
4333#endif // HAVE_QUIC
4334
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004335// Tests that RTX codec is removed from the answer when it isn't supported
4336// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004337TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004338 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004339 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004340 std::string offer_sdp(kSdpWithRtx);
4341
4342 SessionDescriptionInterface* offer =
4343 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4344 EXPECT_TRUE(offer->ToString(&offer_sdp));
4345
4346 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004347 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004348 SetRemoteDescriptionWithoutError(offer);
4349
htaa2a49d92016-03-04 02:51:39 -08004350 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004351 // Answer SDP does not contain the RTX codec.
4352 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004353 SetLocalDescriptionWithoutError(answer);
4354}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004355
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004356// This verifies that the voice channel after bundle has both options from video
4357// and voice channels.
4358TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4359 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004360 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004361
4362 PeerConnectionInterface::RTCOfferAnswerOptions options;
4363 options.use_rtp_mux = true;
4364
4365 SessionDescriptionInterface* offer = CreateOffer(options);
4366 SetLocalDescriptionWithoutError(offer);
4367
4368 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4369 rtc::Socket::Option::OPT_SNDBUF, 4000);
4370
4371 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4372 rtc::Socket::Option::OPT_RCVBUF, 8000);
4373
4374 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004375 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004376 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4377 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004378 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004379 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4380
deadbeefcbecd352015-09-23 11:50:27 -07004381 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004382 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4383 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004384 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004385 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4386
deadbeefcbecd352015-09-23 11:50:27 -07004387 EXPECT_NE(session_->voice_rtp_transport_channel(),
4388 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004389
deadbeefab9b2d12015-10-14 11:33:11 -07004390 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004391 SessionDescriptionInterface* answer =
4392 CreateRemoteAnswer(session_->local_description());
4393 SetRemoteDescriptionWithoutError(answer);
4394
deadbeefcbecd352015-09-23 11:50:27 -07004395 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004396 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4397 EXPECT_EQ(4000, option_val);
4398
deadbeefcbecd352015-09-23 11:50:27 -07004399 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004400 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4401 EXPECT_EQ(8000, option_val);
4402}
4403
tommi0f620f42015-07-09 03:25:02 -07004404// Test creating a session, request multiple offers, destroy the session
4405// and make sure we got success/failure callbacks for all of the requests.
4406// Background: crbug.com/507307
4407TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4408 Init();
4409
4410 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4411 PeerConnectionInterface::RTCOfferAnswerOptions options;
4412 options.offer_to_receive_audio =
4413 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004414 cricket::MediaSessionOptions session_options;
4415 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004416
4417 for (auto& o : observers) {
4418 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004419 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004420 }
4421
4422 session_.reset();
4423
tommi0f620f42015-07-09 03:25:02 -07004424 for (auto& o : observers) {
4425 // We expect to have received a notification now even if the session was
4426 // terminated. The offer creation may or may not have succeeded, but we
4427 // must have received a notification which, so the only invalid state
4428 // is kInit.
4429 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4430 }
4431}
4432
stefanc1aeaf02015-10-15 07:26:07 -07004433TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4434 TestPacketOptions();
4435}
4436
deadbeef057ecf02016-01-20 14:30:43 -08004437// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4438// is destroyed.
4439TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4440 Init();
4441 session_.reset();
4442 EXPECT_TRUE(session_destroyed_);
4443}
4444
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004445// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4446// currently fails because upon disconnection and reconnection OnIceComplete is
4447// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004448
deadbeefcbecd352015-09-23 11:50:27 -07004449INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4450 WebRtcSessionTest,
4451 testing::Values(ALREADY_GENERATED,
4452 DTLS_IDENTITY_STORE));