blob: 1a5f47da257e4d33f6205c832a89a63a3c09a6f3 [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/fakemetricsobserver.h"
16#include "webrtc/api/jsepicecandidate.h"
17#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080018#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000019#include "webrtc/base/fakenetwork.h"
20#include "webrtc/base/firewallsocketserver.h"
21#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/network.h"
24#include "webrtc/base/physicalsocketserver.h"
25#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020026#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/sslstreamadapter.h"
28#include "webrtc/base/stringutils.h"
29#include "webrtc/base/thread.h"
30#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070031#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/fakemediaengine.h"
33#include "webrtc/media/base/fakevideorenderer.h"
34#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010035#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080036#include "webrtc/media/sctp/sctptransportinternal.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080037#include "webrtc/p2p/base/packettransportinternal.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/p2p/base/stunserver.h"
39#include "webrtc/p2p/base/teststunserver.h"
40#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080042#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010043#include "webrtc/pc/channelmanager.h"
44#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080045#include "webrtc/pc/peerconnection.h"
46#include "webrtc/pc/sctputils.h"
47#include "webrtc/pc/test/fakertccertificategenerator.h"
48#include "webrtc/pc/videotrack.h"
49#include "webrtc/pc/webrtcsession.h"
50#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000057using webrtc::CreateSessionDescriptionObserver;
58using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070059using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070060using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070062using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::JsepIceCandidate;
64using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000065using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066using webrtc::PeerConnectionInterface;
67using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070068using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000070using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000071using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000072using webrtc::kCreateChannelFailed;
73using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000075using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000076using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000077using webrtc::kSdpWithoutDtlsFingerprint;
78using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000080using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000081using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000083typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
84
wu@webrtc.org364f2042013-11-20 21:49:41 +000085static const int kClientAddrPort = 0;
86static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000087static const char kClientIPv6AddrHost1[] =
88 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000089static const char kClientAddrHost2[] = "22.22.22.22";
90static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000091static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
92static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000093static const char kTurnUsername[] = "test";
94static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
96static const char kSessionVersion[] = "1";
97
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098// Media index of candidates belonging to the first media content.
99static const int kMediaContentIndex0 = 0;
100static const char kMediaContentName0[] = "audio";
101
102// Media index of candidates belonging to the second media content.
103static const int kMediaContentIndex1 = 1;
104static const char kMediaContentName1[] = "video";
105
deadbeef953c2ce2017-01-09 14:53:41 -0800106static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107static const int kIceCandidatesTimeout = 10000;
108
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000109static const char kFakeDtlsFingerprint[] =
110 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
111 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
112
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000113static const char kTooLongIceUfragPwd[] =
114 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
115 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
116 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
117 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
118
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000119static const char kSdpWithRtx[] =
120 "v=0\r\n"
121 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
122 "s=-\r\n"
123 "t=0 0\r\n"
124 "a=msid-semantic: WMS stream1\r\n"
125 "m=video 9 RTP/SAVPF 0 96\r\n"
126 "c=IN IP4 0.0.0.0\r\n"
127 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
128 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
129 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
130 "a=mid:video\r\n"
131 "a=sendrecv\r\n"
132 "a=rtcp-mux\r\n"
133 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
134 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
135 "a=rtpmap:0 fake_video_codec/90000\r\n"
136 "a=rtpmap:96 rtx/90000\r\n"
137 "a=fmtp:96 apt=0\r\n";
138
deadbeefab9b2d12015-10-14 11:33:11 -0700139static const char kStream1[] = "stream1";
140static const char kVideoTrack1[] = "video1";
141static const char kAudioTrack1[] = "audio1";
142
143static const char kStream2[] = "stream2";
144static const char kVideoTrack2[] = "video2";
145static const char kAudioTrack2[] = "audio2";
146
Henrik Boström87713d02015-08-25 09:53:21 +0200147enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
148
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149class MockIceObserver : public webrtc::IceObserver {
150 public:
151 MockIceObserver()
152 : oncandidatesready_(false),
153 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
154 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
155 }
156
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200157 virtual ~MockIceObserver() = default;
158
zstein6dfd53a2017-03-06 13:49:03 -0800159 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800160 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700162 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 }
perkjdfb769d2016-02-09 03:09:43 -0800164 void OnIceGatheringChange(
165 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 // We can never transition back to "new".
167 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
168 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800169 oncandidatesready_ =
170 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 }
172
173 // Found a new candidate.
jbauch81bf7b02017-03-25 08:31:12 -0700174 void OnIceCandidate(
175 std::unique_ptr<webrtc::IceCandidateInterface> candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
nissec80e7412017-01-11 05:56:46 -0800184 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700194 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700203 std::vector<PeerConnectionInterface::IceConnectionState>
204 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700205 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206};
207
deadbeef953c2ce2017-01-09 14:53:41 -0800208// Used for tests in this file to verify that WebRtcSession responds to signals
209// from the SctpTransport correctly, and calls Start with the correct
210// local/remote ports.
211class FakeSctpTransport : public cricket::SctpTransportInternal {
212 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800213 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800214 bool Start(int local_port, int remote_port) override {
215 local_port_ = local_port;
216 remote_port_ = remote_port;
217 return true;
218 }
219 bool OpenStream(int sid) override { return true; }
220 bool ResetStream(int sid) override { return true; }
221 bool SendData(const cricket::SendDataParams& params,
222 const rtc::CopyOnWriteBuffer& payload,
223 cricket::SendDataResult* result = nullptr) override {
224 return true;
225 }
226 bool ReadyToSendData() override { return true; }
227 void set_debug_name_for_testing(const char* debug_name) override {}
228
229 int local_port() const { return local_port_; }
230 int remote_port() const { return remote_port_; }
231
232 private:
233 int local_port_ = -1;
234 int remote_port_ = -1;
235};
236
237class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
238 public:
239 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800240 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800241 last_fake_sctp_transport_ = new FakeSctpTransport();
242 return std::unique_ptr<cricket::SctpTransportInternal>(
243 last_fake_sctp_transport_);
244 }
245
246 FakeSctpTransport* last_fake_sctp_transport() {
247 return last_fake_sctp_transport_;
248 }
249
250 private:
251 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
252};
253
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254class WebRtcSessionForTest : public webrtc::WebRtcSession {
255 public:
zhihuang29ff8442016-07-27 11:07:25 -0700256 WebRtcSessionForTest(
nisseeaabdf62017-05-05 02:23:02 -0700257 webrtc::Call* fake_call,
258 cricket::ChannelManager* channel_manager,
259 const cricket::MediaConfig& media_config,
260 webrtc::RtcEventLog* event_log,
zhihuang29ff8442016-07-27 11:07:25 -0700261 rtc::Thread* network_thread,
262 rtc::Thread* worker_thread,
263 rtc::Thread* signaling_thread,
264 cricket::PortAllocator* port_allocator,
265 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800266 std::unique_ptr<cricket::TransportController> transport_controller,
267 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
nisseeaabdf62017-05-05 02:23:02 -0700268 : WebRtcSession(fake_call, channel_manager, media_config, event_log,
danilchape9021a32016-05-17 01:52:02 -0700269 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700270 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700271 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700272 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800273 std::move(transport_controller),
274 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 RegisterIceObserver(ice_observer);
276 }
277 virtual ~WebRtcSessionForTest() {}
278
deadbeefcbecd352015-09-23 11:50:27 -0700279 // Note that these methods are only safe to use if the signaling thread
280 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800281 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700282 return rtp_transport_channel(voice_channel());
283 }
284
deadbeef5bd5ca32017-02-10 11:31:50 -0800285 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700286 return rtcp_transport_channel(voice_channel());
287 }
288
deadbeef5bd5ca32017-02-10 11:31:50 -0800289 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700290 return rtp_transport_channel(video_channel());
291 }
292
deadbeef5bd5ca32017-02-10 11:31:50 -0800293 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700294 return rtcp_transport_channel(video_channel());
295 }
296
deadbeefcbecd352015-09-23 11:50:27 -0700297 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800298 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800299 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700300 if (!ch) {
301 return nullptr;
302 }
zhihuangb2cdd932017-01-19 16:54:25 -0800303 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700304 }
305
deadbeef5bd5ca32017-02-10 11:31:50 -0800306 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800307 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700308 if (!ch) {
309 return nullptr;
310 }
zhihuangb2cdd932017-01-19 16:54:25 -0800311 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700312 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313};
314
wu@webrtc.org91053e72013-08-10 07:18:04 +0000315class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000316 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000318 enum State {
319 kInit,
320 kFailed,
321 kSucceeded,
322 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000323 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000324
325 // CreateSessionDescriptionObserver implementation.
326 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000327 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000328 state_ = kSucceeded;
329 }
330 virtual void OnFailure(const std::string& error) {
331 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000334 SessionDescriptionInterface* description() { return description_.get(); }
335
336 SessionDescriptionInterface* ReleaseDescription() {
337 return description_.release();
338 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339
wu@webrtc.org91053e72013-08-10 07:18:04 +0000340 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
wu@webrtc.org91053e72013-08-10 07:18:04 +0000342 protected:
343 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344
345 private:
kwibergd1fe2812016-04-27 06:47:29 -0700346 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000347 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348};
349
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800350class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000351 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800352 FakeAudioSource() : sink_(NULL) {}
353 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000354 if (sink_)
355 sink_->OnClose();
356 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000357
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000358 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000359
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800360 const cricket::AudioSource::Sink* sink() const { return sink_; }
361
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000362 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800363 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000364};
365
Henrik Boström87713d02015-08-25 09:53:21 +0200366class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700367 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
368 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 protected:
370 // TODO Investigate why ChannelManager crashes, if it's created
371 // after stun_server.
372 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700373 : media_engine_(new cricket::FakeMediaEngine()),
374 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800375 channel_manager_(new cricket::ChannelManager(
376 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
377 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
378 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700379 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700380 tdesc_factory_(new cricket::TransportDescriptionFactory()),
381 desc_factory_(
382 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
383 tdesc_factory_.get())),
384 pss_(new rtc::PhysicalSocketServer),
385 vss_(new rtc::VirtualSocketServer(pss_.get())),
386 fss_(new rtc::FirewallSocketServer(vss_.get())),
387 ss_scope_(fss_.get()),
388 stun_socket_addr_(
389 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
390 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
391 stun_socket_addr_)),
392 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
393 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000394 cricket::ServerAddresses stun_servers;
395 stun_servers.insert(stun_socket_addr_);
396 allocator_.reset(new cricket::BasicPortAllocator(
397 &network_manager_,
398 stun_servers,
399 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000400 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700401 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 EXPECT_TRUE(channel_manager_->Init());
403 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000404 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
407 void AddInterface(const SocketAddress& addr) {
408 network_manager_.AddInterface(addr);
409 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700410 void RemoveInterface(const SocketAddress& addr) {
411 network_manager_.RemoveInterface(addr);
412 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413
Henrik Boströmd79599d2016-06-01 13:58:50 +0200414 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
415 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
416 // options. When DTLS is enabled a certificate will be used if provided,
417 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800419 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef7914b8c2017-04-21 03:23:33 -0700420 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy,
421 const rtc::CryptoOptions& crypto_options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800423 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
nisseeaabdf62017-05-05 02:23:02 -0700424 session_.reset(new WebRtcSessionForTest(&fake_call_,
425 channel_manager_.get(), cricket::MediaConfig(), &event_log_,
426 rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700427 rtc::Thread::Current(), allocator_.get(), &observer_,
428 std::unique_ptr<cricket::TransportController>(
deadbeef7914b8c2017-04-21 03:23:33 -0700429 new cricket::TransportController(
430 rtc::Thread::Current(), rtc::Thread::Current(),
431 allocator_.get(),
432 /*redetermine_role_on_ice_restart=*/true, crypto_options)),
deadbeef953c2ce2017-01-09 14:53:41 -0800433 std::unique_ptr<FakeSctpTransportFactory>(
434 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700435 session_->SignalDataChannelOpenMessage.connect(
436 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
zhihuang4dfb8ce2016-11-23 10:30:12 -0800438 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
440 observer_.ice_connection_state_);
441 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
442 observer_.ice_gathering_state_);
443
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200444 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800445 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700446 session_->set_metrics_observer(metrics_observer_);
deadbeef7914b8c2017-04-21 03:23:33 -0700447 crypto_options_ = crypto_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 }
449
deadbeefab9b2d12015-10-14 11:33:11 -0700450 void OnDataChannelOpenMessage(const std::string& label,
451 const InternalDataChannelInit& config) {
452 last_data_channel_label_ = label;
453 last_data_channel_config_ = config;
454 }
455
zhihuang4dfb8ce2016-11-23 10:30:12 -0800456 void Init() {
deadbeef7914b8c2017-04-21 03:23:33 -0700457 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
458 rtc::CryptoOptions());
zhihuang4dfb8ce2016-11-23 10:30:12 -0800459 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000460
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 void InitWithBundlePolicy(
462 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800463 configuration_.bundle_policy = bundle_policy;
464 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700465 }
466
467 void InitWithRtcpMuxPolicy(
468 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
469 PeerConnectionInterface::RTCConfiguration configuration;
deadbeef7914b8c2017-04-21 03:23:33 -0700470 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions());
471 }
472
473 void InitWithCryptoOptions(const rtc::CryptoOptions& crypto_options) {
474 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
475 crypto_options);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000476 }
477
Henrik Boström87713d02015-08-25 09:53:21 +0200478 // Successfully init with DTLS; with a certificate generated and supplied or
479 // with a store that generates it for us.
480 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200481 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200482 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800483 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200484 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200485 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200486 cert_generator.reset(new FakeRTCCertificateGenerator());
487 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200488 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700489 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200490 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800491 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700492 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
493 rtc::CryptoOptions());
Henrik Boström87713d02015-08-25 09:53:21 +0200494 }
495
496 // Init with DTLS with a store that will fail to generate a certificate.
497 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200498 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
499 new FakeRTCCertificateGenerator());
500 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800501 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700502 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
503 rtc::CryptoOptions());
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000504 }
505
jbauchcb560652016-08-04 05:20:32 -0700506 void InitWithGcm() {
507 rtc::CryptoOptions crypto_options;
508 crypto_options.enable_gcm_crypto_suites = true;
deadbeef7914b8c2017-04-21 03:23:33 -0700509 InitWithCryptoOptions(crypto_options);
jbauchcb560652016-08-04 05:20:32 -0700510 }
511
deadbeefab9b2d12015-10-14 11:33:11 -0700512 void SendAudioVideoStream1() {
513 send_stream_1_ = true;
514 send_stream_2_ = false;
515 send_audio_ = true;
516 send_video_ = true;
517 }
518
519 void SendAudioVideoStream2() {
520 send_stream_1_ = false;
521 send_stream_2_ = true;
522 send_audio_ = true;
523 send_video_ = true;
524 }
525
526 void SendAudioVideoStream1And2() {
527 send_stream_1_ = true;
528 send_stream_2_ = true;
529 send_audio_ = true;
530 send_video_ = true;
531 }
532
533 void SendNothing() {
534 send_stream_1_ = false;
535 send_stream_2_ = false;
536 send_audio_ = false;
537 send_video_ = false;
538 }
539
540 void SendAudioOnlyStream2() {
541 send_stream_1_ = false;
542 send_stream_2_ = true;
543 send_audio_ = true;
544 send_video_ = false;
545 }
546
547 void SendVideoOnlyStream2() {
548 send_stream_1_ = false;
549 send_stream_2_ = true;
550 send_audio_ = false;
551 send_video_ = true;
552 }
553
554 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
555 if (send_stream_1_ && send_audio_) {
556 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
557 kStream1);
558 }
559 if (send_stream_1_ && send_video_) {
560 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
561 kStream1);
562 }
563 if (send_stream_2_ && send_audio_) {
564 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
565 kStream2);
566 }
567 if (send_stream_2_ && send_video_) {
568 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
569 kStream2);
570 }
571 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
572 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
573 data_channel_->label(),
574 data_channel_->label());
575 }
576 }
577
578 void GetOptionsForOffer(
579 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
580 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800581 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700582
deadbeefc80741f2015-10-22 13:14:45 -0700583 AddStreamsToOptions(session_options);
584 if (rtc_options.offer_to_receive_audio ==
585 RTCOfferAnswerOptions::kUndefined) {
586 session_options->recv_audio =
587 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
588 }
589 if (rtc_options.offer_to_receive_video ==
590 RTCOfferAnswerOptions::kUndefined) {
591 session_options->recv_video =
592 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
593 }
594 session_options->bundle_enabled =
595 session_options->bundle_enabled &&
596 (session_options->has_audio() || session_options->has_video() ||
597 session_options->has_data());
598
deadbeefab9b2d12015-10-14 11:33:11 -0700599 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
600 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700601 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
602 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700603 }
jbauchcb560652016-08-04 05:20:32 -0700604
deadbeef7914b8c2017-04-21 03:23:33 -0700605 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700606 }
607
htaa2a49d92016-03-04 02:51:39 -0800608 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
609 // ParseConstraintsForAnswer is used to set some defaults.
610 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700611
deadbeefc80741f2015-10-22 13:14:45 -0700612 AddStreamsToOptions(session_options);
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
zhihuang9763d562016-08-05 11:14:50 -0700618 if (session_->data_channel_type() != cricket::DCT_RTP) {
619 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700620 }
jbauchcb560652016-08-04 05:20:32 -0700621
deadbeef7914b8c2017-04-21 03:23:33 -0700622 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700623 }
624
625 // Creates a local offer and applies it. Starts ICE.
626 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 // to decide which streams to create.
628 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000629 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 SetLocalDescriptionWithoutError(offer);
631 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
632 observer_.ice_gathering_state_,
633 kIceCandidatesTimeout);
634 }
635
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000636 SessionDescriptionInterface* CreateOffer() {
637 PeerConnectionInterface::RTCOfferAnswerOptions options;
638 options.offer_to_receive_audio =
639 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
640
641 return CreateOffer(options);
642 }
643
wu@webrtc.org91053e72013-08-10 07:18:04 +0000644 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800645 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000646 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000647 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700648 cricket::MediaSessionOptions session_options;
649 GetOptionsForOffer(options, &session_options);
650 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000651 EXPECT_TRUE_WAIT(
652 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000653 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000654 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000655 }
656
657 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800658 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000659 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000660 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800661 cricket::MediaSessionOptions session_options = options;
662 GetOptionsForAnswer(&session_options);
663 // Overwrite recv_audio and recv_video with passed-in values.
664 session_options.recv_video = options.recv_video;
665 session_options.recv_audio = options.recv_audio;
666 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000667 EXPECT_TRUE_WAIT(
668 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000669 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000670 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000671 }
672
htaa2a49d92016-03-04 02:51:39 -0800673 SessionDescriptionInterface* CreateAnswer() {
674 cricket::MediaSessionOptions options;
675 options.recv_video = true;
676 options.recv_audio = true;
677 return CreateAnswer(options);
678 }
679
wu@webrtc.org364f2042013-11-20 21:49:41 +0000680 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 return (session_->voice_channel() != NULL &&
682 session_->video_channel() != NULL);
683 }
684
jbauchcb560652016-08-04 05:20:32 -0700685 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
686 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 ASSERT_TRUE(session_.get() != NULL);
688 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
689 ASSERT_TRUE(content != NULL);
690 const cricket::AudioContentDescription* audio_content =
691 static_cast<const cricket::AudioContentDescription*>(
692 content->description);
693 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700694 if (!gcm_enabled) {
695 ASSERT_EQ(1U, audio_content->cryptos().size());
696 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
697 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
698 audio_content->cryptos()[0].cipher_suite);
699 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
700 audio_content->protocol());
701 } else {
702 // The offer contains 3 possible crypto suites, the answer 1.
703 EXPECT_LE(1U, audio_content->cryptos().size());
704 EXPECT_NE(2U, audio_content->cryptos().size());
705 EXPECT_GE(3U, audio_content->cryptos().size());
706 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
707 ASSERT_EQ("AEAD_AES_256_GCM",
708 audio_content->cryptos()[0].cipher_suite);
709 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
710 audio_content->protocol());
711 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
713 content = cricket::GetFirstVideoContent(sdp);
714 ASSERT_TRUE(content != NULL);
715 const cricket::VideoContentDescription* video_content =
716 static_cast<const cricket::VideoContentDescription*>(
717 content->description);
718 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700719 if (!gcm_enabled) {
720 ASSERT_EQ(1U, video_content->cryptos().size());
721 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
722 video_content->cryptos()[0].cipher_suite);
723 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
724 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
725 video_content->protocol());
726 } else {
727 // The offer contains 3 possible crypto suites, the answer 1.
728 EXPECT_LE(1U, video_content->cryptos().size());
729 EXPECT_NE(2U, video_content->cryptos().size());
730 EXPECT_GE(3U, video_content->cryptos().size());
731 ASSERT_EQ("AEAD_AES_256_GCM",
732 video_content->cryptos()[0].cipher_suite);
733 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
734 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
735 video_content->protocol());
736 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 }
738
739 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
740 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
741 ASSERT_TRUE(content != NULL);
742 const cricket::AudioContentDescription* audio_content =
743 static_cast<const cricket::AudioContentDescription*>(
744 content->description);
745 ASSERT_TRUE(audio_content != NULL);
746 ASSERT_EQ(0U, audio_content->cryptos().size());
747
748 content = cricket::GetFirstVideoContent(sdp);
749 ASSERT_TRUE(content != NULL);
750 const cricket::VideoContentDescription* video_content =
751 static_cast<const cricket::VideoContentDescription*>(
752 content->description);
753 ASSERT_TRUE(video_content != NULL);
754 ASSERT_EQ(0U, video_content->cryptos().size());
755
756 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700757 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700759 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 video_content->protocol());
761 } else {
762 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
763 audio_content->protocol());
764 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
765 video_content->protocol());
766 }
767 }
768
769 // Set the internal fake description factories to do DTLS-SRTP.
770 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000771 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000773 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200774 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800775 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700776 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800777 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
779 }
780
781 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
782 bool expected) {
783 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
784 ASSERT_TRUE(audio != NULL);
785 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 const TransportInfo* video = sdp->GetTransportInfoByName("video");
787 ASSERT_TRUE(video != NULL);
788 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 }
790
791 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000792 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000794 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000795 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000797 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000799 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
800 offer);
htaa2a49d92016-03-04 02:51:39 -0800801 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 // Answer should be NULL as no crypto params in offer.
803 ASSERT_TRUE(answer == NULL);
804 }
805
806 void VerifyAnswerFromCryptoOffer() {
807 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000808 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700810 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
812 ASSERT_TRUE(offer.get() != NULL);
813 VerifyCryptoParams(offer->description());
814 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700815 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 ASSERT_TRUE(answer.get() != NULL);
817 VerifyCryptoParams(answer->description());
818 }
819
deadbeef0ed85b22016-02-23 17:24:52 -0800820 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
821 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800823 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 }
825
826 const cricket::ContentInfos& contents = desc1->contents();
827 cricket::ContentInfos::const_iterator it = contents.begin();
828
829 for (; it != contents.end(); ++it) {
830 const cricket::TransportDescription* transport_desc1 =
831 desc1->GetTransportDescriptionByName(it->name);
832 const cricket::TransportDescription* transport_desc2 =
833 desc2->GetTransportDescriptionByName(it->name);
834 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800835 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 }
837 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
838 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800839 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 }
841 }
deadbeef0ed85b22016-02-23 17:24:52 -0800842 return true;
843 }
844
845 // Compares ufrag/password only for the specified |media_type|.
846 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
847 const cricket::SessionDescription* desc2,
848 cricket::MediaType media_type) {
849 if (desc1->contents().size() != desc2->contents().size()) {
850 return false;
851 }
852
853 const cricket::ContentInfo* cinfo =
854 cricket::GetFirstMediaContent(desc1->contents(), media_type);
855 const cricket::TransportDescription* transport_desc1 =
856 desc1->GetTransportDescriptionByName(cinfo->name);
857 const cricket::TransportDescription* transport_desc2 =
858 desc2->GetTransportDescriptionByName(cinfo->name);
859 if (!transport_desc1 || !transport_desc2) {
860 return false;
861 }
862 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
863 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
864 return false;
865 }
866 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000868
869 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
870 std::string *sdp) {
871 const cricket::SessionDescription* desc = current_desc->description();
872 EXPECT_TRUE(current_desc->ToString(sdp));
873
874 const cricket::ContentInfos& contents = desc->contents();
875 cricket::ContentInfos::const_iterator it = contents.begin();
876 // Replace ufrag and pwd lines with empty strings.
877 for (; it != contents.end(); ++it) {
878 const cricket::TransportDescription* transport_desc =
879 desc->GetTransportDescriptionByName(it->name);
880 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
881 + "\r\n";
882 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
883 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000884 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000885 "", 0,
886 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000887 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000888 "", 0,
889 sdp);
890 }
891 }
892
deadbeef0ed85b22016-02-23 17:24:52 -0800893 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
894 const std::string& ufrag,
895 const std::string& pwd) {
896 cricket::SessionDescription* desc = current_desc->description();
897 for (TransportInfo& transport_info : desc->transport_infos()) {
898 cricket::TransportDescription& transport_desc =
899 transport_info.description;
900 transport_desc.ice_ufrag = ufrag;
901 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000902 }
903 }
904
deadbeef0ed85b22016-02-23 17:24:52 -0800905 // Sets ufrag/pwd for specified |media_type|.
906 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
907 cricket::MediaType media_type,
908 const std::string& ufrag,
909 const std::string& pwd) {
910 cricket::SessionDescription* desc = current_desc->description();
911 const cricket::ContentInfo* cinfo =
912 cricket::GetFirstMediaContent(desc->contents(), media_type);
913 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
914 cricket::TransportDescription* transport_desc =
915 &transport_info->description;
916 transport_desc->ice_ufrag = ufrag;
917 transport_desc->ice_pwd = pwd;
918 }
919
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 // Creates a remote offer and and applies it as a remote description,
921 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700922 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 // to decide which local and remote streams to create.
924 void CreateAndSetRemoteOfferAndLocalAnswer() {
925 SessionDescriptionInterface* offer = CreateRemoteOffer();
926 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800927 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 SetLocalDescriptionWithoutError(answer);
929 }
930 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
931 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700932 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
934 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700935 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 SetLocalDescriptionWithoutError(desc);
937 EXPECT_EQ(expected_state, session_->state());
938 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000939 void SetLocalDescriptionExpectError(const std::string& action,
940 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 SessionDescriptionInterface* desc) {
942 std::string error;
943 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000944 std::string sdp_type = "local ";
945 sdp_type.append(action);
946 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_NE(std::string::npos, error.find(expected_error));
948 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000949 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
950 SessionDescriptionInterface* desc) {
951 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
952 expected_error, desc);
953 }
954 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
955 SessionDescriptionInterface* desc) {
956 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
957 expected_error, desc);
958 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
960 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
961 }
962 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700963 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 SetRemoteDescriptionWithoutError(desc);
965 EXPECT_EQ(expected_state, session_->state());
966 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 void SetRemoteDescriptionExpectError(const std::string& action,
968 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 SessionDescriptionInterface* desc) {
970 std::string error;
971 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000972 std::string sdp_type = "remote ";
973 sdp_type.append(action);
974 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 EXPECT_NE(std::string::npos, error.find(expected_error));
976 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000977 void SetRemoteDescriptionOfferExpectError(
978 const std::string& expected_error, SessionDescriptionInterface* desc) {
979 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
980 expected_error, desc);
981 }
982 void SetRemoteDescriptionPranswerExpectError(
983 const std::string& expected_error, SessionDescriptionInterface* desc) {
984 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
985 expected_error, desc);
986 }
987 void SetRemoteDescriptionAnswerExpectError(
988 const std::string& expected_error, SessionDescriptionInterface* desc) {
989 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
990 expected_error, desc);
991 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
994 SessionDescriptionInterface** nocrypto_answer) {
995 // Create a SDP without Crypto.
996 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000997 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 options.bundle_enabled = true;
999 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1000 ASSERT_TRUE(*offer != NULL);
1001 VerifyCryptoParams((*offer)->description());
1002
1003 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1004 cricket::SEC_DISABLED);
1005 EXPECT_TRUE(*nocrypto_answer != NULL);
1006 }
1007
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001008 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1009 SessionDescriptionInterface** nodtls_answer) {
1010 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001011 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001012 options.bundle_enabled = true;
1013
kwibergd1fe2812016-04-27 06:47:29 -07001014 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001015 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1016
1017 *nodtls_answer =
1018 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1019 EXPECT_TRUE(*nodtls_answer != NULL);
1020 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1021 VerifyCryptoParams((*nodtls_answer)->description());
1022
1023 SetFactoryDtlsSrtp();
1024 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1025 ASSERT_TRUE(*offer != NULL);
1026 VerifyFingerprintStatus((*offer)->description(), true);
1027 VerifyCryptoParams((*offer)->description());
1028 }
1029
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 JsepSessionDescription* CreateRemoteOfferWithVersion(
1031 cricket::MediaSessionOptions options,
1032 cricket::SecurePolicy secure_policy,
1033 const std::string& session_version,
1034 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001035 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 const cricket::SessionDescription* cricket_desc = NULL;
1037 if (current_desc) {
1038 cricket_desc = current_desc->description();
1039 session_id = current_desc->session_id();
1040 }
1041
1042 desc_factory_->set_secure(secure_policy);
1043 JsepSessionDescription* offer(
1044 new JsepSessionDescription(JsepSessionDescription::kOffer));
1045 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1046 session_id, session_version)) {
1047 delete offer;
1048 offer = NULL;
1049 }
1050 return offer;
1051 }
1052 JsepSessionDescription* CreateRemoteOffer(
1053 cricket::MediaSessionOptions options) {
1054 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1055 kSessionVersion, NULL);
1056 }
1057 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001058 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1059 return CreateRemoteOfferWithVersion(
1060 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 }
1062 JsepSessionDescription* CreateRemoteOffer(
1063 cricket::MediaSessionOptions options,
1064 const SessionDescriptionInterface* current_desc) {
1065 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1066 kSessionVersion, current_desc);
1067 }
1068
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001069 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1070 const char* sctp_stream_name, int new_port,
1071 cricket::MediaSessionOptions options) {
1072 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001073 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1074 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001075 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1076 }
1077
1078 // Takes ownership of offer_basis (and deletes it).
1079 JsepSessionDescription* ChangeSDPSctpPort(
1080 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1081 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1082 // SessionDescription from the mutated string.
1083 const char* default_port_str = "5000";
1084 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001086 std::string offer_str;
1087 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001088 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001089 new_port_str, strlen(new_port_str),
1090 &offer_str);
1091 JsepSessionDescription* offer = new JsepSessionDescription(
1092 offer_basis->type());
1093 delete offer_basis;
1094 offer->Initialize(offer_str, NULL);
1095 return offer;
1096 }
1097
deadbeefab9b2d12015-10-14 11:33:11 -07001098 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 // before this function to decide which streams to create.
1100 JsepSessionDescription* CreateRemoteOffer() {
1101 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001102 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 return CreateRemoteOffer(options, session_->remote_description());
1104 }
1105
1106 JsepSessionDescription* CreateRemoteAnswer(
1107 const SessionDescriptionInterface* offer,
1108 cricket::MediaSessionOptions options,
1109 cricket::SecurePolicy policy) {
1110 desc_factory_->set_secure(policy);
1111 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001112 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 JsepSessionDescription* answer(
1114 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1115 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1116 options, NULL),
1117 session_id, kSessionVersion)) {
1118 delete answer;
1119 answer = NULL;
1120 }
1121 return answer;
1122 }
1123
1124 JsepSessionDescription* CreateRemoteAnswer(
1125 const SessionDescriptionInterface* offer,
1126 cricket::MediaSessionOptions options) {
1127 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1128 }
1129
deadbeefab9b2d12015-10-14 11:33:11 -07001130 // Creates an answer session description.
1131 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 // to decide which streams to create.
1133 JsepSessionDescription* CreateRemoteAnswer(
1134 const SessionDescriptionInterface* offer) {
1135 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001136 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1138 }
1139
1140 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001141 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001142 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001143 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001144
1145 PeerConnectionInterface::RTCOfferAnswerOptions options;
1146 options.use_rtp_mux = bundle;
1147
1148 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1150 // and answer.
1151 SetLocalDescriptionWithoutError(offer);
1152
kwibergd1fe2812016-04-27 06:47:29 -07001153 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001154 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 std::string sdp;
1156 EXPECT_TRUE(answer->ToString(&sdp));
1157
1158 size_t expected_candidate_num = 2;
1159 if (!rtcp_mux) {
1160 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1161 // for rtp and rtcp.
1162 expected_candidate_num = 4;
1163 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 const std::string kRtcpMux = "a=rtcp-mux";
1165 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001166 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 kXRtcpMux.c_str(), kXRtcpMux.length(),
1168 &sdp);
1169 }
1170
1171 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1172 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173
1174 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001175 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1177 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001178 if (bundle) {
1179 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1180 } else {
1181 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 }
1183 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184
zhihuang3a334652016-05-05 18:37:49 -07001185 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1186 const std::string& codec_name) {
1187 for (const auto& content : desc->description()->contents()) {
1188 if (static_cast<cricket::MediaContentDescription*>(content.description)
1189 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1190 const auto* mdesc =
1191 static_cast<cricket::VideoContentDescription*>(content.description);
1192 for (const auto& codec : mdesc->codecs()) {
1193 if (codec.name == codec_name) {
1194 return true;
1195 }
1196 }
1197 }
1198 }
1199 return false;
1200 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001201 // Helper class to configure loopback network and verify Best
1202 // Connection using right IP protocol for TestLoopbackCall
1203 // method. LoopbackNetworkManager applies firewall rules to block
1204 // all ping traffic once ICE completed, and remove them to observe
1205 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1206 // verifies the best connection is using the right IP protocol after
1207 // initial ICE convergences.
1208
1209 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001210 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001211 LoopbackNetworkConfiguration()
1212 : test_ipv6_network_(false),
1213 test_extra_ipv4_network_(false),
1214 best_connection_after_initial_ice_converged_(1, 0) {}
1215
1216 // Used to track the expected best connection count in each IP protocol.
1217 struct ExpectedBestConnection {
1218 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1219 : ipv4_count_(ipv4_count),
1220 ipv6_count_(ipv6_count) {}
1221
1222 int ipv4_count_;
1223 int ipv6_count_;
1224 };
1225
1226 bool test_ipv6_network_;
1227 bool test_extra_ipv4_network_;
1228 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1229
1230 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001231 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001232 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1233 }
1234
1235 private:
jbauchac8869e2015-07-03 01:36:14 -07001236 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001237 const ExpectedBestConnection& expected) const {
1238 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001239 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1240 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001241 expected.ipv4_count_);
1242 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001243 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1244 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001245 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001246 // This is used in the loopback call so there is only single host to host
1247 // candidate pair.
1248 EXPECT_EQ(metrics_observer->GetEnumCounter(
1249 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1250 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001251 0);
1252 EXPECT_EQ(metrics_observer->GetEnumCounter(
1253 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1254 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001255 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001256 }
1257 };
1258
1259 class LoopbackNetworkManager {
1260 public:
1261 LoopbackNetworkManager(WebRtcSessionTest* session,
1262 const LoopbackNetworkConfiguration& config)
1263 : config_(config) {
1264 session->AddInterface(
1265 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1266 if (config_.test_extra_ipv4_network_) {
1267 session->AddInterface(
1268 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1269 }
1270 if (config_.test_ipv6_network_) {
1271 session->AddInterface(
1272 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1273 }
1274 }
1275
1276 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1277 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1278 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1279 if (config_.test_extra_ipv4_network_) {
1280 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1281 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1282 }
1283 if (config_.test_ipv6_network_) {
1284 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1285 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1286 }
1287 }
1288
1289 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1290
1291 private:
1292 LoopbackNetworkConfiguration config_;
1293 };
1294
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 // The method sets up a call from the session to itself, in a loopback
1296 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001297 // disconnection, and then a permanent disconnection.
1298 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1300 // While running the call, this method also checks if the session goes through
1301 // the correct sequence of ICE states when a connection is established,
1302 // broken, and re-established.
1303 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1305 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001307
stefanc1aeaf02015-10-15 07:26:07 -07001308 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001309 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001310 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001311 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312
1313 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1314 observer_.ice_gathering_state_);
1315 SetLocalDescriptionWithoutError(offer);
1316 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1317 observer_.ice_connection_state_);
1318 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001319 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1321 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001322 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323
1324 std::string sdp;
1325 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001326 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1327 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 ASSERT_TRUE(desc != NULL);
1329 SetRemoteDescriptionWithoutError(desc);
1330
1331 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001332 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001333
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001334 // The ice connection state is "Connected" too briefly to catch in a test.
1335 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001336 observer_.ice_connection_state_, kIceCandidatesTimeout);
1337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338
stefanc1aeaf02015-10-15 07:26:07 -07001339 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1340 LoopbackNetworkManager loopback_network_manager(this, config);
1341 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001342 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 // Adding firewall rule to block ping requests, which should cause
1344 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001345
1346 loopback_network_manager.ApplyFirewallRules(fss_.get());
1347
1348 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1350 observer_.ice_connection_state_,
1351 kIceCandidatesTimeout);
1352
jbauchac8869e2015-07-03 01:36:14 -07001353 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001356 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001358 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001359 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 observer_.ice_connection_state_,
1361 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001362
1363 // Now we block ping requests and wait until the ICE connection transitions
1364 // to the Failed state. This will take at least 30 seconds because it must
1365 // wait for the Port to timeout.
1366 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001367
1368 loopback_network_manager.ApplyFirewallRules(fss_.get());
1369 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001370 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001371 observer_.ice_connection_state_,
1372 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 }
1374
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001375 void TestLoopbackCall() {
1376 LoopbackNetworkConfiguration config;
1377 TestLoopbackCall(config);
1378 }
1379
stefanc1aeaf02015-10-15 07:26:07 -07001380 void TestPacketOptions() {
stefanc1aeaf02015-10-15 07:26:07 -07001381 LoopbackNetworkConfiguration config;
1382 LoopbackNetworkManager loopback_network_manager(this, config);
1383
1384 SetupLoopbackCall();
1385
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001386 // Wait for channel to be ready for sending.
1387 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001388 uint8_t test_packet[15] = {0};
1389 rtc::PacketOptions options;
1390 options.packet_id = 10;
1391 media_engine_->GetVideoChannel(0)
1392 ->SendRtp(test_packet, sizeof(test_packet), options);
1393
1394 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001395 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1396 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001397 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1398 }
1399
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1401 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001402 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1403 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001404
1405 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001406 std::vector<cricket::AudioCodec> codecs =
1407 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 codecs.push_back(kCNCodec1);
1409 codecs.push_back(kCNCodec2);
1410 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001411 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 }
1413
1414 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1415 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001416 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001418 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001419 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1421 if (audio_content_desc->codecs()[i].name == "CN")
1422 return false;
1423 }
1424 return true;
1425 }
1426
deadbeefab9b2d12015-10-14 11:33:11 -07001427 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001428 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001429 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001430 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1431 data_channel_ = DataChannel::Create(
1432 session_.get(), session_->data_channel_type(), "datachannel", dci);
1433 }
1434
1435 void SetLocalDescriptionWithDataChannel() {
1436 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001437 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 SetLocalDescriptionWithoutError(offer);
1439 }
1440
wu@webrtc.org91053e72013-08-10 07:18:04 +00001441 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001442 RTCCertificateGenerationMethod cert_gen_method,
1443 CreateSessionDescriptionRequest::Type type) {
1444 InitWithDtls(cert_gen_method);
1445 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1446 }
1447
1448 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1449 CreateSessionDescriptionRequest::Type type) {
1450 InitWithDtlsIdentityGenFail();
1451 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1452 }
1453
1454 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001455 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001456 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001457 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001458 if (type == CreateSessionDescriptionRequest::kAnswer) {
1459 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001460 std::unique_ptr<JsepSessionDescription> offer(
1461 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001462 ASSERT_TRUE(offer.get() != NULL);
1463 SetRemoteDescriptionWithoutError(offer.release());
1464 }
1465
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001466 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001467 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001468 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001469 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001470 observers[kNumber];
1471 for (int i = 0; i < kNumber; ++i) {
1472 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1473 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001474 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001475 } else {
htaa2a49d92016-03-04 02:51:39 -08001476 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001477 }
1478 }
1479
1480 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1481 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1482 WebRtcSessionCreateSDPObserverForTest::kFailed;
1483
1484 for (int i = 0; i < kNumber; ++i) {
1485 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1486 if (success) {
1487 EXPECT_TRUE(observers[i]->description() != NULL);
1488 } else {
1489 EXPECT_TRUE(observers[i]->description() == NULL);
1490 }
1491 }
1492 }
1493
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001494 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001495 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001496 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001497 turn_server.credentials = credentials;
1498 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001499 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001500 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001501 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001502 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001503 }
1504
skvlad11a9cbf2016-10-07 11:53:05 -07001505 webrtc::RtcEventLogNullImpl event_log_;
deadbeef112b2e92017-02-10 20:13:37 -08001506 // |media_engine_| and |data_engine_| are actually owned by
1507 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 cricket::FakeMediaEngine* media_engine_;
1509 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001510 // Actually owned by session_.
1511 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001512 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001513 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001514 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1515 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1516 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1517 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1518 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001519 rtc::SocketServerScope ss_scope_;
1520 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001521 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001522 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001523 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001524 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001525 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001526 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001527 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 MockIceObserver observer_;
1529 cricket::FakeVideoMediaChannel* video_channel_;
1530 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001531 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001532 // The following flags affect options created for CreateOffer/CreateAnswer.
1533 bool send_stream_1_ = false;
1534 bool send_stream_2_ = false;
1535 bool send_audio_ = false;
1536 bool send_video_ = false;
1537 rtc::scoped_refptr<DataChannel> data_channel_;
1538 // Last values received from data channel creation signal.
1539 std::string last_data_channel_label_;
1540 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001541 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542};
1543
Henrik Boström87713d02015-08-25 09:53:21 +02001544TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1545 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001546 // SDES is disabled when DTLS is on.
1547 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548}
1549
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001550TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001551 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001552 // SDES is required if DTLS is off.
1553 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001554}
1555
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1557 TestSessionCandidatesWithBundleRtcpMux(false, false);
1558}
1559
1560// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1561// with rtcp-mux and/or bundle.
1562TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1563 TestSessionCandidatesWithBundleRtcpMux(false, true);
1564}
1565
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1567 TestSessionCandidatesWithBundleRtcpMux(true, true);
1568}
1569
1570TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001571 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1572 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001573 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001574 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 InitiateCall();
1576 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1577 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1578 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1579}
1580
deadbeeff5f03e82016-06-06 11:16:06 -07001581TEST_F(WebRtcSessionTest, TestStunError) {
1582 rtc::ScopedFakeClock clock;
1583
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001584 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1585 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001586 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001587 rtc::FP_UDP,
1588 rtc::FD_ANY,
1589 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001590 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001591 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001593 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001594 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1595 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1597 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001598 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1599 // warning.
1600 session_->Close();
1601 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602}
1603
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001604TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001605 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001606 SessionDescriptionInterface* offer = NULL;
1607 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1608 std::string unknown_action;
1609 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1610 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1611}
1612
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613// Test creating offers and receive answers and make sure the
1614// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001616 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 const std::string session_id_orig = offer->session_id();
1620 const std::string session_version_orig = offer->session_version();
1621 SetLocalDescriptionWithoutError(offer);
1622
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 SessionDescriptionInterface* answer =
1625 CreateRemoteAnswer(session_->local_description());
1626 SetRemoteDescriptionWithoutError(answer);
1627
1628 video_channel_ = media_engine_->GetVideoChannel(0);
1629 voice_channel_ = media_engine_->GetVoiceChannel(0);
1630
1631 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1632 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1633
1634 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1635 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1636
1637 ASSERT_EQ(1u, video_channel_->send_streams().size());
1638 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1640 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1641
1642 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001643 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001644 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645
1646 // Verify the session id is the same and the session version is
1647 // increased.
1648 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001649 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1650 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651
1652 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001653 EXPECT_EQ(0u, video_channel_->send_streams().size());
1654 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655
deadbeefab9b2d12015-10-14 11:33:11 -07001656 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 answer = CreateRemoteAnswer(session_->local_description());
1658 SetRemoteDescriptionWithoutError(answer);
1659
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 // Make sure the receive streams have not changed.
1661 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1662 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1663 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1664 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1665}
1666
1667// Test receiving offers and creating answers and make sure the
1668// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001669TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001670 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001671 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001672 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001673 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 SetRemoteDescriptionWithoutError(offer);
1675
deadbeefab9b2d12015-10-14 11:33:11 -07001676 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001677 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001678 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 SetLocalDescriptionWithoutError(answer);
1680
1681 const std::string session_id_orig = answer->session_id();
1682 const std::string session_version_orig = answer->session_version();
1683
1684 video_channel_ = media_engine_->GetVideoChannel(0);
1685 voice_channel_ = media_engine_->GetVoiceChannel(0);
1686
htaa2a49d92016-03-04 02:51:39 -08001687 ASSERT_TRUE(video_channel_);
1688 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1690 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1691
1692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1693 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1694
1695 ASSERT_EQ(1u, video_channel_->send_streams().size());
1696 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1697 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1698 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1699
deadbeefab9b2d12015-10-14 11:33:11 -07001700 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001701 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 SetRemoteDescriptionWithoutError(offer);
1703
1704 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001705 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001706 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
1708 // Verify the session id is the same and the session version is
1709 // increased.
1710 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001711 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1712 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 SetLocalDescriptionWithoutError(answer);
1714
1715 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1716 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1717 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1718 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1719 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1720 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1721
1722 // Make sure we have no send streams.
1723 EXPECT_EQ(0u, video_channel_->send_streams().size());
1724 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1725}
1726
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001727TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001728 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001729 media_engine_->set_fail_create_channel(true);
1730
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001731 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001732 ASSERT_TRUE(offer != NULL);
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer.
1735 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001737 ASSERT_TRUE(offer != NULL);
1738 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1739}
1740
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741//
1742// Tests for creating/setting SDP under different SDES/DTLS polices:
1743//
1744// --DTLS off and SDES on
1745// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1746// set local/remote offer/answer with crypto --> success
1747// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1748// failure
1749// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1750// failure
1751// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1752// failure
1753//
1754// --DTLS on and SDES off
1755// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1756// set local/remote offer/answer with DTLS fingerprint --> success
1757// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1758// fingerprint --> failure
1759// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1760// --> failure
1761// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1762// --> failure
1763//
1764// --Encryption disabled: DTLS off and SDES off
1765// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1766// answer without SDES or DTLS --> success
1767// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1768// answer without SDES or DTLS --> success
1769//
1770
1771// Test that we return a failure when applying a remote/local offer that doesn't
1772// have cryptos enabled when DTLS is off.
1773TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001776 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 JsepSessionDescription* offer = CreateRemoteOffer(
1778 options, cricket::SEC_DISABLED);
1779 ASSERT_TRUE(offer != NULL);
1780 VerifyNoCryptoParams(offer->description(), false);
1781 // SetRemoteDescription and SetLocalDescription will take the ownership of
1782 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1785 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789// Test that we return a failure when applying a local answer that doesn't have
1790// cryptos enabled when DTLS is off.
1791TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001792 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 SessionDescriptionInterface* offer = NULL;
1794 SessionDescriptionInterface* answer = NULL;
1795 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1796 // SetRemoteDescription and SetLocalDescription will take the ownership of
1797 // the offer.
1798 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001799 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800}
1801
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802// Test we will return fail when apply an remote answer that doesn't have
1803// crypto enabled when DTLS is off.
1804TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001805 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 SessionDescriptionInterface* offer = NULL;
1807 SessionDescriptionInterface* answer = NULL;
1808 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1809 // SetRemoteDescription and SetLocalDescription will take the ownership of
1810 // the offer.
1811 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813}
1814
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001815// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1816// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001817TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001818 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001819 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 SetFactoryDtlsSrtp();
1821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001822 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 JsepSessionDescription* offer =
1824 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 ASSERT_TRUE(offer != NULL);
1826 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001827 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828
1829 // SetRemoteDescription will take the ownership of the offer.
1830 SetRemoteDescriptionWithoutError(offer);
1831
1832 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001833 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 ASSERT_TRUE(answer != NULL);
1835 VerifyFingerprintStatus(answer->description(), true);
1836 // Check that we don't have an a=crypto line in the answer.
1837 VerifyNoCryptoParams(answer->description(), true);
1838
1839 // Now set the local description, which should work, even without a=crypto.
1840 SetLocalDescriptionWithoutError(answer);
1841}
1842
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001843// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1844// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001845TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001846 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001847 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848 SetFactoryDtlsSrtp();
1849
1850 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001851 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001852 ASSERT_TRUE(offer != NULL);
1853 VerifyFingerprintStatus(offer->description(), true);
1854 // Check that we don't have an a=crypto line in the offer.
1855 VerifyNoCryptoParams(offer->description(), true);
1856
1857 // Now set the local description, which should work, even without a=crypto.
1858 SetLocalDescriptionWithoutError(offer);
1859
1860 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001861 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 JsepSessionDescription* answer =
1863 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1864 ASSERT_TRUE(answer != NULL);
1865 VerifyFingerprintStatus(answer->description(), true);
1866 VerifyNoCryptoParams(answer->description(), true);
1867
1868 // SetRemoteDescription will take the ownership of the answer.
1869 SetRemoteDescriptionWithoutError(answer);
1870}
1871
1872// Test that if we support DTLS and the other side didn't offer a fingerprint,
1873// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001874TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001875 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001877 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 JsepSessionDescription* offer = CreateRemoteOffer(
1880 options, cricket::SEC_REQUIRED);
1881 ASSERT_TRUE(offer != NULL);
1882 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885 // SetRemoteDescription will take the ownership of the offer.
1886 SetRemoteDescriptionOfferExpectError(
1887 kSdpWithoutDtlsFingerprint, offer);
1888
1889 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1890 // SetLocalDescription will take the ownership of the offer.
1891 SetLocalDescriptionOfferExpectError(
1892 kSdpWithoutDtlsFingerprint, offer);
1893}
1894
1895// Test that we return a failure when applying a local answer that doesn't have
1896// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001897TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001898 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899 SessionDescriptionInterface* offer = NULL;
1900 SessionDescriptionInterface* answer = NULL;
1901 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1902
1903 // SetRemoteDescription and SetLocalDescription will take the ownership of
1904 // the offer and answer.
1905 SetRemoteDescriptionWithoutError(offer);
1906 SetLocalDescriptionAnswerExpectError(
1907 kSdpWithoutDtlsFingerprint, answer);
1908}
1909
1910// Test that we return a failure when applying a remote answer that doesn't have
1911// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001912TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001913 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001914 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001916 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001917 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001918 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001920 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921
1922 // SetRemoteDescription and SetLocalDescription will take the ownership of
1923 // the offer and answer.
1924 SetLocalDescriptionWithoutError(offer);
1925 SetRemoteDescriptionAnswerExpectError(
1926 kSdpWithoutDtlsFingerprint, answer);
1927}
1928
1929// Test that we create a local offer without SDES or DTLS and accept a remote
1930// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001931TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001932 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001933 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001934 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001935
1936 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001937 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938 ASSERT_TRUE(offer != NULL);
1939 VerifyFingerprintStatus(offer->description(), false);
1940 // Check that we don't have an a=crypto line in the offer.
1941 VerifyNoCryptoParams(offer->description(), false);
1942
1943 // Now set the local description, which should work, even without a=crypto.
1944 SetLocalDescriptionWithoutError(offer);
1945
1946 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001947 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 JsepSessionDescription* answer =
1949 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1950 ASSERT_TRUE(answer != NULL);
1951 VerifyFingerprintStatus(answer->description(), false);
1952 VerifyNoCryptoParams(answer->description(), false);
1953
1954 // SetRemoteDescription will take the ownership of the answer.
1955 SetRemoteDescriptionWithoutError(answer);
1956}
1957
1958// Test that we create a local answer without SDES or DTLS and accept a remote
1959// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001960TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001962 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963
1964 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001965 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966 JsepSessionDescription* offer =
1967 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1968 ASSERT_TRUE(offer != NULL);
1969 VerifyFingerprintStatus(offer->description(), false);
1970 VerifyNoCryptoParams(offer->description(), false);
1971
1972 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 SetRemoteDescriptionWithoutError(offer);
1974
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001975 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001976 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 ASSERT_TRUE(answer != NULL);
1978 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001979 // Check that we don't have an a=crypto line in the answer.
1980 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001982 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 SetLocalDescriptionWithoutError(answer);
1984}
1985
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001986// Test that we can create and set an answer correctly when different
1987// SSL roles have been negotiated for different transports.
1988// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1989TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1990 SendAudioVideoStream1();
1991 InitWithDtls(GetParam());
1992 SetFactoryDtlsSrtp();
1993
1994 SessionDescriptionInterface* offer = CreateOffer();
1995 SetLocalDescriptionWithoutError(offer);
1996
1997 cricket::MediaSessionOptions options;
1998 options.recv_video = true;
1999
2000 // First, negotiate different SSL roles.
2001 SessionDescriptionInterface* answer =
2002 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2003 TransportInfo* audio_transport_info =
2004 answer->description()->GetTransportInfoByName("audio");
2005 audio_transport_info->description.connection_role =
2006 cricket::CONNECTIONROLE_ACTIVE;
2007 TransportInfo* video_transport_info =
2008 answer->description()->GetTransportInfoByName("video");
2009 video_transport_info->description.connection_role =
2010 cricket::CONNECTIONROLE_PASSIVE;
2011 SetRemoteDescriptionWithoutError(answer);
2012
2013 // Now create an offer in the reverse direction, and ensure the initial
2014 // offerer responds with an answer with correct SSL roles.
2015 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2016 kSessionVersion,
2017 session_->remote_description());
2018 SetRemoteDescriptionWithoutError(offer);
2019
htaa2a49d92016-03-04 02:51:39 -08002020 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002021 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2022 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2023 audio_transport_info->description.connection_role);
2024 video_transport_info = answer->description()->GetTransportInfoByName("video");
2025 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2026 video_transport_info->description.connection_role);
2027 SetLocalDescriptionWithoutError(answer);
2028
2029 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2030 // audio is transferred over to video in the answer that completes the BUNDLE
2031 // negotiation.
2032 options.bundle_enabled = true;
2033 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2034 kSessionVersion,
2035 session_->remote_description());
2036 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002037 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002038 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2039 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2040 audio_transport_info->description.connection_role);
2041 video_transport_info = answer->description()->GetTransportInfoByName("video");
2042 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2043 video_transport_info->description.connection_role);
2044 SetLocalDescriptionWithoutError(answer);
2045}
2046
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 SetLocalDescriptionWithoutError(offer);
2053
2054 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002055 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 SetLocalDescriptionWithoutError(offer2);
2057}
2058
2059TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002060 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 SetRemoteDescriptionWithoutError(offer);
2065
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SetRemoteDescriptionWithoutError(offer2);
2068}
2069
2070TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002075 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002076 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2077 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
2080TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002081 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002082 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002083 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002085 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002086 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002087 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088}
2089
2090TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
htaa2a49d92016-03-04 02:51:39 -08002096 JsepSessionDescription* pranswer =
2097 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002099 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002102 JsepSessionDescription* pranswer2 =
2103 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2105
deadbeefd59daf82015-10-14 15:02:44 -07002106 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
deadbeefab9b2d12015-10-14 11:33:11 -07002108 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002109 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002110 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111}
2112
2113TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002114 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002115 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002117 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118
2119 JsepSessionDescription* pranswer =
2120 CreateRemoteAnswer(session_->local_description());
2121 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2122
2123 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002124 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
deadbeefab9b2d12015-10-14 11:33:11 -07002126 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 JsepSessionDescription* pranswer2 =
2128 CreateRemoteAnswer(session_->local_description());
2129 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2130
2131 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002132 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
deadbeefab9b2d12015-10-14 11:33:11 -07002134 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 SessionDescriptionInterface* answer =
2136 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002137 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138}
2139
2140TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002141 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002142 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002143 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 SessionDescriptionInterface* answer =
2146 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002147 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2148 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149}
2150
2151TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002152 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002153 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002154 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 SessionDescriptionInterface* answer =
2157 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002158 SetRemoteDescriptionAnswerExpectError(
2159 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160}
2161
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002162// Tests that the remote candidates are added and removed successfully.
2163TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002164 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002165 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002167 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
zhihuang38989e52017-03-21 11:04:53 -07002168 "", "", "local", 0, "");
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002169 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2171
deadbeefd59daf82015-10-14 15:02:44 -07002172 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2174
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002177
2178 // Fail since we have not set a remote description.
2179 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180
2181 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2182 session_->local_description());
2183 SetRemoteDescriptionWithoutError(answer);
2184
deadbeefd59daf82015-10-14 15:02:44 -07002185 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2186 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002187 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002188 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2189 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 // Verifying the candidates are copied properly from internal vector.
2192 const SessionDescriptionInterface* remote_desc =
2193 session_->remote_description();
2194 ASSERT_TRUE(remote_desc != NULL);
2195 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2196 const IceCandidateCollection* candidates =
2197 remote_desc->candidates(kMediaContentIndex0);
2198 ASSERT_EQ(2u, candidates->count());
2199 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2200 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2201 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2202 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2203
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002204 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2205 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 candidate.set_component(2);
2207 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002209 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210
2211 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2212 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002213
2214 // Remove candidate1 and candidate2
2215 std::vector<cricket::Candidate> remote_candidates;
2216 remote_candidates.push_back(ice_candidate1.candidate());
2217 remote_candidates.push_back(ice_candidate2.candidate());
2218 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2219 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220}
2221
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002222// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223// that it is retained if the remote session description is changed.
2224TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002225 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 cricket::Candidate candidate1;
2227 candidate1.set_component(1);
2228 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2229 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002230 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 CreateAndSetRemoteOfferAndLocalAnswer();
2232
2233 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2234 const SessionDescriptionInterface* remote_desc =
2235 session_->remote_description();
2236 ASSERT_TRUE(remote_desc != NULL);
2237 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2238 const IceCandidateCollection* candidates =
2239 remote_desc->candidates(kMediaContentIndex0);
2240 ASSERT_EQ(1u, candidates->count());
2241 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2242
2243 // Update the RemoteSessionDescription with a new session description and
2244 // a candidate and check that the new remote session description contains both
2245 // candidates.
2246 SessionDescriptionInterface* offer = CreateRemoteOffer();
2247 cricket::Candidate candidate2;
2248 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2249 candidate2);
2250 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2251 SetRemoteDescriptionWithoutError(offer);
2252
2253 remote_desc = session_->remote_description();
2254 ASSERT_TRUE(remote_desc != NULL);
2255 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2256 candidates = remote_desc->candidates(kMediaContentIndex0);
2257 ASSERT_EQ(2u, candidates->count());
2258 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2259 // Username and password have be updated with the TransportInfo of the
2260 // SessionDescription, won't be equal to the original one.
2261 candidate2.set_username(candidates->at(0)->candidate().username());
2262 candidate2.set_password(candidates->at(0)->candidate().password());
2263 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2264 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2265 // No need to verify the username and password.
2266 candidate1.set_username(candidates->at(1)->candidate().username());
2267 candidate1.set_password(candidates->at(1)->candidate().password());
2268 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2269
2270 // Test that the candidate is ignored if we can add the same candidate again.
2271 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2272}
2273
2274// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002275// that they are retained if the local session description is changed. And if
2276// continual gathering is enabled, they are removed from the local session
2277// description when the network is down.
2278TEST_F(WebRtcSessionTest,
2279 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002282 // Enable Continual Gathering.
2283 cricket::IceConfig config;
2284 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2285 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002286 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 CreateAndSetRemoteOfferAndLocalAnswer();
2288
2289 const SessionDescriptionInterface* local_desc = session_->local_description();
2290 const IceCandidateCollection* candidates =
2291 local_desc->candidates(kMediaContentIndex0);
2292 ASSERT_TRUE(candidates != NULL);
2293 EXPECT_EQ(0u, candidates->count());
2294
deadbeefb60a8192016-08-24 15:15:00 -07002295 // Since we're using continual gathering, we won't get "gathering done".
2296 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297
2298 local_desc = session_->local_description();
2299 candidates = local_desc->candidates(kMediaContentIndex0);
2300 ASSERT_TRUE(candidates != NULL);
2301 EXPECT_LT(0u, candidates->count());
2302 candidates = local_desc->candidates(1);
2303 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002304 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305
2306 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 CreateAndSetRemoteOfferAndLocalAnswer();
2309
2310 local_desc = session_->local_description();
2311 candidates = local_desc->candidates(kMediaContentIndex0);
2312 ASSERT_TRUE(candidates != NULL);
2313 EXPECT_LT(0u, candidates->count());
2314 candidates = local_desc->candidates(1);
2315 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002316 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002317
2318 candidates = local_desc->candidates(kMediaContentIndex0);
2319 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002320 // Bring down the network interface to trigger candidate removals.
2321 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2322 // Verify that all local candidates are removed.
2323 EXPECT_EQ(0, observer_.num_candidates_removed_);
2324 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2325 kIceCandidatesTimeout);
2326 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2327}
2328
2329// Tests that if continual gathering is disabled, local candidates won't be
2330// removed when the interface is turned down.
2331TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2332 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2333 Init();
2334 SendAudioVideoStream1();
2335 CreateAndSetRemoteOfferAndLocalAnswer();
2336
2337 const SessionDescriptionInterface* local_desc = session_->local_description();
2338 const IceCandidateCollection* candidates =
2339 local_desc->candidates(kMediaContentIndex0);
2340 ASSERT_TRUE(candidates != NULL);
2341 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2342
2343 size_t num_local_candidates = candidates->count();
2344 EXPECT_LT(0u, num_local_candidates);
2345 // By default, Continual Gathering is disabled.
2346 // Bring down the network interface.
2347 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2348 // Verify that the local candidates are not removed.
2349 rtc::Thread::Current()->ProcessMessages(1000);
2350 EXPECT_EQ(0, observer_.num_candidates_removed_);
2351 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352}
2353
2354// Test that we can set a remote session description with remote candidates.
2355TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002356 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
2358 cricket::Candidate candidate1;
2359 candidate1.set_component(1);
2360 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2361 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002362 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002363 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
2365 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2366 SetRemoteDescriptionWithoutError(offer);
2367
2368 const SessionDescriptionInterface* remote_desc =
2369 session_->remote_description();
2370 ASSERT_TRUE(remote_desc != NULL);
2371 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2372 const IceCandidateCollection* candidates =
2373 remote_desc->candidates(kMediaContentIndex0);
2374 ASSERT_EQ(1u, candidates->count());
2375 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2376
htaa2a49d92016-03-04 02:51:39 -08002377 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 SetLocalDescriptionWithoutError(answer);
2379}
2380
2381// Test that offers and answers contains ice candidates when Ice candidates have
2382// been gathered.
2383TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002384 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002385 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002386 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 // Ice is started but candidates are not provided until SetLocalDescription
2388 // is called.
2389 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2390 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2391 CreateAndSetRemoteOfferAndLocalAnswer();
2392 // Wait until at least one local candidate has been collected.
2393 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2394 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395
kwibergd1fe2812016-04-27 06:47:29 -07002396 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2399 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
2401 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2402 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002403 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2405 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 SetLocalDescriptionWithoutError(answer);
2407}
2408
2409// Verifies TransportProxy and media channels are created with content names
2410// present in the SessionDescription.
2411TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002412 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002413 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002414 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415
2416 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002417 // "video". Goal is to modify these content names and verify transport
2418 // channels
2419 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 // present in SDP.
2421 std::string sdp;
2422 EXPECT_TRUE(offer->ToString(&sdp));
2423 const std::string kAudioMid = "a=mid:audio";
2424 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2425 const std::string kVideoMid = "a=mid:video";
2426 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2427
2428 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002429 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 kAudioMidReplaceStr.c_str(),
2431 kAudioMidReplaceStr.length(),
2432 &sdp);
2433 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 kVideoMidReplaceStr.c_str(),
2436 kVideoMidReplaceStr.length(),
2437 &sdp);
2438
2439 SessionDescriptionInterface* modified_offer =
2440 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2441
2442 SetRemoteDescriptionWithoutError(modified_offer);
2443
htaa2a49d92016-03-04 02:51:39 -08002444 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 SetLocalDescriptionWithoutError(answer);
2446
deadbeef5bd5ca32017-02-10 11:31:50 -08002447 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002448 session_->voice_rtp_transport_channel();
2449 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002450 EXPECT_EQ(voice_transport_channel->debug_name(),
2451 "audio_content_name " +
2452 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002453 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002454 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002455 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002456 EXPECT_EQ(video_transport_channel->debug_name(),
2457 "video_content_name " +
2458 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2460 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2461}
2462
2463// Test that an offer contains the correct media content descriptions based on
2464// the send streams when no constraints have been set.
2465TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002466 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002467 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 ASSERT_TRUE(offer != NULL);
2470 const cricket::ContentInfo* content =
2471 cricket::GetFirstAudioContent(offer->description());
2472 EXPECT_TRUE(content != NULL);
2473 content = cricket::GetFirstVideoContent(offer->description());
2474 EXPECT_TRUE(content == NULL);
2475}
2476
2477// Test that an offer contains the correct media content descriptions based on
2478// the send streams when no constraints have been set.
2479TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002480 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002482 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002483 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 const cricket::ContentInfo* content =
2486 cricket::GetFirstAudioContent(offer->description());
2487 EXPECT_TRUE(content != NULL);
2488 content = cricket::GetFirstVideoContent(offer->description());
2489 EXPECT_TRUE(content == NULL);
2490
2491 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002492 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002493 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 content = cricket::GetFirstAudioContent(offer->description());
2495 EXPECT_TRUE(content != NULL);
2496 content = cricket::GetFirstVideoContent(offer->description());
2497 EXPECT_TRUE(content != NULL);
2498}
2499
2500// Test that an offer contains no media content descriptions if
2501// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2502TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002503 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002504 PeerConnectionInterface::RTCOfferAnswerOptions options;
2505 options.offer_to_receive_audio = 0;
2506 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
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 only audio media content descriptions if
2519// kOfferToReceiveAudio constraints are set to true.
2520TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002522 PeerConnectionInterface::RTCOfferAnswerOptions options;
2523 options.offer_to_receive_audio =
2524 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2525
kwibergd1fe2812016-04-27 06:47:29 -07002526 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527
2528 const cricket::ContentInfo* content =
2529 cricket::GetFirstAudioContent(offer->description());
2530 EXPECT_TRUE(content != NULL);
2531 content = cricket::GetFirstVideoContent(offer->description());
2532 EXPECT_TRUE(content == NULL);
2533}
2534
2535// Test that an offer contains audio and video media content descriptions if
2536// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2537TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002540 PeerConnectionInterface::RTCOfferAnswerOptions options;
2541 options.offer_to_receive_audio =
2542 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2543 options.offer_to_receive_video =
2544 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2545
kwibergd1fe2812016-04-27 06:47:29 -07002546 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 const cricket::ContentInfo* content =
2549 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002550 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 content = cricket::GetFirstVideoContent(offer->description());
2553 EXPECT_TRUE(content != NULL);
2554
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002555 // Sets constraints to false and verifies that audio/video contents are
2556 // removed.
2557 options.offer_to_receive_audio = 0;
2558 options.offer_to_receive_video = 0;
2559 offer.reset(CreateOffer(options));
2560
2561 content = cricket::GetFirstAudioContent(offer->description());
2562 EXPECT_TRUE(content == NULL);
2563 content = cricket::GetFirstVideoContent(offer->description());
2564 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565}
2566
2567// Test that an answer can not be created if the last remote description is not
2568// an offer.
2569TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002570 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002571 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 SetLocalDescriptionWithoutError(offer);
2573 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2574 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002575 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576}
2577
2578// Test that an answer contains the correct media content descriptions when no
2579// constraints have been set.
2580TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002583 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002585 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 const cricket::ContentInfo* content =
2587 cricket::GetFirstAudioContent(answer->description());
2588 ASSERT_TRUE(content != NULL);
2589 EXPECT_FALSE(content->rejected);
2590
2591 content = cricket::GetFirstVideoContent(answer->description());
2592 ASSERT_TRUE(content != NULL);
2593 EXPECT_FALSE(content->rejected);
2594}
2595
2596// Test that an answer contains the correct media content descriptions when no
2597// constraints have been set and the offer only contain audio.
2598TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002599 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 // Create a remote offer with audio only.
2601 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002602
kwibergd1fe2812016-04-27 06:47:29 -07002603 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2605 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2606
2607 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002608 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 const cricket::ContentInfo* content =
2610 cricket::GetFirstAudioContent(answer->description());
2611 ASSERT_TRUE(content != NULL);
2612 EXPECT_FALSE(content->rejected);
2613
2614 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2615}
2616
2617// Test that an answer contains the correct media content descriptions when no
2618// constraints have been set.
2619TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002620 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002622 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 SetRemoteDescriptionWithoutError(offer.release());
2624 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002625 SendAudioVideoStream1();
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
2638// constraints have been set but no stream is sent.
2639TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
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 and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002642 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 SetRemoteDescriptionWithoutError(offer.release());
2644
htaa2a49d92016-03-04 02:51:39 -08002645 cricket::MediaSessionOptions session_options;
2646 session_options.recv_audio = false;
2647 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002648 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002649 CreateAnswer(session_options));
2650
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 const cricket::ContentInfo* content =
2652 cricket::GetFirstAudioContent(answer->description());
2653 ASSERT_TRUE(content != NULL);
2654 EXPECT_TRUE(content->rejected);
2655
2656 content = cricket::GetFirstVideoContent(answer->description());
2657 ASSERT_TRUE(content != NULL);
2658 EXPECT_TRUE(content->rejected);
2659}
2660
2661// Test that an answer contains the correct media content descriptions when
2662// constraints have been set and streams are sent.
2663TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002664 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002666 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 SetRemoteDescriptionWithoutError(offer.release());
2668
htaa2a49d92016-03-04 02:51:39 -08002669 cricket::MediaSessionOptions options;
2670 options.recv_audio = false;
2671 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672
2673 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002674 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002675 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676
2677 // TODO(perkj): Should the direction be set to SEND_ONLY?
2678 const cricket::ContentInfo* content =
2679 cricket::GetFirstAudioContent(answer->description());
2680 ASSERT_TRUE(content != NULL);
2681 EXPECT_FALSE(content->rejected);
2682
2683 // TODO(perkj): Should the direction be set to SEND_ONLY?
2684 content = cricket::GetFirstVideoContent(answer->description());
2685 ASSERT_TRUE(content != NULL);
2686 EXPECT_FALSE(content->rejected);
2687}
2688
2689TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2690 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002691 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002692 PeerConnectionInterface::RTCOfferAnswerOptions options;
2693 options.offer_to_receive_audio =
2694 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2695 options.voice_activity_detection = false;
2696
kwibergd1fe2812016-04-27 06:47:29 -07002697 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002698
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 const cricket::ContentInfo* content =
2700 cricket::GetFirstAudioContent(offer->description());
2701 EXPECT_TRUE(content != NULL);
2702 EXPECT_TRUE(VerifyNoCNCodecs(content));
2703}
2704
2705TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2706 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002707 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002709 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 SetRemoteDescriptionWithoutError(offer.release());
2711
htaa2a49d92016-03-04 02:51:39 -08002712 cricket::MediaSessionOptions options;
2713 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002714 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 const cricket::ContentInfo* content =
2716 cricket::GetFirstAudioContent(answer->description());
2717 ASSERT_TRUE(content != NULL);
2718 EXPECT_TRUE(VerifyNoCNCodecs(content));
2719}
2720
2721// This test verifies the call setup when remote answer with audio only and
2722// later updates with video.
2723TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002724 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2726 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2727
deadbeefab9b2d12015-10-14 11:33:11 -07002728 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002729 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730
2731 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2733
2734 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2735 // and answer;
2736 SetLocalDescriptionWithoutError(offer);
2737 SetRemoteDescriptionWithoutError(answer);
2738
2739 video_channel_ = media_engine_->GetVideoChannel(0);
2740 voice_channel_ = media_engine_->GetVoiceChannel(0);
2741
2742 ASSERT_TRUE(video_channel_ == NULL);
2743
2744 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2745 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2746 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2747
2748 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 CreateAndSetRemoteOfferAndLocalAnswer();
2751
2752 video_channel_ = media_engine_->GetVideoChannel(0);
2753 voice_channel_ = media_engine_->GetVoiceChannel(0);
2754
2755 ASSERT_TRUE(video_channel_ != NULL);
2756 ASSERT_TRUE(voice_channel_ != NULL);
2757
2758 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2759 ASSERT_EQ(1u, video_channel_->send_streams().size());
2760 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2761 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2762 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2763 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2764 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2765 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2766
2767 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002768 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769 CreateAndSetRemoteOfferAndLocalAnswer();
2770
2771 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2772 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2773 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2774 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2775 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2776}
2777
2778// This test verifies the call setup when remote answer with video only and
2779// later updates with audio.
2780TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2783 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002784 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002785 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786
2787 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002788 options.recv_audio = false;
2789 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2791 offer, options, cricket::SEC_ENABLED);
2792
2793 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2794 // and answer.
2795 SetLocalDescriptionWithoutError(offer);
2796 SetRemoteDescriptionWithoutError(answer);
2797
2798 video_channel_ = media_engine_->GetVideoChannel(0);
2799 voice_channel_ = media_engine_->GetVoiceChannel(0);
2800
2801 ASSERT_TRUE(voice_channel_ == NULL);
2802 ASSERT_TRUE(video_channel_ != NULL);
2803
2804 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2805 ASSERT_EQ(1u, video_channel_->send_streams().size());
2806 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2807
2808 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002809 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 CreateAndSetRemoteOfferAndLocalAnswer();
2811
2812 voice_channel_ = media_engine_->GetVoiceChannel(0);
2813 ASSERT_TRUE(voice_channel_ != NULL);
2814
2815 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2816 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2817 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2818 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2819
2820 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002821 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002822 CreateAndSetRemoteOfferAndLocalAnswer();
2823
2824 video_channel_ = media_engine_->GetVideoChannel(0);
2825 voice_channel_ = media_engine_->GetVoiceChannel(0);
2826
2827 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2828 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2829 ASSERT_EQ(1u, video_channel_->send_streams().size());
2830 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2831}
2832
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002834 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002835 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 VerifyCryptoParams(offer->description());
2838 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002839 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 VerifyCryptoParams(answer->description());
2841}
2842
jbauchcb560652016-08-04 05:20:32 -07002843TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2844 InitWithGcm();
2845 SendAudioVideoStream1();
2846 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2847 VerifyCryptoParams(offer->description(), true);
2848 SetRemoteDescriptionWithoutError(offer.release());
2849 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2850 VerifyCryptoParams(answer->description(), true);
2851}
2852
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002854 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002855 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002856 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002857 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 VerifyNoCryptoParams(offer->description(), false);
2859}
2860
2861TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002862 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 VerifyAnswerFromNonCryptoOffer();
2864}
2865
2866TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002867 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 VerifyAnswerFromCryptoOffer();
2869}
2870
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002871// This test verifies that setLocalDescription fails if
2872// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2873TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002874 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002875 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002876 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002877
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002878 std::string sdp;
2879 RemoveIceUfragPwdLines(offer.get(), &sdp);
2880 SessionDescriptionInterface* modified_offer =
2881 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002882 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002883}
2884
2885// This test verifies that setRemoteDescription fails if
2886// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2887TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002888 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002889 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002890 std::string sdp;
2891 RemoveIceUfragPwdLines(offer.get(), &sdp);
2892 SessionDescriptionInterface* modified_offer =
2893 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002894 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002895}
2896
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002897// This test verifies that setLocalDescription fails if local offer has
2898// too short ice ufrag and pwd strings.
2899TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002900 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002901 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002902 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002903 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2904 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002905 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002906 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002907 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002908
2909 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002910 offer.reset(CreateOffer());
2911 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2912 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002913}
2914
2915// This test verifies that setRemoteDescription fails if remote offer has
2916// too short ice ufrag and pwd strings.
2917TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002918 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002919 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002920 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2921 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002922 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002923 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002924 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002925
deadbeef0ed85b22016-02-23 17:24:52 -08002926 offer.reset(CreateRemoteOffer());
2927 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2928 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002929}
2930
Honghai Zhang04e91462015-12-11 14:26:22 -08002931// Test that if the remote offer indicates the peer requested ICE restart (via
2932// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2933TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002934 Init();
honghaiz503726c2015-07-31 12:37:38 -07002935
2936 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002937 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002938 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002939 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2940 0, "", "", "relay", 0, "");
2941 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2942 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002943 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2944 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002945 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2946
2947 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002948 offer.reset(CreateRemoteOffer());
2949 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002950 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2951 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2952 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002953 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2954 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002955 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2956
2957 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002958 offer.reset(CreateRemoteOffer());
2959 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002960 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2961 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2962 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002963 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2964 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002965 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2966
2967 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002968 offer.reset(CreateRemoteOffer());
2969 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2970 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002971 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2972}
2973
Honghai Zhang04e91462015-12-11 14:26:22 -08002974// Test that if the remote answer indicates the peer requested ICE restart (via
2975// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2976TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2977 Init();
2978 SessionDescriptionInterface* offer = CreateOffer();
2979 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002980
2981 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002982 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002983 answer->set_type(JsepSessionDescription::kPrAnswer);
2984 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002985 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2986 0, "", "", "relay", 0, "");
2987 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2988 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002989 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2990 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002991 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2992
2993 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002994 answer.reset(CreateRemoteAnswer(offer));
2995 answer->set_type(JsepSessionDescription::kPrAnswer);
2996 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002997 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2998 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2999 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003000 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3001 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003002 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3003
3004 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003005 answer.reset(CreateRemoteAnswer(offer));
3006 answer->set_type(JsepSessionDescription::kPrAnswer);
3007 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003008 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3009 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3010 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003011 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3012 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003013 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3014
3015 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003016 answer.reset(CreateRemoteAnswer(offer));
3017 answer->set_type(JsepSessionDescription::kPrAnswer);
3018 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3019 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003020 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3021}
3022
Donald Curtisd4f769d2015-05-28 09:48:21 -07003023// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003024// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003025TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3026 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3027
3028 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003029 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003030
3031 PeerConnectionInterface::RTCOfferAnswerOptions options;
3032 options.use_rtp_mux = true;
3033
3034 SessionDescriptionInterface* offer = CreateRemoteOffer();
3035 SetRemoteDescriptionWithoutError(offer);
3036
htaa2a49d92016-03-04 02:51:39 -08003037 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003038 SetLocalDescriptionWithoutError(answer);
3039
deadbeefcbecd352015-09-23 11:50:27 -07003040 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3041 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003042
deadbeefcbecd352015-09-23 11:50:27 -07003043 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003044 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003045
3046 // Checks if one of the transport channels contains a connection using a given
3047 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003048 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003049 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3050 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003051 for (auto& chan_stat : kv.second.channel_stats) {
3052 for (auto& conn_info : chan_stat.connection_infos) {
3053 if (conn_info.remote_candidate.address().port() == port) {
3054 return true;
3055 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003056 }
3057 }
3058 }
3059 return false;
3060 };
3061
3062 EXPECT_FALSE(connection_with_remote_port(5000));
3063 EXPECT_FALSE(connection_with_remote_port(5001));
3064 EXPECT_FALSE(connection_with_remote_port(6000));
3065
3066 // The way the *_WAIT checks work is they only wait if the condition fails,
3067 // which does not help in the case where state is not changing. This is
3068 // problematic in this test since we want to verify that adding a video
3069 // candidate does _not_ change state. So we interleave candidates and assume
3070 // that messages are executed in the order they were posted.
3071
3072 // First audio candidate.
3073 cricket::Candidate candidate0;
3074 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3075 candidate0.set_component(1);
3076 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003077 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003078 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3079 candidate0);
3080 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3081
3082 // Video candidate.
3083 cricket::Candidate candidate1;
3084 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3085 candidate1.set_component(1);
3086 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003087 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003088 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3089 candidate1);
3090 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3091
3092 // Second audio candidate.
3093 cricket::Candidate candidate2;
3094 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3095 candidate2.set_component(1);
3096 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003097 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003098 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3099 candidate2);
3100 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3101
3102 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3103 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3104
3105 // No need here for a _WAIT check since we are checking that state hasn't
3106 // changed: if this is false we would be doing waits for nothing and if this
3107 // is true then there will be no messages processed anyways.
3108 EXPECT_FALSE(connection_with_remote_port(6000));
3109}
3110
deadbeefcbecd352015-09-23 11:50:27 -07003111// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003112TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3113 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003114 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003115
3116 PeerConnectionInterface::RTCOfferAnswerOptions options;
3117 options.use_rtp_mux = true;
3118
3119 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003121
deadbeefcbecd352015-09-23 11:50:27 -07003122 EXPECT_NE(session_->voice_rtp_transport_channel(),
3123 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
deadbeefab9b2d12015-10-14 11:33:11 -07003125 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003126 SessionDescriptionInterface* answer =
3127 CreateRemoteAnswer(session_->local_description());
3128 SetRemoteDescriptionWithoutError(answer);
3129
deadbeefcbecd352015-09-23 11:50:27 -07003130 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3131 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003132}
3133
deadbeefcbecd352015-09-23 11:50:27 -07003134// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003135TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3136 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003137 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003138
Donald Curtis0e209b02015-03-24 09:29:54 -07003139 PeerConnectionInterface::RTCOfferAnswerOptions options;
3140 options.use_rtp_mux = true;
3141
3142 SessionDescriptionInterface* offer = CreateOffer(options);
3143 SetLocalDescriptionWithoutError(offer);
3144
deadbeefcbecd352015-09-23 11:50:27 -07003145 EXPECT_NE(session_->voice_rtp_transport_channel(),
3146 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003147
deadbeefab9b2d12015-10-14 11:33:11 -07003148 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003149
3150 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003151 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003152 CreateRemoteAnswer(session_->local_description()));
3153 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3154 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3155 JsepSessionDescription* modified_answer =
3156 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3157 modified_answer->Initialize(answer_copy, "1", "1");
3158 SetRemoteDescriptionWithoutError(modified_answer); //
3159
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}
3163
3164// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3165TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3166 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003167 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003168
3169 PeerConnectionInterface::RTCOfferAnswerOptions options;
3170 options.use_rtp_mux = true;
3171
3172 SessionDescriptionInterface* offer = CreateOffer(options);
3173 SetLocalDescriptionWithoutError(offer);
3174
deadbeefcbecd352015-09-23 11:50:27 -07003175 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3176 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003177
deadbeefab9b2d12015-10-14 11:33:11 -07003178 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003179 SessionDescriptionInterface* answer =
3180 CreateRemoteAnswer(session_->local_description());
3181 SetRemoteDescriptionWithoutError(answer);
3182
deadbeefcbecd352015-09-23 11:50:27 -07003183 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3184 session_->video_rtp_transport_channel());
3185}
3186
3187// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3188// audio content in the answer.
3189TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3190 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003191 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003192
3193 PeerConnectionInterface::RTCOfferAnswerOptions options;
3194 options.use_rtp_mux = true;
3195
3196 SessionDescriptionInterface* offer = CreateOffer(options);
3197 SetLocalDescriptionWithoutError(offer);
3198
3199 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3200 session_->video_rtp_transport_channel());
3201
deadbeefab9b2d12015-10-14 11:33:11 -07003202 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003203 cricket::MediaSessionOptions recv_options;
3204 recv_options.recv_audio = false;
3205 recv_options.recv_video = true;
3206 SessionDescriptionInterface* answer =
3207 CreateRemoteAnswer(session_->local_description(), recv_options);
3208 SetRemoteDescriptionWithoutError(answer);
3209
deadbeefd59daf82015-10-14 15:02:44 -07003210 EXPECT_TRUE(nullptr == session_->voice_channel());
3211 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003212
deadbeefd59daf82015-10-14 15:02:44 -07003213 session_->Close();
3214 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3215 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3216 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3217 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003218}
3219
3220// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3221TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3222 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003224
Donald Curtis0e209b02015-03-24 09:29:54 -07003225 PeerConnectionInterface::RTCOfferAnswerOptions options;
3226 options.use_rtp_mux = true;
3227
3228 SessionDescriptionInterface* offer = CreateOffer(options);
3229 SetLocalDescriptionWithoutError(offer);
3230
deadbeefcbecd352015-09-23 11:50:27 -07003231 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3232 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003233
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003235
3236 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003237 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 CreateRemoteAnswer(session_->local_description()));
3239 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3240 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3241 JsepSessionDescription* modified_answer =
3242 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3243 modified_answer->Initialize(answer_copy, "1", "1");
3244 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
deadbeefcbecd352015-09-23 11:50:27 -07003246 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3247 session_->video_rtp_transport_channel());
3248}
3249
3250// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3251TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3252 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003253 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003254
3255 SessionDescriptionInterface* offer = CreateRemoteOffer();
3256 SetRemoteDescriptionWithoutError(offer);
3257
3258 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3259 session_->video_rtp_transport_channel());
3260
deadbeefab9b2d12015-10-14 11:33:11 -07003261 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003262 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003263 SetLocalDescriptionWithoutError(answer);
3264
3265 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3266 session_->video_rtp_transport_channel());
3267}
3268
3269// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3270TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003273
3274 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003275 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003276 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3277 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3278 JsepSessionDescription* modified_offer =
3279 new JsepSessionDescription(JsepSessionDescription::kOffer);
3280 modified_offer->Initialize(offer_copy, "1", "1");
3281
3282 // Expect an error when applying the remote description
3283 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3284 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003285}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286
Peter Thatcher4eddf182015-04-30 10:55:59 -07003287// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003288TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3289 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
Donald Curtis0e209b02015-03-24 09:29:54 -07003292 PeerConnectionInterface::RTCOfferAnswerOptions options;
3293 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294
Donald Curtis0e209b02015-03-24 09:29:54 -07003295 SessionDescriptionInterface* offer = CreateOffer(options);
3296 SetLocalDescriptionWithoutError(offer);
3297
deadbeefcbecd352015-09-23 11:50:27 -07003298 EXPECT_NE(session_->voice_rtp_transport_channel(),
3299 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003300
deadbeefab9b2d12015-10-14 11:33:11 -07003301 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003302 SessionDescriptionInterface* answer =
3303 CreateRemoteAnswer(session_->local_description());
3304 SetRemoteDescriptionWithoutError(answer);
3305
3306 // This should lead to an audio-only call but isn't implemented
3307 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003308 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3309 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003310}
3311
deadbeefcbecd352015-09-23 11:50:27 -07003312// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003313TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3314 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003315 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003316 PeerConnectionInterface::RTCOfferAnswerOptions options;
3317 options.use_rtp_mux = true;
3318
3319 SessionDescriptionInterface* offer = CreateOffer(options);
3320 SetLocalDescriptionWithoutError(offer);
3321
deadbeefcbecd352015-09-23 11:50:27 -07003322 EXPECT_NE(session_->voice_rtp_transport_channel(),
3323 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003324
deadbeefab9b2d12015-10-14 11:33:11 -07003325 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003326
3327 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003328 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003329 CreateRemoteAnswer(session_->local_description()));
3330 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3331 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3332 JsepSessionDescription* modified_answer =
3333 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3334 modified_answer->Initialize(answer_copy, "1", "1");
3335 SetRemoteDescriptionWithoutError(modified_answer); //
3336
deadbeefcbecd352015-09-23 11:50:27 -07003337 EXPECT_NE(session_->voice_rtp_transport_channel(),
3338 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339}
3340
Peter Thatcher4eddf182015-04-30 10:55:59 -07003341// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3342TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3343 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003344 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003345
3346 PeerConnectionInterface::RTCOfferAnswerOptions options;
3347 options.use_rtp_mux = true;
3348
3349 SessionDescriptionInterface* offer = CreateOffer(options);
3350 SetRemoteDescriptionWithoutError(offer);
3351
deadbeefcbecd352015-09-23 11:50:27 -07003352 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3353 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003354}
3355
skvlad6c87a672016-05-17 17:49:52 -07003356// Adding a new channel to a BUNDLE which is already connected should directly
3357// assign the bundle transport to the channel, without first setting a
3358// disconnected non-bundle transport and then replacing it. The application
3359// should not receive any changes in the ICE state.
3360TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3361 LoopbackNetworkConfiguration config;
3362 LoopbackNetworkManager loopback_network_manager(this, config);
3363 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3364 // connected. Disabling either of these two means that we need to wait for the
3365 // answer to find out if more transports are needed.
3366 configuration_.bundle_policy =
3367 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003368 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07003369 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003370
3371 // Negotiate an audio channel with MAX_BUNDLE enabled.
3372 SendAudioOnlyStream2();
3373 SessionDescriptionInterface* offer = CreateOffer();
3374 SetLocalDescriptionWithoutError(offer);
3375 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3376 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3377 std::string sdp;
3378 offer->ToString(&sdp);
3379 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3380 JsepSessionDescription::kAnswer, sdp, nullptr);
3381 ASSERT_TRUE(answer != NULL);
3382 SetRemoteDescriptionWithoutError(answer);
3383
3384 // Wait for the ICE state to stabilize.
3385 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3386 observer_.ice_connection_state_, kIceCandidatesTimeout);
3387 observer_.ice_connection_state_history_.clear();
3388
3389 // Now add a video channel which should be using the same bundle transport.
3390 SendAudioVideoStream2();
3391 offer = CreateOffer();
3392 offer->ToString(&sdp);
3393 SetLocalDescriptionWithoutError(offer);
3394 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3395 sdp, nullptr);
3396 ASSERT_TRUE(answer != NULL);
3397 SetRemoteDescriptionWithoutError(answer);
3398
3399 // Wait for ICE state to stabilize
3400 rtc::Thread::Current()->ProcessMessages(0);
3401 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3402 observer_.ice_connection_state_, kIceCandidatesTimeout);
3403
3404 // No ICE state changes are expected to happen.
3405 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3406}
3407
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3409 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003410 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003411
3412 PeerConnectionInterface::RTCOfferAnswerOptions options;
3413 SessionDescriptionInterface* offer = CreateOffer(options);
3414 SetLocalDescriptionWithoutError(offer);
3415
deadbeefcbecd352015-09-23 11:50:27 -07003416 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3417 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003418
deadbeefab9b2d12015-10-14 11:33:11 -07003419 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003420 SessionDescriptionInterface* answer =
3421 CreateRemoteAnswer(session_->local_description());
3422 SetRemoteDescriptionWithoutError(answer);
3423
deadbeefcbecd352015-09-23 11:50:27 -07003424 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3425 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003426}
3427
3428TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3429 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003430 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003431
3432 PeerConnectionInterface::RTCOfferAnswerOptions options;
3433 SessionDescriptionInterface* offer = CreateOffer(options);
3434 SetLocalDescriptionWithoutError(offer);
3435
deadbeefcbecd352015-09-23 11:50:27 -07003436 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3437 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003438
deadbeefab9b2d12015-10-14 11:33:11 -07003439 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003440 SessionDescriptionInterface* answer =
3441 CreateRemoteAnswer(session_->local_description());
3442 SetRemoteDescriptionWithoutError(answer);
3443
deadbeefcbecd352015-09-23 11:50:27 -07003444 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3445 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003446}
3447
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003448// This test verifies that SetLocalDescription and SetRemoteDescription fails
3449// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3450TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003451 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003452 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003453
3454 PeerConnectionInterface::RTCOfferAnswerOptions options;
3455 options.use_rtp_mux = true;
3456
3457 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003458 std::string offer_str;
3459 offer->ToString(&offer_str);
3460 // Disable rtcp-mux
3461 const std::string rtcp_mux = "rtcp-mux";
3462 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003463 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003464 xrtcp_mux.c_str(), xrtcp_mux.length(),
3465 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003466 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003467 new JsepSessionDescription(JsepSessionDescription::kOffer);
3468 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003469 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003470 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003471 new JsepSessionDescription(JsepSessionDescription::kOffer);
3472 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003473 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003474 // Trying unmodified SDP.
3475 SetLocalDescriptionWithoutError(offer);
3476}
3477
jbauchcb560652016-08-04 05:20:32 -07003478TEST_F(WebRtcSessionTest, SetSetupGcm) {
3479 InitWithGcm();
3480 SendAudioVideoStream1();
3481 CreateAndSetRemoteOfferAndLocalAnswer();
3482}
3483
deadbeefd59daf82015-10-14 15:02:44 -07003484// This test verifies the |initial_offerer| flag when session initiates the
3485// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003487 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003488 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003489 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3491 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003492 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003494 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495}
3496
deadbeefd59daf82015-10-14 15:02:44 -07003497// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003499 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003500 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SessionDescriptionInterface* offer = CreateRemoteOffer();
3502 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003503 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003507 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508}
3509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3511TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003512 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003513 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003514 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003516 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 CreateRemoteAnswer(session_->local_description()));
3518
3519 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3520 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003521 JsepSessionDescription* modified_answer =
3522 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
3524 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3525 answer->session_id(),
3526 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003527 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
wu@webrtc.org4e393072014-04-07 17:04:35 +00003529 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 std::string sdp;
3531 EXPECT_TRUE(answer->ToString(&sdp));
3532 const std::string kAudioMid = "a=mid:audio";
3533 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003534 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 kAudioMidReplaceStr.c_str(),
3536 kAudioMidReplaceStr.length(),
3537 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003538 SessionDescriptionInterface* modified_answer1 =
3539 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003540 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541
wu@webrtc.org4e393072014-04-07 17:04:35 +00003542 // Different media types.
3543 EXPECT_TRUE(answer->ToString(&sdp));
3544 const std::string kAudioMline = "m=audio";
3545 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003546 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003547 kAudioMlineReplaceStr.c_str(),
3548 kAudioMlineReplaceStr.length(),
3549 &sdp);
3550 SessionDescriptionInterface* modified_answer2 =
3551 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3552 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3553
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 SetRemoteDescriptionWithoutError(answer.release());
3555}
3556
3557// Verifying remote offer and local answer have matching m-lines as per
3558// RFC 3264.
3559TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003560 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003561 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SessionDescriptionInterface* offer = CreateRemoteOffer();
3563 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003564 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565
3566 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3567 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003568 JsepSessionDescription* modified_answer =
3569 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570
3571 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3572 answer->session_id(),
3573 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003574 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 SetLocalDescriptionWithoutError(answer);
3576}
3577
3578// This test verifies that WebRtcSession does not start candidate allocation
3579// before SetLocalDescription is called.
3580TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003581 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003582 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 SessionDescriptionInterface* offer = CreateRemoteOffer();
3584 cricket::Candidate candidate;
3585 candidate.set_component(1);
3586 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3587 candidate);
3588 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3589 cricket::Candidate candidate1;
3590 candidate1.set_component(1);
3591 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3592 candidate1);
3593 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3594 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003595 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3596 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597
3598 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003599 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3601 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3602
htaa2a49d92016-03-04 02:51:39 -08003603 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003604 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3606}
3607
3608// This test verifies that crypto parameter is updated in local session
3609// description as per security policy set in MediaSessionDescriptionFactory.
3610TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003611 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003612 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003613 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
3615 // Making sure SetLocalDescription correctly sets crypto value in
3616 // SessionDescription object after de-serialization of sdp string. The value
3617 // will be set as per MediaSessionDescriptionFactory.
3618 std::string offer_str;
3619 offer->ToString(&offer_str);
3620 SessionDescriptionInterface* jsep_offer_str =
3621 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3622 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003623 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3624 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625}
3626
3627// This test verifies the crypto parameter when security is disabled.
3628TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003629 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003632 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633
3634 // Making sure SetLocalDescription correctly sets crypto value in
3635 // SessionDescription object after de-serialization of sdp string. The value
3636 // will be set as per MediaSessionDescriptionFactory.
3637 std::string offer_str;
3638 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003639 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3641 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003642 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3643 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003644}
3645
3646// This test verifies that an answer contains new ufrag and password if an offer
3647// with new ufrag and password is received.
3648TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003651 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003652 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 SetRemoteDescriptionWithoutError(offer.release());
3654
deadbeefab9b2d12015-10-14 11:33:11 -07003655 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003656 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003657 SetLocalDescriptionWithoutError(answer.release());
3658
3659 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003660 for (const cricket::ContentInfo& content :
3661 session_->local_description()->description()->contents()) {
3662 options.transport_options[content.name].ice_restart = true;
3663 }
kwibergd1fe2812016-04-27 06:47:29 -07003664 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003665 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666 SetRemoteDescriptionWithoutError(updated_offer1.release());
3667
kwibergd1fe2812016-04-27 06:47:29 -07003668 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669
deadbeef0ed85b22016-02-23 17:24:52 -08003670 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3671 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672
deadbeef0ed85b22016-02-23 17:24:52 -08003673 // Even a second answer (created before the description is set) should have
3674 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003675 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003676
3677 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3678 session_->local_description()->description()));
3679
3680 SetLocalDescriptionWithoutError(updated_answer2.release());
3681}
3682
3683// This test verifies that an answer contains new ufrag and password if an offer
3684// that changes either the ufrag or password (but not both) is received.
3685// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3686// a=ice-pwd attributes compared to the previous SDP from the peer, it
3687// indicates that ICE is restarting for this media stream."
3688TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3689 Init();
3690 cricket::MediaSessionOptions options;
3691 options.recv_audio = true;
3692 options.recv_video = true;
3693 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003694 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003695 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3696 SetRemoteDescriptionWithoutError(offer.release());
3697
3698 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003699 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003700 SetLocalDescriptionWithoutError(answer.release());
3701
3702 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003703 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003704 CreateRemoteOffer(options, session_->remote_description()));
3705 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3706 "original_password12345");
3707 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3708
kwibergd1fe2812016-04-27 06:47:29 -07003709 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003710 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3711 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003713
3714 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003715 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003716 CreateRemoteOffer(options, session_->remote_description()));
3717 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3718 "modified_password12345");
3719 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3720
kwibergd1fe2812016-04-27 06:47:29 -07003721 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003722 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3723 session_->local_description()->description()));
3724 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003725}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726
wu@webrtc.org91053e72013-08-10 07:18:04 +00003727// This test verifies that an answer contains old ufrag and password if an offer
3728// with old ufrag and password is received.
3729TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003730 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003731 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003732 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003733 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003734 SetRemoteDescriptionWithoutError(offer.release());
3735
deadbeefab9b2d12015-10-14 11:33:11 -07003736 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003737 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003738 SetLocalDescriptionWithoutError(answer.release());
3739
3740 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003741 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003742 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 SetRemoteDescriptionWithoutError(updated_offer2.release());
3744
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
deadbeef0ed85b22016-02-23 17:24:52 -08003747 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3748 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749
3750 SetLocalDescriptionWithoutError(updated_answer2.release());
3751}
3752
deadbeef0ed85b22016-02-23 17:24:52 -08003753// This test verifies that if an offer does an ICE restart on some, but not all
3754// media sections, the answer will change the ufrag/password in the correct
3755// media sections.
3756TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3757 Init();
3758 cricket::MediaSessionOptions options;
3759 options.recv_video = true;
3760 options.recv_audio = true;
3761 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003762 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003763
3764 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3765 "aaaaaaaaaaaaaaaaaaaaaa");
3766 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3767 "bbbbbbbbbbbbbbbbbbbbbb");
3768 SetRemoteDescriptionWithoutError(offer.release());
3769
3770 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003771 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003772 SetLocalDescriptionWithoutError(answer.release());
3773
3774 // Receive an offer with new ufrag and password, but only for the video media
3775 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003776 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003777 CreateRemoteOffer(options, session_->remote_description()));
3778 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3779 "cccccccccccccccccccccc");
3780 SetRemoteDescriptionWithoutError(updated_offer.release());
3781
kwibergd1fe2812016-04-27 06:47:29 -07003782 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003783
3784 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3785 session_->local_description()->description(),
3786 cricket::MEDIA_TYPE_AUDIO));
3787
3788 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3789 session_->local_description()->description(),
3790 cricket::MEDIA_TYPE_VIDEO));
3791
3792 SetLocalDescriptionWithoutError(updated_answer.release());
3793}
3794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003795TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003796 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003797 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003798 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003799 const std::string session_id_orig = offer->session_id();
3800 const std::string session_version_orig = offer->session_version();
3801 SetLocalDescriptionWithoutError(offer);
3802
3803 video_channel_ = media_engine_->GetVideoChannel(0);
3804 video_channel_->set_fail_set_send_codecs(true);
3805
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003806 SessionDescriptionInterface* answer =
3807 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003808 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003809
3810 // Test that after a content error, setting any description will
3811 // result in an error.
3812 video_channel_->set_fail_set_send_codecs(false);
3813 answer = CreateRemoteAnswer(session_->local_description());
3814 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3815 offer = CreateRemoteOffer();
3816 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817}
3818
3819// Runs the loopback call test with BUNDLE and STUN disabled.
3820TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3821 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003822 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003823 cricket::PORTALLOCATOR_DISABLE_STUN |
3824 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825 TestLoopbackCall();
3826}
3827
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003828TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003829 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003830 cricket::PORTALLOCATOR_DISABLE_STUN |
3831 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3832 cricket::PORTALLOCATOR_DISABLE_RELAY);
3833
3834 // best connection is IPv6 since it has higher network preference.
3835 LoopbackNetworkConfiguration config;
3836 config.test_ipv6_network_ = true;
3837 config.best_connection_after_initial_ice_converged_ =
3838 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3839
3840 TestLoopbackCall(config);
3841}
3842
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003843// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003844TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003845 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3846 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003847 TestLoopbackCall();
3848}
3849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003851 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003852 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003853 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003854 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003855 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003856}
3857
Henrik Boström87713d02015-08-25 09:53:21 +02003858TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003859 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003860 options_.disable_sctp_data_channels = false;
3861
Henrik Boström87713d02015-08-25 09:53:21 +02003862 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863
3864 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003865 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3866}
3867
3868// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3869// before and after BUNDLE is negotiated.
3870TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003871 SetFactoryDtlsSrtp();
3872 InitWithDtls(GetParam());
3873
3874 // Initially these fields should be empty.
3875 EXPECT_FALSE(session_->sctp_content_name());
3876 EXPECT_FALSE(session_->sctp_transport_name());
3877
3878 // Create offer with audio/video/data.
3879 // Default bundle policy is "balanced", so data should be using its own
3880 // transport.
3881 SendAudioVideoStream1();
3882 CreateDataChannel();
3883 InitiateCall();
3884 ASSERT_TRUE(session_->sctp_content_name());
3885 ASSERT_TRUE(session_->sctp_transport_name());
3886 EXPECT_EQ("data", *session_->sctp_content_name());
3887 EXPECT_EQ("data", *session_->sctp_transport_name());
3888
3889 // Create answer that finishes BUNDLE negotiation, which means everything
3890 // should be bundled on the first transport (audio).
3891 cricket::MediaSessionOptions answer_options;
3892 answer_options.recv_video = true;
3893 answer_options.bundle_enabled = true;
3894 answer_options.data_channel_type = cricket::DCT_SCTP;
3895 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3896 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3897 ASSERT_TRUE(session_->sctp_content_name());
3898 ASSERT_TRUE(session_->sctp_transport_name());
3899 EXPECT_EQ("data", *session_->sctp_content_name());
3900 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003901}
3902
Henrik Boström87713d02015-08-25 09:53:21 +02003903TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003904 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003905
kwibergd1fe2812016-04-27 06:47:29 -07003906 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003907 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003908 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3909}
3910
Henrik Boström87713d02015-08-25 09:53:21 +02003911TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003912 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003913 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003914
3915 // Create remote offer with SCTP.
3916 cricket::MediaSessionOptions options;
3917 options.data_channel_type = cricket::DCT_SCTP;
3918 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003919 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003920 SetRemoteDescriptionWithoutError(offer);
3921
3922 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003923 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003924 EXPECT_TRUE(answer != NULL);
3925 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3926 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003927}
3928
deadbeef953c2ce2017-01-09 14:53:41 -08003929// Test that if DTLS is disabled, we don't end up with an SctpTransport
3930// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003931TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003932 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003933 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003934
3935 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003936 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3937 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003938}
3939
deadbeef953c2ce2017-01-09 14:53:41 -08003940// Test that if DTLS is enabled, we end up with an SctpTransport created
3941// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003942TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003943 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003944
3945 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003946 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3947 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003948}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003949
deadbeef953c2ce2017-01-09 14:53:41 -08003950// Test that if SCTP is disabled, we don't end up with an SctpTransport
3951// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003952TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003953 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003954 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003955
3956 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003957 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3958 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003959}
3960
Henrik Boström87713d02015-08-25 09:53:21 +02003961TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003962 const int new_send_port = 9998;
3963 const int new_recv_port = 7775;
3964
Henrik Boström87713d02015-08-25 09:53:21 +02003965 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003966 SetFactoryDtlsSrtp();
3967
3968 // By default, don't actually add the codecs to desc_factory_; they don't
3969 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3970 // let the session description get parsed. That'll get the proper codecs
3971 // into the stream.
3972 cricket::MediaSessionOptions options;
3973 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3974 "stream1", new_send_port, options);
3975
3976 // SetRemoteDescription will take the ownership of the offer.
3977 SetRemoteDescriptionWithoutError(offer);
3978
htaa2a49d92016-03-04 02:51:39 -08003979 SessionDescriptionInterface* answer =
3980 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003981 ASSERT_TRUE(answer != NULL);
3982
3983 // Now set the local description, which'll take ownership of the answer.
3984 SetLocalDescriptionWithoutError(answer);
3985
3986 // TEST PLAN: Set the port number to something new, set it in the SDP,
3987 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003988 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003989 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003990 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3991 EXPECT_EQ(
3992 new_recv_port,
3993 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3994 EXPECT_EQ(
3995 new_send_port,
3996 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003997}
3998
deadbeef953c2ce2017-01-09 14:53:41 -08003999// Verifies that when a session's SctpTransport receives an OPEN message,
4000// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004001// config.
4002TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004003 InitWithDtls(GetParam());
4004
4005 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004006 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4007 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004008
deadbeef953c2ce2017-01-09 14:53:41 -08004009 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004010 webrtc::DataChannelInit config;
4011 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004012 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004013 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4014 cricket::ReceiveDataParams params;
4015 params.ssrc = config.id;
4016 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004017 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4018 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004019
deadbeef953c2ce2017-01-09 14:53:41 -08004020 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004021 EXPECT_EQ(config.id, last_data_channel_config_.id);
4022 EXPECT_FALSE(last_data_channel_config_.negotiated);
4023 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4024 last_data_channel_config_.open_handshake_role);
4025}
4026
4027TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004028 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004029 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004030
htaa2a49d92016-03-04 02:51:39 -08004031 configuration_.certificates.push_back(certificate);
4032 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004033 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4034
4035 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4036}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004037
Henrik Boström87713d02015-08-25 09:53:21 +02004038// Verifies that CreateOffer succeeds when CreateOffer is called before async
4039// identity generation is finished (even if a certificate is provided this is
4040// an async op).
4041TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004042 InitWithDtls(GetParam());
4043
Henrik Boströmd8281982015-08-27 10:12:24 +02004044 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004045 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004046 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004047
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004049 VerifyNoCryptoParams(offer->description(), true);
4050 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004051}
4052
4053// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004054// identity generation is finished (even if a certificate is provided this is
4055// an async op).
4056TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004057 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004058 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059
4060 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004061 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004062 std::unique_ptr<JsepSessionDescription> offer(
4063 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004064 ASSERT_TRUE(offer.get() != NULL);
4065 SetRemoteDescriptionWithoutError(offer.release());
4066
kwibergd1fe2812016-04-27 06:47:29 -07004067 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004069 VerifyNoCryptoParams(answer->description(), true);
4070 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004071}
4072
4073// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004074// identity generation is finished (even if a certificate is provided this is
4075// an async op).
4076TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004077 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004078
Henrik Boströmd8281982015-08-27 10:12:24 +02004079 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004080
kwibergd1fe2812016-04-27 06:47:29 -07004081 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004082 EXPECT_TRUE(offer != NULL);
4083}
4084
4085// Verifies that CreateOffer fails when CreateOffer is called after async
4086// identity generation fails.
4087TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004088 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004089
Henrik Boströmd8281982015-08-27 10:12:24 +02004090 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004091
kwibergd1fe2812016-04-27 06:47:29 -07004092 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004093 EXPECT_TRUE(offer == NULL);
4094}
4095
4096// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4097// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004098TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004100 VerifyMultipleAsyncCreateDescription(GetParam(),
4101 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004102}
4103
4104// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4105// before async identity generation fails.
4106TEST_F(WebRtcSessionTest,
4107 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004108 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4109 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004110}
4111
4112// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4113// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004114TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004117 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118}
4119
4120// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4121// before async identity generation fails.
4122TEST_F(WebRtcSessionTest,
4123 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004124 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4125 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004126}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004127
4128// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4129// offer has no SDES crypto but only DTLS fingerprint.
4130TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4131 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004132 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004133 // Create a remote offer with secured transport disabled.
4134 cricket::MediaSessionOptions options;
4135 JsepSessionDescription* offer(CreateRemoteOffer(
4136 options, cricket::SEC_DISABLED));
4137 // Adds a DTLS fingerprint to the remote offer.
4138 cricket::SessionDescription* sdp = offer->description();
4139 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4140 ASSERT_TRUE(audio != NULL);
4141 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4142 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004143 rtc::SSLFingerprint::CreateFromRfc4572(
4144 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004145 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004146 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004147}
4148
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004149TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004150 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004151 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004152 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004153 SessionDescriptionInterface* offer = CreateOffer();
4154
4155 SetLocalDescriptionWithoutError(offer);
4156
4157 voice_channel_ = media_engine_->GetVoiceChannel(0);
4158
4159 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004160 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004161 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004162}
4163
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004164// Tests that we can renegotiate new media content with ICE candidates in the
4165// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004166TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004167 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004168 SetFactoryDtlsSrtp();
4169
deadbeefab9b2d12015-10-14 11:33:11 -07004170 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004171 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004172 SetLocalDescriptionWithoutError(offer);
4173
4174 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4175 SetRemoteDescriptionWithoutError(answer);
4176
4177 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004178 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004179 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4180
4181 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004182 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004183 candidate1.set_component(1);
4184 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4185 candidate1);
4186 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4187 SetRemoteDescriptionWithoutError(offer);
4188
htaa2a49d92016-03-04 02:51:39 -08004189 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004190 SetLocalDescriptionWithoutError(answer);
4191}
4192
4193// Tests that we can renegotiate new media content with ICE candidates separated
4194// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004195TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004196 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004197 SetFactoryDtlsSrtp();
4198
deadbeefab9b2d12015-10-14 11:33:11 -07004199 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004200 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004201 SetLocalDescriptionWithoutError(offer);
4202
4203 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4204 SetRemoteDescriptionWithoutError(answer);
4205
4206 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004207 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004208 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4209 SetRemoteDescriptionWithoutError(offer);
4210
4211 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004212 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004213 candidate1.set_component(1);
4214 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4215 candidate1);
4216 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4217
htaa2a49d92016-03-04 02:51:39 -08004218 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004219 SetLocalDescriptionWithoutError(answer);
4220}
honghaiz7f777492016-02-02 21:54:01 -08004221
zhihuang9763d562016-08-05 11:14:50 -07004222#ifdef HAVE_QUIC
4223TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4224 configuration_.enable_quic = true;
4225 InitWithDtls(GetParam());
4226 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4227 SessionDescriptionInterface* offer = CreateOffer();
4228 ASSERT_TRUE(offer);
4229 ASSERT_TRUE(offer->description());
4230 SetLocalDescriptionWithoutError(offer);
4231 cricket::MediaSessionOptions options;
4232 options.recv_audio = true;
4233 options.recv_video = true;
4234 SessionDescriptionInterface* answer =
4235 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4236 ASSERT_TRUE(answer);
4237 ASSERT_TRUE(answer->description());
4238 SetRemoteDescriptionWithoutError(answer);
4239}
4240#endif // HAVE_QUIC
4241
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004242// Tests that RTX codec is removed from the answer when it isn't supported
4243// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004244TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004245 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004246 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004247 std::string offer_sdp(kSdpWithRtx);
4248
4249 SessionDescriptionInterface* offer =
4250 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4251 EXPECT_TRUE(offer->ToString(&offer_sdp));
4252
4253 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004254 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004255 SetRemoteDescriptionWithoutError(offer);
4256
htaa2a49d92016-03-04 02:51:39 -08004257 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004258 // Answer SDP does not contain the RTX codec.
4259 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004260 SetLocalDescriptionWithoutError(answer);
4261}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004262
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004263// This verifies that the voice channel after bundle has both options from video
4264// and voice channels.
4265TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4266 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004267 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004268
4269 PeerConnectionInterface::RTCOfferAnswerOptions options;
4270 options.use_rtp_mux = true;
4271
4272 SessionDescriptionInterface* offer = CreateOffer(options);
4273 SetLocalDescriptionWithoutError(offer);
4274
4275 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4276 rtc::Socket::Option::OPT_SNDBUF, 4000);
4277
4278 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4279 rtc::Socket::Option::OPT_RCVBUF, 8000);
4280
4281 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004282 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004283 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4284 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4287
deadbeefcbecd352015-09-23 11:50:27 -07004288 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004289 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4290 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004291 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004292 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4293
deadbeefcbecd352015-09-23 11:50:27 -07004294 EXPECT_NE(session_->voice_rtp_transport_channel(),
4295 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004296
deadbeefab9b2d12015-10-14 11:33:11 -07004297 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004298 SessionDescriptionInterface* answer =
4299 CreateRemoteAnswer(session_->local_description());
4300 SetRemoteDescriptionWithoutError(answer);
4301
deadbeefcbecd352015-09-23 11:50:27 -07004302 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4304 EXPECT_EQ(4000, option_val);
4305
deadbeefcbecd352015-09-23 11:50:27 -07004306 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004307 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4308 EXPECT_EQ(8000, option_val);
4309}
4310
tommi0f620f42015-07-09 03:25:02 -07004311// Test creating a session, request multiple offers, destroy the session
4312// and make sure we got success/failure callbacks for all of the requests.
4313// Background: crbug.com/507307
4314TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4315 Init();
4316
4317 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4318 PeerConnectionInterface::RTCOfferAnswerOptions options;
4319 options.offer_to_receive_audio =
4320 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004321 cricket::MediaSessionOptions session_options;
4322 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004323
4324 for (auto& o : observers) {
4325 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004326 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004327 }
4328
4329 session_.reset();
4330
tommi0f620f42015-07-09 03:25:02 -07004331 for (auto& o : observers) {
4332 // We expect to have received a notification now even if the session was
4333 // terminated. The offer creation may or may not have succeeded, but we
4334 // must have received a notification which, so the only invalid state
4335 // is kInit.
4336 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4337 }
4338}
4339
stefanc1aeaf02015-10-15 07:26:07 -07004340TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4341 TestPacketOptions();
4342}
4343
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004344// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4345// currently fails because upon disconnection and reconnection OnIceComplete is
4346// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004347
deadbeefcbecd352015-09-23 11:50:27 -07004348INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4349 WebRtcSessionTest,
4350 testing::Values(ALREADY_GENERATED,
4351 DTLS_IDENTITY_STORE));