blob: 40b979dc9d89a1ed2583ab9f352dbd8dcb000535 [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"
Henrik Kjellandera80c16a2017-07-01 16:48:15 +020018#include "webrtc/base/checks.h"
19#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/ssladapter.h"
25#include "webrtc/base/sslidentity.h"
26#include "webrtc/base/sslstreamadapter.h"
27#include "webrtc/base/stringutils.h"
28#include "webrtc/base/thread.h"
29#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070030#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080031#include "webrtc/media/base/fakemediaengine.h"
32#include "webrtc/media/base/fakevideorenderer.h"
33#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010034#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080035#include "webrtc/media/sctp/sctptransportinternal.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080036#include "webrtc/p2p/base/packettransportinternal.h"
kjellandera96e2d72016-02-04 23:52:28 -080037#include "webrtc/p2p/base/stunserver.h"
38#include "webrtc/p2p/base/teststunserver.h"
39#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080040#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080041#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010042#include "webrtc/pc/channelmanager.h"
43#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080044#include "webrtc/pc/peerconnection.h"
45#include "webrtc/pc/sctputils.h"
46#include "webrtc/pc/test/fakertccertificategenerator.h"
47#include "webrtc/pc/videotrack.h"
48#include "webrtc/pc/webrtcsession.h"
49#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000056using webrtc::CreateSessionDescriptionObserver;
57using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070058using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070059using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070061using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::JsepIceCandidate;
63using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000064using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065using webrtc::PeerConnectionInterface;
66using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070067using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000069using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000070using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000071using webrtc::kCreateChannelFailed;
72using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000074using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000075using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000076using webrtc::kSdpWithoutDtlsFingerprint;
77using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000079using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000080using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000082typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
83
wu@webrtc.org364f2042013-11-20 21:49:41 +000084static const int kClientAddrPort = 0;
85static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000086static const char kClientIPv6AddrHost1[] =
87 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000088static const char kClientAddrHost2[] = "22.22.22.22";
89static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000090static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
91static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000092static const char kTurnUsername[] = "test";
93static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
95static const char kSessionVersion[] = "1";
96
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097// Media index of candidates belonging to the first media content.
98static const int kMediaContentIndex0 = 0;
99static const char kMediaContentName0[] = "audio";
100
101// Media index of candidates belonging to the second media content.
102static const int kMediaContentIndex1 = 1;
103static const char kMediaContentName1[] = "video";
104
deadbeef953c2ce2017-01-09 14:53:41 -0800105static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106static const int kIceCandidatesTimeout = 10000;
107
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000108static const char kFakeDtlsFingerprint[] =
109 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
110 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
111
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000112static const char kTooLongIceUfragPwd[] =
113 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
114 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
115 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
116 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
117
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000118static const char kSdpWithRtx[] =
119 "v=0\r\n"
120 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
121 "s=-\r\n"
122 "t=0 0\r\n"
123 "a=msid-semantic: WMS stream1\r\n"
124 "m=video 9 RTP/SAVPF 0 96\r\n"
125 "c=IN IP4 0.0.0.0\r\n"
126 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
127 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
128 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
129 "a=mid:video\r\n"
130 "a=sendrecv\r\n"
131 "a=rtcp-mux\r\n"
132 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
133 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
134 "a=rtpmap:0 fake_video_codec/90000\r\n"
135 "a=rtpmap:96 rtx/90000\r\n"
136 "a=fmtp:96 apt=0\r\n";
137
deadbeefab9b2d12015-10-14 11:33:11 -0700138static const char kStream1[] = "stream1";
139static const char kVideoTrack1[] = "video1";
140static const char kAudioTrack1[] = "audio1";
141
142static const char kStream2[] = "stream2";
143static const char kVideoTrack2[] = "video2";
144static const char kAudioTrack2[] = "audio2";
145
Henrik Boström87713d02015-08-25 09:53:21 +0200146enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
147
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148class MockIceObserver : public webrtc::IceObserver {
149 public:
150 MockIceObserver()
151 : oncandidatesready_(false),
152 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
153 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
154 }
155
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200156 virtual ~MockIceObserver() = default;
157
zstein6dfd53a2017-03-06 13:49:03 -0800158 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800159 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700161 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 }
perkjdfb769d2016-02-09 03:09:43 -0800163 void OnIceGatheringChange(
164 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 // We can never transition back to "new".
166 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
167 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800168 oncandidatesready_ =
169 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 }
171
172 // Found a new candidate.
jbauch81bf7b02017-03-25 08:31:12 -0700173 void OnIceCandidate(
174 std::unique_ptr<webrtc::IceCandidateInterface> candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000175 switch (candidate->sdp_mline_index()) {
176 case kMediaContentIndex0:
177 mline_0_candidates_.push_back(candidate->candidate());
178 break;
179 case kMediaContentIndex1:
180 mline_1_candidates_.push_back(candidate->candidate());
181 break;
182 default:
nissec80e7412017-01-11 05:56:46 -0800183 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000185
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 // The ICE gathering state should always be Gathering when a candidate is
187 // received (or possibly Completed in the case of the final candidate).
188 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
189 }
190
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700191 // Some local candidates are removed.
192 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700193 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 num_candidates_removed_ += candidates.size();
195 }
196
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 bool oncandidatesready_;
198 std::vector<cricket::Candidate> mline_0_candidates_;
199 std::vector<cricket::Candidate> mline_1_candidates_;
200 PeerConnectionInterface::IceConnectionState ice_connection_state_;
201 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700202 std::vector<PeerConnectionInterface::IceConnectionState>
203 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700204 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205};
206
deadbeef953c2ce2017-01-09 14:53:41 -0800207// Used for tests in this file to verify that WebRtcSession responds to signals
208// from the SctpTransport correctly, and calls Start with the correct
209// local/remote ports.
210class FakeSctpTransport : public cricket::SctpTransportInternal {
211 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800212 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800213 bool Start(int local_port, int remote_port) override {
214 local_port_ = local_port;
215 remote_port_ = remote_port;
216 return true;
217 }
218 bool OpenStream(int sid) override { return true; }
219 bool ResetStream(int sid) override { return true; }
220 bool SendData(const cricket::SendDataParams& params,
221 const rtc::CopyOnWriteBuffer& payload,
222 cricket::SendDataResult* result = nullptr) override {
223 return true;
224 }
225 bool ReadyToSendData() override { return true; }
226 void set_debug_name_for_testing(const char* debug_name) override {}
227
228 int local_port() const { return local_port_; }
229 int remote_port() const { return remote_port_; }
230
231 private:
232 int local_port_ = -1;
233 int remote_port_ = -1;
234};
235
236class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
237 public:
238 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800239 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800240 last_fake_sctp_transport_ = new FakeSctpTransport();
241 return std::unique_ptr<cricket::SctpTransportInternal>(
242 last_fake_sctp_transport_);
243 }
244
245 FakeSctpTransport* last_fake_sctp_transport() {
246 return last_fake_sctp_transport_;
247 }
248
249 private:
250 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
251};
252
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253class WebRtcSessionForTest : public webrtc::WebRtcSession {
254 public:
zhihuang29ff8442016-07-27 11:07:25 -0700255 WebRtcSessionForTest(
nisseeaabdf62017-05-05 02:23:02 -0700256 webrtc::Call* fake_call,
257 cricket::ChannelManager* channel_manager,
258 const cricket::MediaConfig& media_config,
259 webrtc::RtcEventLog* event_log,
zhihuang29ff8442016-07-27 11:07:25 -0700260 rtc::Thread* network_thread,
261 rtc::Thread* worker_thread,
262 rtc::Thread* signaling_thread,
263 cricket::PortAllocator* port_allocator,
264 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800265 std::unique_ptr<cricket::TransportController> transport_controller,
266 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
nisseeaabdf62017-05-05 02:23:02 -0700267 : WebRtcSession(fake_call, channel_manager, media_config, event_log,
danilchape9021a32016-05-17 01:52:02 -0700268 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700269 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700270 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700271 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800272 std::move(transport_controller),
273 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 RegisterIceObserver(ice_observer);
275 }
276 virtual ~WebRtcSessionForTest() {}
277
deadbeefcbecd352015-09-23 11:50:27 -0700278 // Note that these methods are only safe to use if the signaling thread
279 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800280 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700281 return rtp_transport_channel(voice_channel());
282 }
283
deadbeef5bd5ca32017-02-10 11:31:50 -0800284 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700285 return rtcp_transport_channel(voice_channel());
286 }
287
deadbeef5bd5ca32017-02-10 11:31:50 -0800288 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700289 return rtp_transport_channel(video_channel());
290 }
291
deadbeef5bd5ca32017-02-10 11:31:50 -0800292 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700293 return rtcp_transport_channel(video_channel());
294 }
295
deadbeefcbecd352015-09-23 11:50:27 -0700296 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800297 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800298 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700299 if (!ch) {
300 return nullptr;
301 }
zhihuangb2cdd932017-01-19 16:54:25 -0800302 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700303 }
304
deadbeef5bd5ca32017-02-10 11:31:50 -0800305 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800306 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700307 if (!ch) {
308 return nullptr;
309 }
zhihuangb2cdd932017-01-19 16:54:25 -0800310 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700311 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312};
313
wu@webrtc.org91053e72013-08-10 07:18:04 +0000314class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000315 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000317 enum State {
318 kInit,
319 kFailed,
320 kSucceeded,
321 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000322 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000323
324 // CreateSessionDescriptionObserver implementation.
325 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000326 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000327 state_ = kSucceeded;
328 }
329 virtual void OnFailure(const std::string& error) {
330 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000333 SessionDescriptionInterface* description() { return description_.get(); }
334
335 SessionDescriptionInterface* ReleaseDescription() {
336 return description_.release();
337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
wu@webrtc.org91053e72013-08-10 07:18:04 +0000339 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 protected:
342 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343
344 private:
kwibergd1fe2812016-04-27 06:47:29 -0700345 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000346 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347};
348
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800349class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000350 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800351 FakeAudioSource() : sink_(NULL) {}
352 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000353 if (sink_)
354 sink_->OnClose();
355 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000357 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000358
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800359 const cricket::AudioSource::Sink* sink() const { return sink_; }
360
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000361 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800362 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000363};
364
Henrik Boström87713d02015-08-25 09:53:21 +0200365class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700366 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
367 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 protected:
369 // TODO Investigate why ChannelManager crashes, if it's created
370 // after stun_server.
371 WebRtcSessionTest()
deadbeef98e186c2017-05-16 18:00:06 -0700372 : vss_(new rtc::VirtualSocketServer()),
nisse7eaa4ea2017-05-08 05:25:41 -0700373 fss_(new rtc::FirewallSocketServer(vss_.get())),
374 thread_(fss_.get()),
375 media_engine_(new cricket::FakeMediaEngine()),
stefanc1aeaf02015-10-15 07:26:07 -0700376 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800377 channel_manager_(new cricket::ChannelManager(
378 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
379 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
380 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700381 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700382 tdesc_factory_(new cricket::TransportDescriptionFactory()),
383 desc_factory_(
384 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
385 tdesc_factory_.get())),
stefanc1aeaf02015-10-15 07:26:07 -0700386 stun_socket_addr_(
387 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
388 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
389 stun_socket_addr_)),
390 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
391 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000392 cricket::ServerAddresses stun_servers;
393 stun_servers.insert(stun_socket_addr_);
394 allocator_.reset(new cricket::BasicPortAllocator(
395 &network_manager_,
396 stun_servers,
397 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000398 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700399 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 EXPECT_TRUE(channel_manager_->Init());
401 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000402 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 }
404
405 void AddInterface(const SocketAddress& addr) {
406 network_manager_.AddInterface(addr);
407 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700408 void RemoveInterface(const SocketAddress& addr) {
409 network_manager_.RemoveInterface(addr);
410 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411
Henrik Boströmd79599d2016-06-01 13:58:50 +0200412 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
413 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
414 // options. When DTLS is enabled a certificate will be used if provided,
415 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000416 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800417 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef7914b8c2017-04-21 03:23:33 -0700418 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy,
419 const rtc::CryptoOptions& crypto_options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800421 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
nisseeaabdf62017-05-05 02:23:02 -0700422 session_.reset(new WebRtcSessionForTest(&fake_call_,
423 channel_manager_.get(), cricket::MediaConfig(), &event_log_,
424 rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700425 rtc::Thread::Current(), allocator_.get(), &observer_,
426 std::unique_ptr<cricket::TransportController>(
deadbeef7914b8c2017-04-21 03:23:33 -0700427 new cricket::TransportController(
428 rtc::Thread::Current(), rtc::Thread::Current(),
429 allocator_.get(),
430 /*redetermine_role_on_ice_restart=*/true, crypto_options)),
deadbeef953c2ce2017-01-09 14:53:41 -0800431 std::unique_ptr<FakeSctpTransportFactory>(
432 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700433 session_->SignalDataChannelOpenMessage.connect(
434 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
zhihuang4dfb8ce2016-11-23 10:30:12 -0800436 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
438 observer_.ice_connection_state_);
439 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
440 observer_.ice_gathering_state_);
441
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200442 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800443 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700444 session_->set_metrics_observer(metrics_observer_);
deadbeef7914b8c2017-04-21 03:23:33 -0700445 crypto_options_ = crypto_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 }
447
deadbeefab9b2d12015-10-14 11:33:11 -0700448 void OnDataChannelOpenMessage(const std::string& label,
449 const InternalDataChannelInit& config) {
450 last_data_channel_label_ = label;
451 last_data_channel_config_ = config;
452 }
453
zhihuang4dfb8ce2016-11-23 10:30:12 -0800454 void Init() {
deadbeef7914b8c2017-04-21 03:23:33 -0700455 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
456 rtc::CryptoOptions());
zhihuang4dfb8ce2016-11-23 10:30:12 -0800457 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000458
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000459 void InitWithBundlePolicy(
460 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800461 configuration_.bundle_policy = bundle_policy;
462 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700463 }
464
465 void InitWithRtcpMuxPolicy(
466 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
467 PeerConnectionInterface::RTCConfiguration configuration;
deadbeef7914b8c2017-04-21 03:23:33 -0700468 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions());
469 }
470
471 void InitWithCryptoOptions(const rtc::CryptoOptions& crypto_options) {
472 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
473 crypto_options);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000474 }
475
Henrik Boström87713d02015-08-25 09:53:21 +0200476 // Successfully init with DTLS; with a certificate generated and supplied or
477 // with a store that generates it for us.
478 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200479 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200480 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800481 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200482 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200483 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200484 cert_generator.reset(new FakeRTCCertificateGenerator());
485 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200486 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700487 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200488 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800489 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700490 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
491 rtc::CryptoOptions());
Henrik Boström87713d02015-08-25 09:53:21 +0200492 }
493
494 // Init with DTLS with a store that will fail to generate a certificate.
495 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200496 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
497 new FakeRTCCertificateGenerator());
498 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800499 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700500 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
501 rtc::CryptoOptions());
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000502 }
503
jbauchcb560652016-08-04 05:20:32 -0700504 void InitWithGcm() {
505 rtc::CryptoOptions crypto_options;
506 crypto_options.enable_gcm_crypto_suites = true;
deadbeef7914b8c2017-04-21 03:23:33 -0700507 InitWithCryptoOptions(crypto_options);
jbauchcb560652016-08-04 05:20:32 -0700508 }
509
deadbeefab9b2d12015-10-14 11:33:11 -0700510 void SendAudioVideoStream1() {
511 send_stream_1_ = true;
512 send_stream_2_ = false;
513 send_audio_ = true;
514 send_video_ = true;
515 }
516
517 void SendAudioVideoStream2() {
518 send_stream_1_ = false;
519 send_stream_2_ = true;
520 send_audio_ = true;
521 send_video_ = true;
522 }
523
524 void SendAudioVideoStream1And2() {
525 send_stream_1_ = true;
526 send_stream_2_ = true;
527 send_audio_ = true;
528 send_video_ = true;
529 }
530
531 void SendNothing() {
532 send_stream_1_ = false;
533 send_stream_2_ = false;
534 send_audio_ = false;
535 send_video_ = false;
536 }
537
538 void SendAudioOnlyStream2() {
539 send_stream_1_ = false;
540 send_stream_2_ = true;
541 send_audio_ = true;
542 send_video_ = false;
543 }
544
545 void SendVideoOnlyStream2() {
546 send_stream_1_ = false;
547 send_stream_2_ = true;
548 send_audio_ = false;
549 send_video_ = true;
550 }
551
552 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
553 if (send_stream_1_ && send_audio_) {
554 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
555 kStream1);
556 }
557 if (send_stream_1_ && send_video_) {
558 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
559 kStream1);
560 }
561 if (send_stream_2_ && send_audio_) {
562 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
563 kStream2);
564 }
565 if (send_stream_2_ && send_video_) {
566 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
567 kStream2);
568 }
569 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
570 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
571 data_channel_->label(),
572 data_channel_->label());
573 }
574 }
575
576 void GetOptionsForOffer(
577 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
578 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800579 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700580
deadbeefc80741f2015-10-22 13:14:45 -0700581 AddStreamsToOptions(session_options);
582 if (rtc_options.offer_to_receive_audio ==
583 RTCOfferAnswerOptions::kUndefined) {
584 session_options->recv_audio =
585 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
586 }
587 if (rtc_options.offer_to_receive_video ==
588 RTCOfferAnswerOptions::kUndefined) {
589 session_options->recv_video =
590 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
591 }
592 session_options->bundle_enabled =
593 session_options->bundle_enabled &&
594 (session_options->has_audio() || session_options->has_video() ||
595 session_options->has_data());
596
deadbeefab9b2d12015-10-14 11:33:11 -0700597 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
598 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700599 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
600 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700601 }
jbauchcb560652016-08-04 05:20:32 -0700602
deadbeef7914b8c2017-04-21 03:23:33 -0700603 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700604 }
605
htaa2a49d92016-03-04 02:51:39 -0800606 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
607 // ParseConstraintsForAnswer is used to set some defaults.
608 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700609
deadbeefc80741f2015-10-22 13:14:45 -0700610 AddStreamsToOptions(session_options);
611 session_options->bundle_enabled =
612 session_options->bundle_enabled &&
613 (session_options->has_audio() || session_options->has_video() ||
614 session_options->has_data());
615
zhihuang9763d562016-08-05 11:14:50 -0700616 if (session_->data_channel_type() != cricket::DCT_RTP) {
617 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700618 }
jbauchcb560652016-08-04 05:20:32 -0700619
deadbeef7914b8c2017-04-21 03:23:33 -0700620 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700621 }
622
623 // Creates a local offer and applies it. Starts ICE.
624 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 // to decide which streams to create.
626 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000627 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 SetLocalDescriptionWithoutError(offer);
629 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
630 observer_.ice_gathering_state_,
631 kIceCandidatesTimeout);
632 }
633
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000634 SessionDescriptionInterface* CreateOffer() {
635 PeerConnectionInterface::RTCOfferAnswerOptions options;
636 options.offer_to_receive_audio =
637 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
638
639 return CreateOffer(options);
640 }
641
wu@webrtc.org91053e72013-08-10 07:18:04 +0000642 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800643 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000644 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000645 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700646 cricket::MediaSessionOptions session_options;
647 GetOptionsForOffer(options, &session_options);
648 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000649 EXPECT_TRUE_WAIT(
650 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000651 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000652 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000653 }
654
655 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800656 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000657 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000658 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800659 cricket::MediaSessionOptions session_options = options;
660 GetOptionsForAnswer(&session_options);
661 // Overwrite recv_audio and recv_video with passed-in values.
662 session_options.recv_video = options.recv_video;
663 session_options.recv_audio = options.recv_audio;
664 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000665 EXPECT_TRUE_WAIT(
666 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000667 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000668 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000669 }
670
htaa2a49d92016-03-04 02:51:39 -0800671 SessionDescriptionInterface* CreateAnswer() {
672 cricket::MediaSessionOptions options;
673 options.recv_video = true;
674 options.recv_audio = true;
675 return CreateAnswer(options);
676 }
677
wu@webrtc.org364f2042013-11-20 21:49:41 +0000678 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 return (session_->voice_channel() != NULL &&
680 session_->video_channel() != NULL);
681 }
682
jbauchcb560652016-08-04 05:20:32 -0700683 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
684 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 ASSERT_TRUE(session_.get() != NULL);
686 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
687 ASSERT_TRUE(content != NULL);
688 const cricket::AudioContentDescription* audio_content =
689 static_cast<const cricket::AudioContentDescription*>(
690 content->description);
691 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700692 if (!gcm_enabled) {
693 ASSERT_EQ(1U, audio_content->cryptos().size());
694 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
695 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
696 audio_content->cryptos()[0].cipher_suite);
697 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
698 audio_content->protocol());
699 } else {
700 // The offer contains 3 possible crypto suites, the answer 1.
701 EXPECT_LE(1U, audio_content->cryptos().size());
702 EXPECT_NE(2U, audio_content->cryptos().size());
703 EXPECT_GE(3U, audio_content->cryptos().size());
704 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
705 ASSERT_EQ("AEAD_AES_256_GCM",
706 audio_content->cryptos()[0].cipher_suite);
707 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
708 audio_content->protocol());
709 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710
711 content = cricket::GetFirstVideoContent(sdp);
712 ASSERT_TRUE(content != NULL);
713 const cricket::VideoContentDescription* video_content =
714 static_cast<const cricket::VideoContentDescription*>(
715 content->description);
716 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700717 if (!gcm_enabled) {
718 ASSERT_EQ(1U, video_content->cryptos().size());
719 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
720 video_content->cryptos()[0].cipher_suite);
721 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
722 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
723 video_content->protocol());
724 } else {
725 // The offer contains 3 possible crypto suites, the answer 1.
726 EXPECT_LE(1U, video_content->cryptos().size());
727 EXPECT_NE(2U, video_content->cryptos().size());
728 EXPECT_GE(3U, video_content->cryptos().size());
729 ASSERT_EQ("AEAD_AES_256_GCM",
730 video_content->cryptos()[0].cipher_suite);
731 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
732 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
733 video_content->protocol());
734 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 }
736
737 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
738 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
739 ASSERT_TRUE(content != NULL);
740 const cricket::AudioContentDescription* audio_content =
741 static_cast<const cricket::AudioContentDescription*>(
742 content->description);
743 ASSERT_TRUE(audio_content != NULL);
744 ASSERT_EQ(0U, audio_content->cryptos().size());
745
746 content = cricket::GetFirstVideoContent(sdp);
747 ASSERT_TRUE(content != NULL);
748 const cricket::VideoContentDescription* video_content =
749 static_cast<const cricket::VideoContentDescription*>(
750 content->description);
751 ASSERT_TRUE(video_content != NULL);
752 ASSERT_EQ(0U, video_content->cryptos().size());
753
754 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700755 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700757 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 video_content->protocol());
759 } else {
760 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
761 audio_content->protocol());
762 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
763 video_content->protocol());
764 }
765 }
766
767 // Set the internal fake description factories to do DTLS-SRTP.
768 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000769 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000771 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200772 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800773 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700774 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800775 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
777 }
778
779 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
780 bool expected) {
781 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
782 ASSERT_TRUE(audio != NULL);
783 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 const TransportInfo* video = sdp->GetTransportInfoByName("video");
785 ASSERT_TRUE(video != NULL);
786 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 }
788
789 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000790 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000792 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000793 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000795 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000797 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
798 offer);
htaa2a49d92016-03-04 02:51:39 -0800799 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 // Answer should be NULL as no crypto params in offer.
801 ASSERT_TRUE(answer == NULL);
802 }
803
804 void VerifyAnswerFromCryptoOffer() {
805 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000806 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700808 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
810 ASSERT_TRUE(offer.get() != NULL);
811 VerifyCryptoParams(offer->description());
812 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700813 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 ASSERT_TRUE(answer.get() != NULL);
815 VerifyCryptoParams(answer->description());
816 }
817
deadbeef0ed85b22016-02-23 17:24:52 -0800818 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
819 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800821 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 }
823
824 const cricket::ContentInfos& contents = desc1->contents();
825 cricket::ContentInfos::const_iterator it = contents.begin();
826
827 for (; it != contents.end(); ++it) {
828 const cricket::TransportDescription* transport_desc1 =
829 desc1->GetTransportDescriptionByName(it->name);
830 const cricket::TransportDescription* transport_desc2 =
831 desc2->GetTransportDescriptionByName(it->name);
832 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800833 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 }
835 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
836 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800837 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 }
839 }
deadbeef0ed85b22016-02-23 17:24:52 -0800840 return true;
841 }
842
843 // Compares ufrag/password only for the specified |media_type|.
844 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
845 const cricket::SessionDescription* desc2,
846 cricket::MediaType media_type) {
847 if (desc1->contents().size() != desc2->contents().size()) {
848 return false;
849 }
850
851 const cricket::ContentInfo* cinfo =
852 cricket::GetFirstMediaContent(desc1->contents(), media_type);
853 const cricket::TransportDescription* transport_desc1 =
854 desc1->GetTransportDescriptionByName(cinfo->name);
855 const cricket::TransportDescription* transport_desc2 =
856 desc2->GetTransportDescriptionByName(cinfo->name);
857 if (!transport_desc1 || !transport_desc2) {
858 return false;
859 }
860 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
861 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
862 return false;
863 }
864 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000866
867 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
868 std::string *sdp) {
869 const cricket::SessionDescription* desc = current_desc->description();
870 EXPECT_TRUE(current_desc->ToString(sdp));
871
872 const cricket::ContentInfos& contents = desc->contents();
873 cricket::ContentInfos::const_iterator it = contents.begin();
874 // Replace ufrag and pwd lines with empty strings.
875 for (; it != contents.end(); ++it) {
876 const cricket::TransportDescription* transport_desc =
877 desc->GetTransportDescriptionByName(it->name);
878 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
879 + "\r\n";
880 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
881 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000882 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000883 "", 0,
884 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000885 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000886 "", 0,
887 sdp);
888 }
889 }
890
deadbeef0ed85b22016-02-23 17:24:52 -0800891 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
892 const std::string& ufrag,
893 const std::string& pwd) {
894 cricket::SessionDescription* desc = current_desc->description();
895 for (TransportInfo& transport_info : desc->transport_infos()) {
896 cricket::TransportDescription& transport_desc =
897 transport_info.description;
898 transport_desc.ice_ufrag = ufrag;
899 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000900 }
901 }
902
deadbeef0ed85b22016-02-23 17:24:52 -0800903 // Sets ufrag/pwd for specified |media_type|.
904 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
905 cricket::MediaType media_type,
906 const std::string& ufrag,
907 const std::string& pwd) {
908 cricket::SessionDescription* desc = current_desc->description();
909 const cricket::ContentInfo* cinfo =
910 cricket::GetFirstMediaContent(desc->contents(), media_type);
911 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
912 cricket::TransportDescription* transport_desc =
913 &transport_info->description;
914 transport_desc->ice_ufrag = ufrag;
915 transport_desc->ice_pwd = pwd;
916 }
917
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 // Creates a remote offer and and applies it as a remote description,
919 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700920 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 // to decide which local and remote streams to create.
922 void CreateAndSetRemoteOfferAndLocalAnswer() {
923 SessionDescriptionInterface* offer = CreateRemoteOffer();
924 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800925 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 SetLocalDescriptionWithoutError(answer);
927 }
928 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
929 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700930 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 }
932 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700933 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 SetLocalDescriptionWithoutError(desc);
935 EXPECT_EQ(expected_state, session_->state());
936 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000937 void SetLocalDescriptionExpectError(const std::string& action,
938 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 SessionDescriptionInterface* desc) {
940 std::string error;
941 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000942 std::string sdp_type = "local ";
943 sdp_type.append(action);
944 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 EXPECT_NE(std::string::npos, error.find(expected_error));
946 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000947 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
948 SessionDescriptionInterface* desc) {
949 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
950 expected_error, desc);
951 }
952 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
953 SessionDescriptionInterface* desc) {
954 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
955 expected_error, desc);
956 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
958 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
959 }
960 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700961 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 SetRemoteDescriptionWithoutError(desc);
963 EXPECT_EQ(expected_state, session_->state());
964 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000965 void SetRemoteDescriptionExpectError(const std::string& action,
966 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 SessionDescriptionInterface* desc) {
968 std::string error;
969 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000970 std::string sdp_type = "remote ";
971 sdp_type.append(action);
972 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 EXPECT_NE(std::string::npos, error.find(expected_error));
974 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000975 void SetRemoteDescriptionOfferExpectError(
976 const std::string& expected_error, SessionDescriptionInterface* desc) {
977 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
978 expected_error, desc);
979 }
980 void SetRemoteDescriptionPranswerExpectError(
981 const std::string& expected_error, SessionDescriptionInterface* desc) {
982 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
983 expected_error, desc);
984 }
985 void SetRemoteDescriptionAnswerExpectError(
986 const std::string& expected_error, SessionDescriptionInterface* desc) {
987 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
988 expected_error, desc);
989 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990
991 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
992 SessionDescriptionInterface** nocrypto_answer) {
993 // Create a SDP without Crypto.
994 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000995 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 options.bundle_enabled = true;
997 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
998 ASSERT_TRUE(*offer != NULL);
999 VerifyCryptoParams((*offer)->description());
1000
1001 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1002 cricket::SEC_DISABLED);
1003 EXPECT_TRUE(*nocrypto_answer != NULL);
1004 }
1005
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001006 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1007 SessionDescriptionInterface** nodtls_answer) {
1008 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001009 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001010 options.bundle_enabled = true;
1011
kwibergd1fe2812016-04-27 06:47:29 -07001012 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001013 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1014
1015 *nodtls_answer =
1016 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1017 EXPECT_TRUE(*nodtls_answer != NULL);
1018 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1019 VerifyCryptoParams((*nodtls_answer)->description());
1020
1021 SetFactoryDtlsSrtp();
1022 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1023 ASSERT_TRUE(*offer != NULL);
1024 VerifyFingerprintStatus((*offer)->description(), true);
1025 VerifyCryptoParams((*offer)->description());
1026 }
1027
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 JsepSessionDescription* CreateRemoteOfferWithVersion(
1029 cricket::MediaSessionOptions options,
1030 cricket::SecurePolicy secure_policy,
1031 const std::string& session_version,
1032 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001033 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 const cricket::SessionDescription* cricket_desc = NULL;
1035 if (current_desc) {
1036 cricket_desc = current_desc->description();
1037 session_id = current_desc->session_id();
1038 }
1039
1040 desc_factory_->set_secure(secure_policy);
1041 JsepSessionDescription* offer(
1042 new JsepSessionDescription(JsepSessionDescription::kOffer));
1043 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1044 session_id, session_version)) {
1045 delete offer;
1046 offer = NULL;
1047 }
1048 return offer;
1049 }
1050 JsepSessionDescription* CreateRemoteOffer(
1051 cricket::MediaSessionOptions options) {
1052 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1053 kSessionVersion, NULL);
1054 }
1055 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001056 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1057 return CreateRemoteOfferWithVersion(
1058 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 }
1060 JsepSessionDescription* CreateRemoteOffer(
1061 cricket::MediaSessionOptions options,
1062 const SessionDescriptionInterface* current_desc) {
1063 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1064 kSessionVersion, current_desc);
1065 }
1066
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001067 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1068 const char* sctp_stream_name, int new_port,
1069 cricket::MediaSessionOptions options) {
1070 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001071 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1072 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001073 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1074 }
1075
1076 // Takes ownership of offer_basis (and deletes it).
1077 JsepSessionDescription* ChangeSDPSctpPort(
1078 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1079 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1080 // SessionDescription from the mutated string.
1081 const char* default_port_str = "5000";
1082 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001083 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001084 std::string offer_str;
1085 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001087 new_port_str, strlen(new_port_str),
1088 &offer_str);
1089 JsepSessionDescription* offer = new JsepSessionDescription(
1090 offer_basis->type());
1091 delete offer_basis;
1092 offer->Initialize(offer_str, NULL);
1093 return offer;
1094 }
1095
deadbeefab9b2d12015-10-14 11:33:11 -07001096 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 // before this function to decide which streams to create.
1098 JsepSessionDescription* CreateRemoteOffer() {
1099 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001100 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 return CreateRemoteOffer(options, session_->remote_description());
1102 }
1103
1104 JsepSessionDescription* CreateRemoteAnswer(
1105 const SessionDescriptionInterface* offer,
1106 cricket::MediaSessionOptions options,
1107 cricket::SecurePolicy policy) {
1108 desc_factory_->set_secure(policy);
1109 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001110 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 JsepSessionDescription* answer(
1112 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1113 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1114 options, NULL),
1115 session_id, kSessionVersion)) {
1116 delete answer;
1117 answer = NULL;
1118 }
1119 return answer;
1120 }
1121
1122 JsepSessionDescription* CreateRemoteAnswer(
1123 const SessionDescriptionInterface* offer,
1124 cricket::MediaSessionOptions options) {
1125 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1126 }
1127
deadbeefab9b2d12015-10-14 11:33:11 -07001128 // Creates an answer session description.
1129 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 // to decide which streams to create.
1131 JsepSessionDescription* CreateRemoteAnswer(
1132 const SessionDescriptionInterface* offer) {
1133 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001134 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1136 }
1137
1138 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001139 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001140 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001141 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001142
1143 PeerConnectionInterface::RTCOfferAnswerOptions options;
1144 options.use_rtp_mux = bundle;
1145
1146 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1148 // and answer.
1149 SetLocalDescriptionWithoutError(offer);
1150
kwibergd1fe2812016-04-27 06:47:29 -07001151 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001152 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 std::string sdp;
1154 EXPECT_TRUE(answer->ToString(&sdp));
1155
1156 size_t expected_candidate_num = 2;
1157 if (!rtcp_mux) {
1158 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1159 // for rtp and rtcp.
1160 expected_candidate_num = 4;
1161 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162 const std::string kRtcpMux = "a=rtcp-mux";
1163 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001164 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 kXRtcpMux.c_str(), kXRtcpMux.length(),
1166 &sdp);
1167 }
1168
1169 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1170 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171
1172 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001173 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1175 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001176 if (bundle) {
1177 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1178 } else {
1179 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 }
1181 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182
zhihuang3a334652016-05-05 18:37:49 -07001183 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1184 const std::string& codec_name) {
1185 for (const auto& content : desc->description()->contents()) {
1186 if (static_cast<cricket::MediaContentDescription*>(content.description)
1187 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1188 const auto* mdesc =
1189 static_cast<cricket::VideoContentDescription*>(content.description);
1190 for (const auto& codec : mdesc->codecs()) {
1191 if (codec.name == codec_name) {
1192 return true;
1193 }
1194 }
1195 }
1196 }
1197 return false;
1198 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001199 // Helper class to configure loopback network and verify Best
1200 // Connection using right IP protocol for TestLoopbackCall
1201 // method. LoopbackNetworkManager applies firewall rules to block
1202 // all ping traffic once ICE completed, and remove them to observe
1203 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1204 // verifies the best connection is using the right IP protocol after
1205 // initial ICE convergences.
1206
1207 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001208 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001209 LoopbackNetworkConfiguration()
1210 : test_ipv6_network_(false),
1211 test_extra_ipv4_network_(false),
1212 best_connection_after_initial_ice_converged_(1, 0) {}
1213
1214 // Used to track the expected best connection count in each IP protocol.
1215 struct ExpectedBestConnection {
1216 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1217 : ipv4_count_(ipv4_count),
1218 ipv6_count_(ipv6_count) {}
1219
1220 int ipv4_count_;
1221 int ipv6_count_;
1222 };
1223
1224 bool test_ipv6_network_;
1225 bool test_extra_ipv4_network_;
1226 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1227
1228 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001229 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001230 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1231 }
1232
1233 private:
jbauchac8869e2015-07-03 01:36:14 -07001234 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001235 const ExpectedBestConnection& expected) const {
1236 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001237 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1238 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001239 expected.ipv4_count_);
1240 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001241 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1242 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001243 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001244 // This is used in the loopback call so there is only single host to host
1245 // candidate pair.
1246 EXPECT_EQ(metrics_observer->GetEnumCounter(
1247 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1248 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001249 0);
1250 EXPECT_EQ(metrics_observer->GetEnumCounter(
1251 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1252 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001253 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001254 }
1255 };
1256
1257 class LoopbackNetworkManager {
1258 public:
1259 LoopbackNetworkManager(WebRtcSessionTest* session,
1260 const LoopbackNetworkConfiguration& config)
1261 : config_(config) {
1262 session->AddInterface(
1263 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1264 if (config_.test_extra_ipv4_network_) {
1265 session->AddInterface(
1266 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1267 }
1268 if (config_.test_ipv6_network_) {
1269 session->AddInterface(
1270 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1271 }
1272 }
1273
1274 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1275 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1276 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1277 if (config_.test_extra_ipv4_network_) {
1278 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1279 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1280 }
1281 if (config_.test_ipv6_network_) {
1282 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1283 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1284 }
1285 }
1286
1287 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1288
1289 private:
1290 LoopbackNetworkConfiguration config_;
1291 };
1292
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 // The method sets up a call from the session to itself, in a loopback
1294 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001295 // disconnection, and then a permanent disconnection.
1296 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1298 // While running the call, this method also checks if the session goes through
1299 // the correct sequence of ICE states when a connection is established,
1300 // broken, and re-established.
1301 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001302 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1303 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001305
stefanc1aeaf02015-10-15 07:26:07 -07001306 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001307 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001308 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001309 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310
1311 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1312 observer_.ice_gathering_state_);
1313 SetLocalDescriptionWithoutError(offer);
1314 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1315 observer_.ice_connection_state_);
1316 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001317 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1319 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001320 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321
1322 std::string sdp;
1323 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001324 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1325 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 ASSERT_TRUE(desc != NULL);
1327 SetRemoteDescriptionWithoutError(desc);
1328
1329 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001330 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001331
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001332 // The ice connection state is "Connected" too briefly to catch in a test.
1333 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001334 observer_.ice_connection_state_, kIceCandidatesTimeout);
1335 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336
stefanc1aeaf02015-10-15 07:26:07 -07001337 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1338 LoopbackNetworkManager loopback_network_manager(this, config);
1339 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001340 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 // Adding firewall rule to block ping requests, which should cause
1342 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001343
1344 loopback_network_manager.ApplyFirewallRules(fss_.get());
1345
1346 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1348 observer_.ice_connection_state_,
1349 kIceCandidatesTimeout);
1350
jbauchac8869e2015-07-03 01:36:14 -07001351 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001354 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001356 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001357 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 observer_.ice_connection_state_,
1359 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001360
1361 // Now we block ping requests and wait until the ICE connection transitions
1362 // to the Failed state. This will take at least 30 seconds because it must
1363 // wait for the Port to timeout.
1364 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001365
1366 loopback_network_manager.ApplyFirewallRules(fss_.get());
1367 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001368 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001369 observer_.ice_connection_state_,
1370 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 }
1372
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001373 void TestLoopbackCall() {
1374 LoopbackNetworkConfiguration config;
1375 TestLoopbackCall(config);
1376 }
1377
stefanc1aeaf02015-10-15 07:26:07 -07001378 void TestPacketOptions() {
stefanc1aeaf02015-10-15 07:26:07 -07001379 LoopbackNetworkConfiguration config;
1380 LoopbackNetworkManager loopback_network_manager(this, config);
1381
1382 SetupLoopbackCall();
1383
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001384 // Wait for channel to be ready for sending.
1385 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001386 uint8_t test_packet[15] = {0};
1387 rtc::PacketOptions options;
1388 options.packet_id = 10;
1389 media_engine_->GetVideoChannel(0)
1390 ->SendRtp(test_packet, sizeof(test_packet), options);
1391
1392 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001393 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1394 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001395 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1396 }
1397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1399 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001400 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1401 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001402
1403 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001404 std::vector<cricket::AudioCodec> codecs =
1405 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 codecs.push_back(kCNCodec1);
1407 codecs.push_back(kCNCodec2);
1408 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001409 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 }
1411
1412 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1413 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001414 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001416 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001417 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1419 if (audio_content_desc->codecs()[i].name == "CN")
1420 return false;
1421 }
1422 return true;
1423 }
1424
deadbeefab9b2d12015-10-14 11:33:11 -07001425 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001426 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001427 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001428 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1429 data_channel_ = DataChannel::Create(
1430 session_.get(), session_->data_channel_type(), "datachannel", dci);
1431 }
1432
1433 void SetLocalDescriptionWithDataChannel() {
1434 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001435 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 SetLocalDescriptionWithoutError(offer);
1437 }
1438
wu@webrtc.org91053e72013-08-10 07:18:04 +00001439 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001440 RTCCertificateGenerationMethod cert_gen_method,
1441 CreateSessionDescriptionRequest::Type type) {
1442 InitWithDtls(cert_gen_method);
1443 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1444 }
1445
1446 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1447 CreateSessionDescriptionRequest::Type type) {
1448 InitWithDtlsIdentityGenFail();
1449 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1450 }
1451
1452 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001453 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001454 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001455 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001456 if (type == CreateSessionDescriptionRequest::kAnswer) {
1457 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001458 std::unique_ptr<JsepSessionDescription> offer(
1459 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001460 ASSERT_TRUE(offer.get() != NULL);
1461 SetRemoteDescriptionWithoutError(offer.release());
1462 }
1463
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001464 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001465 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001466 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001467 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001468 observers[kNumber];
1469 for (int i = 0; i < kNumber; ++i) {
1470 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1471 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001472 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001473 } else {
htaa2a49d92016-03-04 02:51:39 -08001474 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001475 }
1476 }
1477
1478 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1479 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1480 WebRtcSessionCreateSDPObserverForTest::kFailed;
1481
1482 for (int i = 0; i < kNumber; ++i) {
1483 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1484 if (success) {
1485 EXPECT_TRUE(observers[i]->description() != NULL);
1486 } else {
1487 EXPECT_TRUE(observers[i]->description() == NULL);
1488 }
1489 }
1490 }
1491
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001492 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001493 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001494 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001495 turn_server.credentials = credentials;
1496 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001497 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001498 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001499 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001500 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001501 }
1502
skvlad11a9cbf2016-10-07 11:53:05 -07001503 webrtc::RtcEventLogNullImpl event_log_;
nisse7eaa4ea2017-05-08 05:25:41 -07001504 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1505 std::unique_ptr<rtc::FirewallSocketServer> fss_;
1506 rtc::AutoSocketServerThread thread_;
deadbeef112b2e92017-02-10 20:13:37 -08001507 // |media_engine_| and |data_engine_| are actually owned by
1508 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 cricket::FakeMediaEngine* media_engine_;
1510 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001511 // Actually owned by session_.
1512 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001513 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001514 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001515 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1516 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001517 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001518 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001519 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001520 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001521 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001522 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001523 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001524 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 MockIceObserver observer_;
1526 cricket::FakeVideoMediaChannel* video_channel_;
1527 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001528 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001529 // The following flags affect options created for CreateOffer/CreateAnswer.
1530 bool send_stream_1_ = false;
1531 bool send_stream_2_ = false;
1532 bool send_audio_ = false;
1533 bool send_video_ = false;
1534 rtc::scoped_refptr<DataChannel> data_channel_;
1535 // Last values received from data channel creation signal.
1536 std::string last_data_channel_label_;
1537 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001538 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539};
1540
Henrik Boström87713d02015-08-25 09:53:21 +02001541TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1542 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001543 // SDES is disabled when DTLS is on.
1544 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545}
1546
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001547TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001548 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001549 // SDES is required if DTLS is off.
1550 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001551}
1552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1554 TestSessionCandidatesWithBundleRtcpMux(false, false);
1555}
1556
1557// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1558// with rtcp-mux and/or bundle.
1559TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1560 TestSessionCandidatesWithBundleRtcpMux(false, true);
1561}
1562
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1564 TestSessionCandidatesWithBundleRtcpMux(true, true);
1565}
1566
1567TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001568 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1569 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001570 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001571 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 InitiateCall();
1573 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1574 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1575 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1576}
1577
deadbeeff5f03e82016-06-06 11:16:06 -07001578TEST_F(WebRtcSessionTest, TestStunError) {
1579 rtc::ScopedFakeClock clock;
1580
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001581 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1582 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001583 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001584 rtc::FP_UDP,
1585 rtc::FD_ANY,
1586 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001587 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001588 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001590 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001591 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1592 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1594 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001595 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1596 // warning.
1597 session_->Close();
1598 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599}
1600
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001601TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001602 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001603 SessionDescriptionInterface* offer = NULL;
1604 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1605 std::string unknown_action;
1606 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1607 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1608}
1609
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610// Test creating offers and receive answers and make sure the
1611// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001612TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001613 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001614 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001615 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 const std::string session_id_orig = offer->session_id();
1617 const std::string session_version_orig = offer->session_version();
1618 SetLocalDescriptionWithoutError(offer);
1619
deadbeefab9b2d12015-10-14 11:33:11 -07001620 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 SessionDescriptionInterface* answer =
1622 CreateRemoteAnswer(session_->local_description());
1623 SetRemoteDescriptionWithoutError(answer);
1624
1625 video_channel_ = media_engine_->GetVideoChannel(0);
1626 voice_channel_ = media_engine_->GetVoiceChannel(0);
1627
1628 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1629 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1630
1631 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1632 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1633
1634 ASSERT_EQ(1u, video_channel_->send_streams().size());
1635 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1636 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1637 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1638
1639 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001640 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001641 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642
1643 // Verify the session id is the same and the session version is
1644 // increased.
1645 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001646 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1647 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648
1649 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001650 EXPECT_EQ(0u, video_channel_->send_streams().size());
1651 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652
deadbeefab9b2d12015-10-14 11:33:11 -07001653 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 answer = CreateRemoteAnswer(session_->local_description());
1655 SetRemoteDescriptionWithoutError(answer);
1656
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 // Make sure the receive streams have not changed.
1658 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1659 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1660 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1661 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1662}
1663
1664// Test receiving offers and creating answers and make sure the
1665// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001666TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001667 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001668 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001669 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 SetRemoteDescriptionWithoutError(offer);
1672
deadbeefab9b2d12015-10-14 11:33:11 -07001673 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001674 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001675 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 SetLocalDescriptionWithoutError(answer);
1677
1678 const std::string session_id_orig = answer->session_id();
1679 const std::string session_version_orig = answer->session_version();
1680
1681 video_channel_ = media_engine_->GetVideoChannel(0);
1682 voice_channel_ = media_engine_->GetVoiceChannel(0);
1683
htaa2a49d92016-03-04 02:51:39 -08001684 ASSERT_TRUE(video_channel_);
1685 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1687 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1688
1689 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1690 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1691
1692 ASSERT_EQ(1u, video_channel_->send_streams().size());
1693 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1694 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1695 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1696
deadbeefab9b2d12015-10-14 11:33:11 -07001697 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001698 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 SetRemoteDescriptionWithoutError(offer);
1700
1701 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001702 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001703 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704
1705 // Verify the session id is the same and the session version is
1706 // increased.
1707 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001708 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1709 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 SetLocalDescriptionWithoutError(answer);
1711
1712 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1713 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1714 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1715 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1716 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1717 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1718
1719 // Make sure we have no send streams.
1720 EXPECT_EQ(0u, video_channel_->send_streams().size());
1721 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1722}
1723
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001724TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001725 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001726 media_engine_->set_fail_create_channel(true);
1727
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001728 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001729 ASSERT_TRUE(offer != NULL);
1730 // SetRemoteDescription and SetLocalDescription will take the ownership of
1731 // the offer.
1732 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001733 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001734 ASSERT_TRUE(offer != NULL);
1735 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1736}
1737
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001738//
1739// Tests for creating/setting SDP under different SDES/DTLS polices:
1740//
1741// --DTLS off and SDES on
1742// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1743// set local/remote offer/answer with crypto --> success
1744// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1745// failure
1746// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1747// failure
1748// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1749// failure
1750//
1751// --DTLS on and SDES off
1752// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1753// set local/remote offer/answer with DTLS fingerprint --> success
1754// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1755// fingerprint --> failure
1756// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1757// --> failure
1758// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1759// --> failure
1760//
1761// --Encryption disabled: DTLS off and SDES off
1762// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1763// answer without SDES or DTLS --> success
1764// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1765// answer without SDES or DTLS --> success
1766//
1767
1768// Test that we return a failure when applying a remote/local offer that doesn't
1769// have cryptos enabled when DTLS is off.
1770TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001771 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001773 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 JsepSessionDescription* offer = CreateRemoteOffer(
1775 options, cricket::SEC_DISABLED);
1776 ASSERT_TRUE(offer != NULL);
1777 VerifyNoCryptoParams(offer->description(), false);
1778 // SetRemoteDescription and SetLocalDescription will take the ownership of
1779 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1782 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784}
1785
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786// Test that we return a failure when applying a local answer that doesn't have
1787// cryptos enabled when DTLS is off.
1788TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001789 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 SessionDescriptionInterface* offer = NULL;
1791 SessionDescriptionInterface* answer = NULL;
1792 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1793 // SetRemoteDescription and SetLocalDescription will take the ownership of
1794 // the offer.
1795 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001796 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797}
1798
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001799// Test we will return fail when apply an remote answer that doesn't have
1800// crypto enabled when DTLS is off.
1801TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001802 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 SessionDescriptionInterface* offer = NULL;
1804 SessionDescriptionInterface* answer = NULL;
1805 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1806 // SetRemoteDescription and SetLocalDescription will take the ownership of
1807 // the offer.
1808 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001809 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810}
1811
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1813// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001814TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001815 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001816 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 SetFactoryDtlsSrtp();
1818 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001819 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001820 JsepSessionDescription* offer =
1821 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 ASSERT_TRUE(offer != NULL);
1823 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825
1826 // SetRemoteDescription will take the ownership of the offer.
1827 SetRemoteDescriptionWithoutError(offer);
1828
1829 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001830 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 ASSERT_TRUE(answer != NULL);
1832 VerifyFingerprintStatus(answer->description(), true);
1833 // Check that we don't have an a=crypto line in the answer.
1834 VerifyNoCryptoParams(answer->description(), true);
1835
1836 // Now set the local description, which should work, even without a=crypto.
1837 SetLocalDescriptionWithoutError(answer);
1838}
1839
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1841// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001842TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001843 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001844 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001845 SetFactoryDtlsSrtp();
1846
1847 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001848 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 ASSERT_TRUE(offer != NULL);
1850 VerifyFingerprintStatus(offer->description(), true);
1851 // Check that we don't have an a=crypto line in the offer.
1852 VerifyNoCryptoParams(offer->description(), true);
1853
1854 // Now set the local description, which should work, even without a=crypto.
1855 SetLocalDescriptionWithoutError(offer);
1856
1857 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001858 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001859 JsepSessionDescription* answer =
1860 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1861 ASSERT_TRUE(answer != NULL);
1862 VerifyFingerprintStatus(answer->description(), true);
1863 VerifyNoCryptoParams(answer->description(), true);
1864
1865 // SetRemoteDescription will take the ownership of the answer.
1866 SetRemoteDescriptionWithoutError(answer);
1867}
1868
1869// Test that if we support DTLS and the other side didn't offer a fingerprint,
1870// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001871TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001872 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001874 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001875 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 JsepSessionDescription* offer = CreateRemoteOffer(
1877 options, cricket::SEC_REQUIRED);
1878 ASSERT_TRUE(offer != NULL);
1879 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001880 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 // SetRemoteDescription will take the ownership of the offer.
1883 SetRemoteDescriptionOfferExpectError(
1884 kSdpWithoutDtlsFingerprint, offer);
1885
1886 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1887 // SetLocalDescription will take the ownership of the offer.
1888 SetLocalDescriptionOfferExpectError(
1889 kSdpWithoutDtlsFingerprint, offer);
1890}
1891
1892// Test that we return a failure when applying a local answer that doesn't have
1893// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001894TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001895 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001896 SessionDescriptionInterface* offer = NULL;
1897 SessionDescriptionInterface* answer = NULL;
1898 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1899
1900 // SetRemoteDescription and SetLocalDescription will take the ownership of
1901 // the offer and answer.
1902 SetRemoteDescriptionWithoutError(offer);
1903 SetLocalDescriptionAnswerExpectError(
1904 kSdpWithoutDtlsFingerprint, answer);
1905}
1906
1907// Test that we return a failure when applying a remote answer that doesn't have
1908// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001909TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001910 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001911 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001913 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001914 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001915 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001917 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918
1919 // SetRemoteDescription and SetLocalDescription will take the ownership of
1920 // the offer and answer.
1921 SetLocalDescriptionWithoutError(offer);
1922 SetRemoteDescriptionAnswerExpectError(
1923 kSdpWithoutDtlsFingerprint, answer);
1924}
1925
1926// Test that we create a local offer without SDES or DTLS and accept a remote
1927// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001928TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001929 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001930 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001931 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001932
1933 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001934 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001935 ASSERT_TRUE(offer != NULL);
1936 VerifyFingerprintStatus(offer->description(), false);
1937 // Check that we don't have an a=crypto line in the offer.
1938 VerifyNoCryptoParams(offer->description(), false);
1939
1940 // Now set the local description, which should work, even without a=crypto.
1941 SetLocalDescriptionWithoutError(offer);
1942
1943 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001944 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945 JsepSessionDescription* answer =
1946 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1947 ASSERT_TRUE(answer != NULL);
1948 VerifyFingerprintStatus(answer->description(), false);
1949 VerifyNoCryptoParams(answer->description(), false);
1950
1951 // SetRemoteDescription will take the ownership of the answer.
1952 SetRemoteDescriptionWithoutError(answer);
1953}
1954
1955// Test that we create a local answer without SDES or DTLS and accept a remote
1956// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001957TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001958 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001959 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001960
1961 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001962 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963 JsepSessionDescription* offer =
1964 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1965 ASSERT_TRUE(offer != NULL);
1966 VerifyFingerprintStatus(offer->description(), false);
1967 VerifyNoCryptoParams(offer->description(), false);
1968
1969 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 SetRemoteDescriptionWithoutError(offer);
1971
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001972 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001973 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 ASSERT_TRUE(answer != NULL);
1975 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001976 // Check that we don't have an a=crypto line in the answer.
1977 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001979 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 SetLocalDescriptionWithoutError(answer);
1981}
1982
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001983// Test that we can create and set an answer correctly when different
1984// SSL roles have been negotiated for different transports.
1985// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1986TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1987 SendAudioVideoStream1();
1988 InitWithDtls(GetParam());
1989 SetFactoryDtlsSrtp();
1990
1991 SessionDescriptionInterface* offer = CreateOffer();
1992 SetLocalDescriptionWithoutError(offer);
1993
1994 cricket::MediaSessionOptions options;
1995 options.recv_video = true;
1996
1997 // First, negotiate different SSL roles.
1998 SessionDescriptionInterface* answer =
1999 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2000 TransportInfo* audio_transport_info =
2001 answer->description()->GetTransportInfoByName("audio");
2002 audio_transport_info->description.connection_role =
2003 cricket::CONNECTIONROLE_ACTIVE;
2004 TransportInfo* video_transport_info =
2005 answer->description()->GetTransportInfoByName("video");
2006 video_transport_info->description.connection_role =
2007 cricket::CONNECTIONROLE_PASSIVE;
2008 SetRemoteDescriptionWithoutError(answer);
2009
2010 // Now create an offer in the reverse direction, and ensure the initial
2011 // offerer responds with an answer with correct SSL roles.
2012 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2013 kSessionVersion,
2014 session_->remote_description());
2015 SetRemoteDescriptionWithoutError(offer);
2016
htaa2a49d92016-03-04 02:51:39 -08002017 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002018 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2019 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2020 audio_transport_info->description.connection_role);
2021 video_transport_info = answer->description()->GetTransportInfoByName("video");
2022 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2023 video_transport_info->description.connection_role);
2024 SetLocalDescriptionWithoutError(answer);
2025
2026 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2027 // audio is transferred over to video in the answer that completes the BUNDLE
2028 // negotiation.
2029 options.bundle_enabled = true;
2030 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2031 kSessionVersion,
2032 session_->remote_description());
2033 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002034 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002035 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2036 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2037 audio_transport_info->description.connection_role);
2038 video_transport_info = answer->description()->GetTransportInfoByName("video");
2039 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2040 video_transport_info->description.connection_role);
2041 SetLocalDescriptionWithoutError(answer);
2042}
2043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002045 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002046 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SetLocalDescriptionWithoutError(offer);
2050
2051 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002052 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 SetLocalDescriptionWithoutError(offer2);
2054}
2055
2056TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002057 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002058 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002060 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 SetRemoteDescriptionWithoutError(offer);
2062
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 SetRemoteDescriptionWithoutError(offer2);
2065}
2066
2067TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002068 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002069 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002070 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002072 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002073 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2074 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075}
2076
2077TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002078 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002079 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002080 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002082 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002083 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002084 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085}
2086
2087TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002091 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
htaa2a49d92016-03-04 02:51:39 -08002093 JsepSessionDescription* pranswer =
2094 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002096 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
deadbeefab9b2d12015-10-14 11:33:11 -07002098 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002099 JsepSessionDescription* pranswer2 =
2100 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2102
deadbeefd59daf82015-10-14 15:02:44 -07002103 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
deadbeefab9b2d12015-10-14 11:33:11 -07002105 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002106 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002107 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108}
2109
2110TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002111 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002112 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002113 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002114 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 JsepSessionDescription* pranswer =
2117 CreateRemoteAnswer(session_->local_description());
2118 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2119
2120 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002121 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122
deadbeefab9b2d12015-10-14 11:33:11 -07002123 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 JsepSessionDescription* pranswer2 =
2125 CreateRemoteAnswer(session_->local_description());
2126 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2127
2128 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002129 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
deadbeefab9b2d12015-10-14 11:33:11 -07002131 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 SessionDescriptionInterface* answer =
2133 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002134 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135}
2136
2137TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002138 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002139 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002140 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 SessionDescriptionInterface* answer =
2143 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002144 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2145 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146}
2147
2148TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002149 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002150 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002151 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002152
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 SessionDescriptionInterface* answer =
2154 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002155 SetRemoteDescriptionAnswerExpectError(
2156 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157}
2158
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002159// Tests that the remote candidates are added and removed successfully.
2160TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002161 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002162 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002164 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
zhihuang38989e52017-03-21 11:04:53 -07002165 "", "", "local", 0, "");
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002166 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2168
deadbeefd59daf82015-10-14 15:02:44 -07002169 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2171
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002172 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002174
2175 // Fail since we have not set a remote description.
2176 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177
2178 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2179 session_->local_description());
2180 SetRemoteDescriptionWithoutError(answer);
2181
deadbeefd59daf82015-10-14 15:02:44 -07002182 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2183 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002184 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002185 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2186 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2187
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 // Verifying the candidates are copied properly from internal vector.
2189 const SessionDescriptionInterface* remote_desc =
2190 session_->remote_description();
2191 ASSERT_TRUE(remote_desc != NULL);
2192 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2193 const IceCandidateCollection* candidates =
2194 remote_desc->candidates(kMediaContentIndex0);
2195 ASSERT_EQ(2u, candidates->count());
2196 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2197 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2198 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2199 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2200
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002201 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2202 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 candidate.set_component(2);
2204 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2205 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002206 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207
2208 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2209 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002210
2211 // Remove candidate1 and candidate2
2212 std::vector<cricket::Candidate> remote_candidates;
2213 remote_candidates.push_back(ice_candidate1.candidate());
2214 remote_candidates.push_back(ice_candidate2.candidate());
2215 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2216 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217}
2218
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002219// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220// that it is retained if the remote session description is changed.
2221TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002222 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 cricket::Candidate candidate1;
2224 candidate1.set_component(1);
2225 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2226 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002227 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 CreateAndSetRemoteOfferAndLocalAnswer();
2229
2230 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2231 const SessionDescriptionInterface* remote_desc =
2232 session_->remote_description();
2233 ASSERT_TRUE(remote_desc != NULL);
2234 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2235 const IceCandidateCollection* candidates =
2236 remote_desc->candidates(kMediaContentIndex0);
2237 ASSERT_EQ(1u, candidates->count());
2238 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2239
2240 // Update the RemoteSessionDescription with a new session description and
2241 // a candidate and check that the new remote session description contains both
2242 // candidates.
2243 SessionDescriptionInterface* offer = CreateRemoteOffer();
2244 cricket::Candidate candidate2;
2245 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2246 candidate2);
2247 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2248 SetRemoteDescriptionWithoutError(offer);
2249
2250 remote_desc = session_->remote_description();
2251 ASSERT_TRUE(remote_desc != NULL);
2252 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2253 candidates = remote_desc->candidates(kMediaContentIndex0);
2254 ASSERT_EQ(2u, candidates->count());
2255 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2256 // Username and password have be updated with the TransportInfo of the
2257 // SessionDescription, won't be equal to the original one.
2258 candidate2.set_username(candidates->at(0)->candidate().username());
2259 candidate2.set_password(candidates->at(0)->candidate().password());
2260 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2261 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2262 // No need to verify the username and password.
2263 candidate1.set_username(candidates->at(1)->candidate().username());
2264 candidate1.set_password(candidates->at(1)->candidate().password());
2265 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2266
2267 // Test that the candidate is ignored if we can add the same candidate again.
2268 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2269}
2270
2271// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002272// that they are retained if the local session description is changed. And if
2273// continual gathering is enabled, they are removed from the local session
2274// description when the network is down.
2275TEST_F(WebRtcSessionTest,
2276 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002277 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002278 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002279 // Enable Continual Gathering.
2280 cricket::IceConfig config;
2281 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2282 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002283 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 CreateAndSetRemoteOfferAndLocalAnswer();
2285
2286 const SessionDescriptionInterface* local_desc = session_->local_description();
2287 const IceCandidateCollection* candidates =
2288 local_desc->candidates(kMediaContentIndex0);
2289 ASSERT_TRUE(candidates != NULL);
2290 EXPECT_EQ(0u, candidates->count());
2291
deadbeefb60a8192016-08-24 15:15:00 -07002292 // Since we're using continual gathering, we won't get "gathering done".
2293 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294
2295 local_desc = session_->local_description();
2296 candidates = local_desc->candidates(kMediaContentIndex0);
2297 ASSERT_TRUE(candidates != NULL);
2298 EXPECT_LT(0u, candidates->count());
2299 candidates = local_desc->candidates(1);
2300 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002301 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302
2303 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002304 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 CreateAndSetRemoteOfferAndLocalAnswer();
2306
2307 local_desc = session_->local_description();
2308 candidates = local_desc->candidates(kMediaContentIndex0);
2309 ASSERT_TRUE(candidates != NULL);
2310 EXPECT_LT(0u, candidates->count());
2311 candidates = local_desc->candidates(1);
2312 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002313 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002314
2315 candidates = local_desc->candidates(kMediaContentIndex0);
2316 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002317 // Bring down the network interface to trigger candidate removals.
2318 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2319 // Verify that all local candidates are removed.
2320 EXPECT_EQ(0, observer_.num_candidates_removed_);
2321 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2322 kIceCandidatesTimeout);
2323 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2324}
2325
2326// Tests that if continual gathering is disabled, local candidates won't be
2327// removed when the interface is turned down.
2328TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2329 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2330 Init();
2331 SendAudioVideoStream1();
2332 CreateAndSetRemoteOfferAndLocalAnswer();
2333
2334 const SessionDescriptionInterface* local_desc = session_->local_description();
2335 const IceCandidateCollection* candidates =
2336 local_desc->candidates(kMediaContentIndex0);
2337 ASSERT_TRUE(candidates != NULL);
2338 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2339
2340 size_t num_local_candidates = candidates->count();
2341 EXPECT_LT(0u, num_local_candidates);
2342 // By default, Continual Gathering is disabled.
2343 // Bring down the network interface.
2344 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2345 // Verify that the local candidates are not removed.
2346 rtc::Thread::Current()->ProcessMessages(1000);
2347 EXPECT_EQ(0, observer_.num_candidates_removed_);
2348 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349}
2350
2351// Test that we can set a remote session description with remote candidates.
2352TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002353 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
2355 cricket::Candidate candidate1;
2356 candidate1.set_component(1);
2357 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2358 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002359 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002360 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361
2362 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2363 SetRemoteDescriptionWithoutError(offer);
2364
2365 const SessionDescriptionInterface* remote_desc =
2366 session_->remote_description();
2367 ASSERT_TRUE(remote_desc != NULL);
2368 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2369 const IceCandidateCollection* candidates =
2370 remote_desc->candidates(kMediaContentIndex0);
2371 ASSERT_EQ(1u, candidates->count());
2372 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2373
htaa2a49d92016-03-04 02:51:39 -08002374 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 SetLocalDescriptionWithoutError(answer);
2376}
2377
2378// Test that offers and answers contains ice candidates when Ice candidates have
2379// been gathered.
2380TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002381 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002382 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002383 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 // Ice is started but candidates are not provided until SetLocalDescription
2385 // is called.
2386 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2387 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2388 CreateAndSetRemoteOfferAndLocalAnswer();
2389 // Wait until at least one local candidate has been collected.
2390 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2391 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392
kwibergd1fe2812016-04-27 06:47:29 -07002393 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002394
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2396 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397
2398 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2399 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002400 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2402 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 SetLocalDescriptionWithoutError(answer);
2404}
2405
2406// Verifies TransportProxy and media channels are created with content names
2407// present in the SessionDescription.
2408TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002409 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002410 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002411 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412
2413 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002414 // "video". Goal is to modify these content names and verify transport
2415 // channels
2416 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 // present in SDP.
2418 std::string sdp;
2419 EXPECT_TRUE(offer->ToString(&sdp));
2420 const std::string kAudioMid = "a=mid:audio";
2421 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2422 const std::string kVideoMid = "a=mid:video";
2423 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2424
2425 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002426 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 kAudioMidReplaceStr.c_str(),
2428 kAudioMidReplaceStr.length(),
2429 &sdp);
2430 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002431 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 kVideoMidReplaceStr.c_str(),
2433 kVideoMidReplaceStr.length(),
2434 &sdp);
2435
2436 SessionDescriptionInterface* modified_offer =
2437 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2438
2439 SetRemoteDescriptionWithoutError(modified_offer);
2440
htaa2a49d92016-03-04 02:51:39 -08002441 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 SetLocalDescriptionWithoutError(answer);
2443
deadbeef5bd5ca32017-02-10 11:31:50 -08002444 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002445 session_->voice_rtp_transport_channel();
2446 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002447 EXPECT_EQ(voice_transport_channel->debug_name(),
2448 "audio_content_name " +
2449 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002450 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002451 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002452 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002453 EXPECT_EQ(video_transport_channel->debug_name(),
2454 "video_content_name " +
2455 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2457 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2458}
2459
2460// Test that an offer contains the correct media content descriptions based on
2461// the send streams when no constraints have been set.
2462TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002463 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002464 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002465
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 ASSERT_TRUE(offer != NULL);
2467 const cricket::ContentInfo* content =
2468 cricket::GetFirstAudioContent(offer->description());
2469 EXPECT_TRUE(content != NULL);
2470 content = cricket::GetFirstVideoContent(offer->description());
2471 EXPECT_TRUE(content == NULL);
2472}
2473
2474// Test that an offer contains the correct media content descriptions based on
2475// the send streams when no constraints have been set.
2476TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002479 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002480 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 const cricket::ContentInfo* content =
2483 cricket::GetFirstAudioContent(offer->description());
2484 EXPECT_TRUE(content != NULL);
2485 content = cricket::GetFirstVideoContent(offer->description());
2486 EXPECT_TRUE(content == NULL);
2487
2488 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002489 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002490 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 content = cricket::GetFirstAudioContent(offer->description());
2492 EXPECT_TRUE(content != NULL);
2493 content = cricket::GetFirstVideoContent(offer->description());
2494 EXPECT_TRUE(content != NULL);
2495}
2496
2497// Test that an offer contains no media content descriptions if
2498// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2499TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002500 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002501 PeerConnectionInterface::RTCOfferAnswerOptions options;
2502 options.offer_to_receive_audio = 0;
2503 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504
kwibergd1fe2812016-04-27 06:47:29 -07002505 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 ASSERT_TRUE(offer != NULL);
2508 const cricket::ContentInfo* content =
2509 cricket::GetFirstAudioContent(offer->description());
2510 EXPECT_TRUE(content == NULL);
2511 content = cricket::GetFirstVideoContent(offer->description());
2512 EXPECT_TRUE(content == NULL);
2513}
2514
2515// Test that an offer contains only audio media content descriptions if
2516// kOfferToReceiveAudio constraints are set to true.
2517TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002518 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002519 PeerConnectionInterface::RTCOfferAnswerOptions options;
2520 options.offer_to_receive_audio =
2521 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2522
kwibergd1fe2812016-04-27 06:47:29 -07002523 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524
2525 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(offer->description());
2527 EXPECT_TRUE(content != NULL);
2528 content = cricket::GetFirstVideoContent(offer->description());
2529 EXPECT_TRUE(content == NULL);
2530}
2531
2532// Test that an offer contains audio and video media content descriptions if
2533// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2534TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002535 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002537 PeerConnectionInterface::RTCOfferAnswerOptions options;
2538 options.offer_to_receive_audio =
2539 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2540 options.offer_to_receive_video =
2541 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2542
kwibergd1fe2812016-04-27 06:47:29 -07002543 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002544
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 const cricket::ContentInfo* content =
2546 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002547 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002548
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 content = cricket::GetFirstVideoContent(offer->description());
2550 EXPECT_TRUE(content != NULL);
2551
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002552 // Sets constraints to false and verifies that audio/video contents are
2553 // removed.
2554 options.offer_to_receive_audio = 0;
2555 options.offer_to_receive_video = 0;
2556 offer.reset(CreateOffer(options));
2557
2558 content = cricket::GetFirstAudioContent(offer->description());
2559 EXPECT_TRUE(content == NULL);
2560 content = cricket::GetFirstVideoContent(offer->description());
2561 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562}
2563
2564// Test that an answer can not be created if the last remote description is not
2565// an offer.
2566TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002567 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002568 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 SetLocalDescriptionWithoutError(offer);
2570 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2571 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002572 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573}
2574
2575// Test that an answer contains the correct media content descriptions when no
2576// constraints have been set.
2577TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002580 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002582 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 const cricket::ContentInfo* content =
2584 cricket::GetFirstAudioContent(answer->description());
2585 ASSERT_TRUE(content != NULL);
2586 EXPECT_FALSE(content->rejected);
2587
2588 content = cricket::GetFirstVideoContent(answer->description());
2589 ASSERT_TRUE(content != NULL);
2590 EXPECT_FALSE(content->rejected);
2591}
2592
2593// Test that an answer contains the correct media content descriptions when no
2594// constraints have been set and the offer only contain audio.
2595TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002596 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 // Create a remote offer with audio only.
2598 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002599
kwibergd1fe2812016-04-27 06:47:29 -07002600 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2602 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2603
2604 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002605 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606 const cricket::ContentInfo* content =
2607 cricket::GetFirstAudioContent(answer->description());
2608 ASSERT_TRUE(content != NULL);
2609 EXPECT_FALSE(content->rejected);
2610
2611 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2612}
2613
2614// Test that an answer contains the correct media content descriptions when no
2615// constraints have been set.
2616TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002617 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002619 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 SetRemoteDescriptionWithoutError(offer.release());
2621 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002622 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002623 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 const cricket::ContentInfo* content =
2625 cricket::GetFirstAudioContent(answer->description());
2626 ASSERT_TRUE(content != NULL);
2627 EXPECT_FALSE(content->rejected);
2628
2629 content = cricket::GetFirstVideoContent(answer->description());
2630 ASSERT_TRUE(content != NULL);
2631 EXPECT_FALSE(content->rejected);
2632}
2633
2634// Test that an answer contains the correct media content descriptions when
2635// constraints have been set but no stream is sent.
2636TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002637 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002639 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 SetRemoteDescriptionWithoutError(offer.release());
2641
htaa2a49d92016-03-04 02:51:39 -08002642 cricket::MediaSessionOptions session_options;
2643 session_options.recv_audio = false;
2644 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002645 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002646 CreateAnswer(session_options));
2647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 const cricket::ContentInfo* content =
2649 cricket::GetFirstAudioContent(answer->description());
2650 ASSERT_TRUE(content != NULL);
2651 EXPECT_TRUE(content->rejected);
2652
2653 content = cricket::GetFirstVideoContent(answer->description());
2654 ASSERT_TRUE(content != NULL);
2655 EXPECT_TRUE(content->rejected);
2656}
2657
2658// Test that an answer contains the correct media content descriptions when
2659// constraints have been set and streams are sent.
2660TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002661 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002663 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 SetRemoteDescriptionWithoutError(offer.release());
2665
htaa2a49d92016-03-04 02:51:39 -08002666 cricket::MediaSessionOptions options;
2667 options.recv_audio = false;
2668 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669
2670 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002671 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002672 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673
2674 // TODO(perkj): Should the direction be set to SEND_ONLY?
2675 const cricket::ContentInfo* content =
2676 cricket::GetFirstAudioContent(answer->description());
2677 ASSERT_TRUE(content != NULL);
2678 EXPECT_FALSE(content->rejected);
2679
2680 // TODO(perkj): Should the direction be set to SEND_ONLY?
2681 content = cricket::GetFirstVideoContent(answer->description());
2682 ASSERT_TRUE(content != NULL);
2683 EXPECT_FALSE(content->rejected);
2684}
2685
2686TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2687 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002688 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002689 PeerConnectionInterface::RTCOfferAnswerOptions options;
2690 options.offer_to_receive_audio =
2691 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2692 options.voice_activity_detection = false;
2693
kwibergd1fe2812016-04-27 06:47:29 -07002694 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002695
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696 const cricket::ContentInfo* content =
2697 cricket::GetFirstAudioContent(offer->description());
2698 EXPECT_TRUE(content != NULL);
2699 EXPECT_TRUE(VerifyNoCNCodecs(content));
2700}
2701
2702TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2703 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002706 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 SetRemoteDescriptionWithoutError(offer.release());
2708
htaa2a49d92016-03-04 02:51:39 -08002709 cricket::MediaSessionOptions options;
2710 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002711 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 const cricket::ContentInfo* content =
2713 cricket::GetFirstAudioContent(answer->description());
2714 ASSERT_TRUE(content != NULL);
2715 EXPECT_TRUE(VerifyNoCNCodecs(content));
2716}
2717
2718// This test verifies the call setup when remote answer with audio only and
2719// later updates with video.
2720TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002721 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2723 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2724
deadbeefab9b2d12015-10-14 11:33:11 -07002725 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002726 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
2728 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2730
2731 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2732 // and answer;
2733 SetLocalDescriptionWithoutError(offer);
2734 SetRemoteDescriptionWithoutError(answer);
2735
2736 video_channel_ = media_engine_->GetVideoChannel(0);
2737 voice_channel_ = media_engine_->GetVoiceChannel(0);
2738
2739 ASSERT_TRUE(video_channel_ == NULL);
2740
2741 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2742 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2743 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2744
2745 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002746 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747 CreateAndSetRemoteOfferAndLocalAnswer();
2748
2749 video_channel_ = media_engine_->GetVideoChannel(0);
2750 voice_channel_ = media_engine_->GetVoiceChannel(0);
2751
2752 ASSERT_TRUE(video_channel_ != NULL);
2753 ASSERT_TRUE(voice_channel_ != NULL);
2754
2755 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2756 ASSERT_EQ(1u, video_channel_->send_streams().size());
2757 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2758 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2759 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2760 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2761 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2762 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2763
2764 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002765 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 CreateAndSetRemoteOfferAndLocalAnswer();
2767
2768 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2769 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2770 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2771 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2772 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2773}
2774
2775// This test verifies the call setup when remote answer with video only and
2776// later updates with audio.
2777TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002778 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2780 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002781 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002782 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783
2784 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002785 options.recv_audio = false;
2786 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2788 offer, options, cricket::SEC_ENABLED);
2789
2790 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2791 // and answer.
2792 SetLocalDescriptionWithoutError(offer);
2793 SetRemoteDescriptionWithoutError(answer);
2794
2795 video_channel_ = media_engine_->GetVideoChannel(0);
2796 voice_channel_ = media_engine_->GetVoiceChannel(0);
2797
2798 ASSERT_TRUE(voice_channel_ == NULL);
2799 ASSERT_TRUE(video_channel_ != NULL);
2800
2801 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2802 ASSERT_EQ(1u, video_channel_->send_streams().size());
2803 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2804
2805 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002806 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 CreateAndSetRemoteOfferAndLocalAnswer();
2808
2809 voice_channel_ = media_engine_->GetVoiceChannel(0);
2810 ASSERT_TRUE(voice_channel_ != NULL);
2811
2812 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2813 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2814 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2815 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2816
2817 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002818 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 CreateAndSetRemoteOfferAndLocalAnswer();
2820
2821 video_channel_ = media_engine_->GetVideoChannel(0);
2822 voice_channel_ = media_engine_->GetVoiceChannel(0);
2823
2824 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2825 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2826 ASSERT_EQ(1u, video_channel_->send_streams().size());
2827 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2828}
2829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002831 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002832 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002833 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834 VerifyCryptoParams(offer->description());
2835 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 VerifyCryptoParams(answer->description());
2838}
2839
jbauchcb560652016-08-04 05:20:32 -07002840TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2841 InitWithGcm();
2842 SendAudioVideoStream1();
2843 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2844 VerifyCryptoParams(offer->description(), true);
2845 SetRemoteDescriptionWithoutError(offer.release());
2846 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2847 VerifyCryptoParams(answer->description(), true);
2848}
2849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002851 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002852 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002853 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002854 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 VerifyNoCryptoParams(offer->description(), false);
2856}
2857
2858TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002859 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860 VerifyAnswerFromNonCryptoOffer();
2861}
2862
2863TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002864 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865 VerifyAnswerFromCryptoOffer();
2866}
2867
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002868// This test verifies that setLocalDescription fails if
2869// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2870TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002871 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002872 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002873 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002874
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002875 std::string sdp;
2876 RemoveIceUfragPwdLines(offer.get(), &sdp);
2877 SessionDescriptionInterface* modified_offer =
2878 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002879 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002880}
2881
2882// This test verifies that setRemoteDescription fails if
2883// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2884TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002885 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002886 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002887 std::string sdp;
2888 RemoveIceUfragPwdLines(offer.get(), &sdp);
2889 SessionDescriptionInterface* modified_offer =
2890 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002891 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002892}
2893
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002894// This test verifies that setLocalDescription fails if local offer has
2895// too short ice ufrag and pwd strings.
2896TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002897 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002898 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002899 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002900 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2901 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002902 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002903 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002904 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002905
2906 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002907 offer.reset(CreateOffer());
2908 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2909 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002910}
2911
2912// This test verifies that setRemoteDescription fails if remote offer has
2913// too short ice ufrag and pwd strings.
2914TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002915 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002916 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002917 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2918 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002919 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002920 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002921 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002922
deadbeef0ed85b22016-02-23 17:24:52 -08002923 offer.reset(CreateRemoteOffer());
2924 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2925 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002926}
2927
Honghai Zhang04e91462015-12-11 14:26:22 -08002928// Test that if the remote offer indicates the peer requested ICE restart (via
2929// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2930TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002931 Init();
honghaiz503726c2015-07-31 12:37:38 -07002932
2933 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002934 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002935 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002936 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2937 0, "", "", "relay", 0, "");
2938 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2939 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002940 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2941 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002942 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2943
2944 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002945 offer.reset(CreateRemoteOffer());
2946 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002947 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2948 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2949 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002950 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2951 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002952 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2953
2954 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002955 offer.reset(CreateRemoteOffer());
2956 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002957 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2958 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2959 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002960 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2961 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002962 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2963
2964 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002965 offer.reset(CreateRemoteOffer());
2966 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2967 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002968 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2969}
2970
Honghai Zhang04e91462015-12-11 14:26:22 -08002971// Test that if the remote answer indicates the peer requested ICE restart (via
2972// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2973TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2974 Init();
2975 SessionDescriptionInterface* offer = CreateOffer();
2976 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002977
2978 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002979 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002980 answer->set_type(JsepSessionDescription::kPrAnswer);
2981 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002982 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2983 0, "", "", "relay", 0, "");
2984 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2985 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002986 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2987 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002988 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2989
2990 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002991 answer.reset(CreateRemoteAnswer(offer));
2992 answer->set_type(JsepSessionDescription::kPrAnswer);
2993 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002994 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2995 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2996 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002997 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2998 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002999 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3000
3001 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003002 answer.reset(CreateRemoteAnswer(offer));
3003 answer->set_type(JsepSessionDescription::kPrAnswer);
3004 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003005 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3006 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3007 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003008 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3009 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003010 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3011
3012 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003013 answer.reset(CreateRemoteAnswer(offer));
3014 answer->set_type(JsepSessionDescription::kPrAnswer);
3015 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3016 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003017 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3018}
3019
Donald Curtisd4f769d2015-05-28 09:48:21 -07003020// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003021// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003022TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3023 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3024
3025 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003026 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003027
3028 PeerConnectionInterface::RTCOfferAnswerOptions options;
3029 options.use_rtp_mux = true;
3030
3031 SessionDescriptionInterface* offer = CreateRemoteOffer();
3032 SetRemoteDescriptionWithoutError(offer);
3033
htaa2a49d92016-03-04 02:51:39 -08003034 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003035 SetLocalDescriptionWithoutError(answer);
3036
deadbeefcbecd352015-09-23 11:50:27 -07003037 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3038 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003039
deadbeefcbecd352015-09-23 11:50:27 -07003040 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003041 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003042
3043 // Checks if one of the transport channels contains a connection using a given
3044 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003045 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003046 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3047 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003048 for (auto& chan_stat : kv.second.channel_stats) {
3049 for (auto& conn_info : chan_stat.connection_infos) {
3050 if (conn_info.remote_candidate.address().port() == port) {
3051 return true;
3052 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003053 }
3054 }
3055 }
3056 return false;
3057 };
3058
3059 EXPECT_FALSE(connection_with_remote_port(5000));
3060 EXPECT_FALSE(connection_with_remote_port(5001));
3061 EXPECT_FALSE(connection_with_remote_port(6000));
3062
3063 // The way the *_WAIT checks work is they only wait if the condition fails,
3064 // which does not help in the case where state is not changing. This is
3065 // problematic in this test since we want to verify that adding a video
3066 // candidate does _not_ change state. So we interleave candidates and assume
3067 // that messages are executed in the order they were posted.
3068
3069 // First audio candidate.
3070 cricket::Candidate candidate0;
3071 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3072 candidate0.set_component(1);
3073 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003074 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003075 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3076 candidate0);
3077 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3078
3079 // Video candidate.
3080 cricket::Candidate candidate1;
3081 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3082 candidate1.set_component(1);
3083 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003084 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003085 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3086 candidate1);
3087 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3088
3089 // Second audio candidate.
3090 cricket::Candidate candidate2;
3091 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3092 candidate2.set_component(1);
3093 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003094 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003095 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3096 candidate2);
3097 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3098
3099 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3100 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3101
3102 // No need here for a _WAIT check since we are checking that state hasn't
3103 // changed: if this is false we would be doing waits for nothing and if this
3104 // is true then there will be no messages processed anyways.
3105 EXPECT_FALSE(connection_with_remote_port(6000));
3106}
3107
deadbeefcbecd352015-09-23 11:50:27 -07003108// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003109TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3110 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003111 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003112
3113 PeerConnectionInterface::RTCOfferAnswerOptions options;
3114 options.use_rtp_mux = true;
3115
3116 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003118
deadbeefcbecd352015-09-23 11:50:27 -07003119 EXPECT_NE(session_->voice_rtp_transport_channel(),
3120 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003121
deadbeefab9b2d12015-10-14 11:33:11 -07003122 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003123 SessionDescriptionInterface* answer =
3124 CreateRemoteAnswer(session_->local_description());
3125 SetRemoteDescriptionWithoutError(answer);
3126
deadbeefcbecd352015-09-23 11:50:27 -07003127 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3128 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129}
3130
deadbeefcbecd352015-09-23 11:50:27 -07003131// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003132TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003135
Donald Curtis0e209b02015-03-24 09:29:54 -07003136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
3138
3139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_NE(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003146
3147 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003148 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003149 CreateRemoteAnswer(session_->local_description()));
3150 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3151 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3152 JsepSessionDescription* modified_answer =
3153 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3154 modified_answer->Initialize(answer_copy, "1", "1");
3155 SetRemoteDescriptionWithoutError(modified_answer); //
3156
deadbeefcbecd352015-09-23 11:50:27 -07003157 EXPECT_NE(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003159}
3160
3161// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003165
3166 PeerConnectionInterface::RTCOfferAnswerOptions options;
3167 options.use_rtp_mux = true;
3168
3169 SessionDescriptionInterface* offer = CreateOffer(options);
3170 SetLocalDescriptionWithoutError(offer);
3171
deadbeefcbecd352015-09-23 11:50:27 -07003172 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3173 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003174
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003176 SessionDescriptionInterface* answer =
3177 CreateRemoteAnswer(session_->local_description());
3178 SetRemoteDescriptionWithoutError(answer);
3179
deadbeefcbecd352015-09-23 11:50:27 -07003180 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
3182}
3183
3184// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3185// audio content in the answer.
3186TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3187 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003189
3190 PeerConnectionInterface::RTCOfferAnswerOptions options;
3191 options.use_rtp_mux = true;
3192
3193 SessionDescriptionInterface* offer = CreateOffer(options);
3194 SetLocalDescriptionWithoutError(offer);
3195
3196 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel());
3198
deadbeefab9b2d12015-10-14 11:33:11 -07003199 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003200 cricket::MediaSessionOptions recv_options;
3201 recv_options.recv_audio = false;
3202 recv_options.recv_video = true;
3203 SessionDescriptionInterface* answer =
3204 CreateRemoteAnswer(session_->local_description(), recv_options);
3205 SetRemoteDescriptionWithoutError(answer);
3206
deadbeefd59daf82015-10-14 15:02:44 -07003207 EXPECT_TRUE(nullptr == session_->voice_channel());
3208 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003209
deadbeefd59daf82015-10-14 15:02:44 -07003210 session_->Close();
3211 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3212 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3213 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3214 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003215}
3216
3217// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3218TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3219 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003220 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003221
Donald Curtis0e209b02015-03-24 09:29:54 -07003222 PeerConnectionInterface::RTCOfferAnswerOptions options;
3223 options.use_rtp_mux = true;
3224
3225 SessionDescriptionInterface* offer = CreateOffer(options);
3226 SetLocalDescriptionWithoutError(offer);
3227
deadbeefcbecd352015-09-23 11:50:27 -07003228 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3229 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003230
deadbeefab9b2d12015-10-14 11:33:11 -07003231 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003232
3233 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003234 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235 CreateRemoteAnswer(session_->local_description()));
3236 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3237 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3238 JsepSessionDescription* modified_answer =
3239 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3240 modified_answer->Initialize(answer_copy, "1", "1");
3241 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
deadbeefcbecd352015-09-23 11:50:27 -07003243 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3244 session_->video_rtp_transport_channel());
3245}
3246
3247// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3248TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3249 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003250 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003251
3252 SessionDescriptionInterface* offer = CreateRemoteOffer();
3253 SetRemoteDescriptionWithoutError(offer);
3254
3255 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3256 session_->video_rtp_transport_channel());
3257
deadbeefab9b2d12015-10-14 11:33:11 -07003258 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003259 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003260 SetLocalDescriptionWithoutError(answer);
3261
3262 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3263 session_->video_rtp_transport_channel());
3264}
3265
3266// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3267TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3268 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003270
3271 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003272 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003273 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3274 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3275 JsepSessionDescription* modified_offer =
3276 new JsepSessionDescription(JsepSessionDescription::kOffer);
3277 modified_offer->Initialize(offer_copy, "1", "1");
3278
3279 // Expect an error when applying the remote description
3280 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3281 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003282}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283
Peter Thatcher4eddf182015-04-30 10:55:59 -07003284// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003285TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3286 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003287 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288
Donald Curtis0e209b02015-03-24 09:29:54 -07003289 PeerConnectionInterface::RTCOfferAnswerOptions options;
3290 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
Donald Curtis0e209b02015-03-24 09:29:54 -07003292 SessionDescriptionInterface* offer = CreateOffer(options);
3293 SetLocalDescriptionWithoutError(offer);
3294
deadbeefcbecd352015-09-23 11:50:27 -07003295 EXPECT_NE(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003297
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003299 SessionDescriptionInterface* answer =
3300 CreateRemoteAnswer(session_->local_description());
3301 SetRemoteDescriptionWithoutError(answer);
3302
3303 // This should lead to an audio-only call but isn't implemented
3304 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003305 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3306 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003307}
3308
deadbeefcbecd352015-09-23 11:50:27 -07003309// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003310TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3311 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003312 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003313 PeerConnectionInterface::RTCOfferAnswerOptions options;
3314 options.use_rtp_mux = true;
3315
3316 SessionDescriptionInterface* offer = CreateOffer(options);
3317 SetLocalDescriptionWithoutError(offer);
3318
deadbeefcbecd352015-09-23 11:50:27 -07003319 EXPECT_NE(session_->voice_rtp_transport_channel(),
3320 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003321
deadbeefab9b2d12015-10-14 11:33:11 -07003322 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003323
3324 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003325 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003326 CreateRemoteAnswer(session_->local_description()));
3327 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3328 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3329 JsepSessionDescription* modified_answer =
3330 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3331 modified_answer->Initialize(answer_copy, "1", "1");
3332 SetRemoteDescriptionWithoutError(modified_answer); //
3333
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_NE(session_->voice_rtp_transport_channel(),
3335 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336}
3337
Peter Thatcher4eddf182015-04-30 10:55:59 -07003338// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3339TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3340 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003341 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003342
3343 PeerConnectionInterface::RTCOfferAnswerOptions options;
3344 options.use_rtp_mux = true;
3345
3346 SessionDescriptionInterface* offer = CreateOffer(options);
3347 SetRemoteDescriptionWithoutError(offer);
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3350 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003351}
3352
skvlad6c87a672016-05-17 17:49:52 -07003353// Adding a new channel to a BUNDLE which is already connected should directly
3354// assign the bundle transport to the channel, without first setting a
3355// disconnected non-bundle transport and then replacing it. The application
3356// should not receive any changes in the ICE state.
3357TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3358 LoopbackNetworkConfiguration config;
3359 LoopbackNetworkManager loopback_network_manager(this, config);
3360 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3361 // connected. Disabling either of these two means that we need to wait for the
3362 // answer to find out if more transports are needed.
3363 configuration_.bundle_policy =
3364 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003365 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07003366 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003367
3368 // Negotiate an audio channel with MAX_BUNDLE enabled.
3369 SendAudioOnlyStream2();
3370 SessionDescriptionInterface* offer = CreateOffer();
3371 SetLocalDescriptionWithoutError(offer);
3372 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3373 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3374 std::string sdp;
3375 offer->ToString(&sdp);
3376 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3377 JsepSessionDescription::kAnswer, sdp, nullptr);
3378 ASSERT_TRUE(answer != NULL);
3379 SetRemoteDescriptionWithoutError(answer);
3380
3381 // Wait for the ICE state to stabilize.
3382 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3383 observer_.ice_connection_state_, kIceCandidatesTimeout);
3384 observer_.ice_connection_state_history_.clear();
3385
3386 // Now add a video channel which should be using the same bundle transport.
3387 SendAudioVideoStream2();
3388 offer = CreateOffer();
3389 offer->ToString(&sdp);
3390 SetLocalDescriptionWithoutError(offer);
3391 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3392 sdp, nullptr);
3393 ASSERT_TRUE(answer != NULL);
3394 SetRemoteDescriptionWithoutError(answer);
3395
3396 // Wait for ICE state to stabilize
3397 rtc::Thread::Current()->ProcessMessages(0);
3398 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3399 observer_.ice_connection_state_, kIceCandidatesTimeout);
3400
3401 // No ICE state changes are expected to happen.
3402 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3403}
3404
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003405TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3406 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003407 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408
3409 PeerConnectionInterface::RTCOfferAnswerOptions options;
3410 SessionDescriptionInterface* offer = CreateOffer(options);
3411 SetLocalDescriptionWithoutError(offer);
3412
deadbeefcbecd352015-09-23 11:50:27 -07003413 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3414 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003415
deadbeefab9b2d12015-10-14 11:33:11 -07003416 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003417 SessionDescriptionInterface* answer =
3418 CreateRemoteAnswer(session_->local_description());
3419 SetRemoteDescriptionWithoutError(answer);
3420
deadbeefcbecd352015-09-23 11:50:27 -07003421 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3422 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003423}
3424
3425TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3426 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003427 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003428
3429 PeerConnectionInterface::RTCOfferAnswerOptions options;
3430 SessionDescriptionInterface* offer = CreateOffer(options);
3431 SetLocalDescriptionWithoutError(offer);
3432
deadbeefcbecd352015-09-23 11:50:27 -07003433 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3434 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003435
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003437 SessionDescriptionInterface* answer =
3438 CreateRemoteAnswer(session_->local_description());
3439 SetRemoteDescriptionWithoutError(answer);
3440
deadbeefcbecd352015-09-23 11:50:27 -07003441 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3442 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003443}
3444
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003445// This test verifies that SetLocalDescription and SetRemoteDescription fails
3446// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3447TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003448 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003449 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003450
3451 PeerConnectionInterface::RTCOfferAnswerOptions options;
3452 options.use_rtp_mux = true;
3453
3454 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003455 std::string offer_str;
3456 offer->ToString(&offer_str);
3457 // Disable rtcp-mux
3458 const std::string rtcp_mux = "rtcp-mux";
3459 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003460 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003461 xrtcp_mux.c_str(), xrtcp_mux.length(),
3462 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003463 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003464 new JsepSessionDescription(JsepSessionDescription::kOffer);
3465 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003466 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003467 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003468 new JsepSessionDescription(JsepSessionDescription::kOffer);
3469 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003470 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003471 // Trying unmodified SDP.
3472 SetLocalDescriptionWithoutError(offer);
3473}
3474
jbauchcb560652016-08-04 05:20:32 -07003475TEST_F(WebRtcSessionTest, SetSetupGcm) {
3476 InitWithGcm();
3477 SendAudioVideoStream1();
3478 CreateAndSetRemoteOfferAndLocalAnswer();
3479}
3480
deadbeefd59daf82015-10-14 15:02:44 -07003481// This test verifies the |initial_offerer| flag when session initiates the
3482// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003484 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003485 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003486 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3488 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003489 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003491 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492}
3493
deadbeefd59daf82015-10-14 15:02:44 -07003494// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003496 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003497 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SessionDescriptionInterface* offer = CreateRemoteOffer();
3499 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003500 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501
deadbeefd59daf82015-10-14 15:02:44 -07003502 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003504 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505}
3506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3508TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003509 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003510 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003511 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003513 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 CreateRemoteAnswer(session_->local_description()));
3515
3516 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3517 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003518 JsepSessionDescription* modified_answer =
3519 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520
3521 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3522 answer->session_id(),
3523 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003524 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525
wu@webrtc.org4e393072014-04-07 17:04:35 +00003526 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527 std::string sdp;
3528 EXPECT_TRUE(answer->ToString(&sdp));
3529 const std::string kAudioMid = "a=mid:audio";
3530 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003531 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532 kAudioMidReplaceStr.c_str(),
3533 kAudioMidReplaceStr.length(),
3534 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003535 SessionDescriptionInterface* modified_answer1 =
3536 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003537 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538
wu@webrtc.org4e393072014-04-07 17:04:35 +00003539 // Different media types.
3540 EXPECT_TRUE(answer->ToString(&sdp));
3541 const std::string kAudioMline = "m=audio";
3542 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003543 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003544 kAudioMlineReplaceStr.c_str(),
3545 kAudioMlineReplaceStr.length(),
3546 &sdp);
3547 SessionDescriptionInterface* modified_answer2 =
3548 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3549 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3550
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551 SetRemoteDescriptionWithoutError(answer.release());
3552}
3553
3554// Verifying remote offer and local answer have matching m-lines as per
3555// RFC 3264.
3556TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003557 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003558 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 SessionDescriptionInterface* offer = CreateRemoteOffer();
3560 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003561 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562
3563 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3564 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003565 JsepSessionDescription* modified_answer =
3566 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567
3568 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3569 answer->session_id(),
3570 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003571 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 SetLocalDescriptionWithoutError(answer);
3573}
3574
3575// This test verifies that WebRtcSession does not start candidate allocation
3576// before SetLocalDescription is called.
3577TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003578 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003579 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 SessionDescriptionInterface* offer = CreateRemoteOffer();
3581 cricket::Candidate candidate;
3582 candidate.set_component(1);
3583 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3584 candidate);
3585 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3586 cricket::Candidate candidate1;
3587 candidate1.set_component(1);
3588 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3589 candidate1);
3590 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3591 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003592 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3593 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
3595 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003596 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3598 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3599
htaa2a49d92016-03-04 02:51:39 -08003600 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3603}
3604
3605// This test verifies that crypto parameter is updated in local session
3606// description as per security policy set in MediaSessionDescriptionFactory.
3607TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003608 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003609 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003610 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
3612 // Making sure SetLocalDescription correctly sets crypto value in
3613 // SessionDescription object after de-serialization of sdp string. The value
3614 // will be set as per MediaSessionDescriptionFactory.
3615 std::string offer_str;
3616 offer->ToString(&offer_str);
3617 SessionDescriptionInterface* jsep_offer_str =
3618 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3619 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003620 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3621 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003622}
3623
3624// This test verifies the crypto parameter when security is disabled.
3625TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003626 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003627 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003628 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003629 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630
3631 // Making sure SetLocalDescription correctly sets crypto value in
3632 // SessionDescription object after de-serialization of sdp string. The value
3633 // will be set as per MediaSessionDescriptionFactory.
3634 std::string offer_str;
3635 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003636 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3638 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003639 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3640 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641}
3642
3643// This test verifies that an answer contains new ufrag and password if an offer
3644// with new ufrag and password is received.
3645TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003646 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003647 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003648 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003649 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 SetRemoteDescriptionWithoutError(offer.release());
3651
deadbeefab9b2d12015-10-14 11:33:11 -07003652 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003653 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003654 SetLocalDescriptionWithoutError(answer.release());
3655
3656 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003657 for (const cricket::ContentInfo& content :
3658 session_->local_description()->description()->contents()) {
3659 options.transport_options[content.name].ice_restart = true;
3660 }
kwibergd1fe2812016-04-27 06:47:29 -07003661 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003662 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SetRemoteDescriptionWithoutError(updated_offer1.release());
3664
kwibergd1fe2812016-04-27 06:47:29 -07003665 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666
deadbeef0ed85b22016-02-23 17:24:52 -08003667 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3668 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669
deadbeef0ed85b22016-02-23 17:24:52 -08003670 // Even a second answer (created before the description is set) should have
3671 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003672 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003673
3674 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3675 session_->local_description()->description()));
3676
3677 SetLocalDescriptionWithoutError(updated_answer2.release());
3678}
3679
3680// This test verifies that an answer contains new ufrag and password if an offer
3681// that changes either the ufrag or password (but not both) is received.
3682// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3683// a=ice-pwd attributes compared to the previous SDP from the peer, it
3684// indicates that ICE is restarting for this media stream."
3685TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3686 Init();
3687 cricket::MediaSessionOptions options;
3688 options.recv_audio = true;
3689 options.recv_video = true;
3690 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003691 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003692 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3693 SetRemoteDescriptionWithoutError(offer.release());
3694
3695 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003696 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003697 SetLocalDescriptionWithoutError(answer.release());
3698
3699 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003700 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003701 CreateRemoteOffer(options, session_->remote_description()));
3702 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3703 "original_password12345");
3704 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3705
kwibergd1fe2812016-04-27 06:47:29 -07003706 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003707 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3708 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003710
3711 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003712 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003713 CreateRemoteOffer(options, session_->remote_description()));
3714 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3715 "modified_password12345");
3716 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3717
kwibergd1fe2812016-04-27 06:47:29 -07003718 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003719 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3720 session_->local_description()->description()));
3721 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003722}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723
wu@webrtc.org91053e72013-08-10 07:18:04 +00003724// This test verifies that an answer contains old ufrag and password if an offer
3725// with old ufrag and password is received.
3726TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003727 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003729 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003730 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003731 SetRemoteDescriptionWithoutError(offer.release());
3732
deadbeefab9b2d12015-10-14 11:33:11 -07003733 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735 SetLocalDescriptionWithoutError(answer.release());
3736
3737 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003739 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 SetRemoteDescriptionWithoutError(updated_offer2.release());
3741
kwibergd1fe2812016-04-27 06:47:29 -07003742 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
deadbeef0ed85b22016-02-23 17:24:52 -08003744 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3745 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
3747 SetLocalDescriptionWithoutError(updated_answer2.release());
3748}
3749
deadbeef0ed85b22016-02-23 17:24:52 -08003750// This test verifies that if an offer does an ICE restart on some, but not all
3751// media sections, the answer will change the ufrag/password in the correct
3752// media sections.
3753TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3754 Init();
3755 cricket::MediaSessionOptions options;
3756 options.recv_video = true;
3757 options.recv_audio = true;
3758 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003759 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003760
3761 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3762 "aaaaaaaaaaaaaaaaaaaaaa");
3763 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3764 "bbbbbbbbbbbbbbbbbbbbbb");
3765 SetRemoteDescriptionWithoutError(offer.release());
3766
3767 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003768 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003769 SetLocalDescriptionWithoutError(answer.release());
3770
3771 // Receive an offer with new ufrag and password, but only for the video media
3772 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003773 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003774 CreateRemoteOffer(options, session_->remote_description()));
3775 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3776 "cccccccccccccccccccccc");
3777 SetRemoteDescriptionWithoutError(updated_offer.release());
3778
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003780
3781 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3782 session_->local_description()->description(),
3783 cricket::MEDIA_TYPE_AUDIO));
3784
3785 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3786 session_->local_description()->description(),
3787 cricket::MEDIA_TYPE_VIDEO));
3788
3789 SetLocalDescriptionWithoutError(updated_answer.release());
3790}
3791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003792TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003793 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003794 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003795 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796 const std::string session_id_orig = offer->session_id();
3797 const std::string session_version_orig = offer->session_version();
3798 SetLocalDescriptionWithoutError(offer);
3799
3800 video_channel_ = media_engine_->GetVideoChannel(0);
3801 video_channel_->set_fail_set_send_codecs(true);
3802
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003803 SessionDescriptionInterface* answer =
3804 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003805 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003806
3807 // Test that after a content error, setting any description will
3808 // result in an error.
3809 video_channel_->set_fail_set_send_codecs(false);
3810 answer = CreateRemoteAnswer(session_->local_description());
3811 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3812 offer = CreateRemoteOffer();
3813 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814}
3815
3816// Runs the loopback call test with BUNDLE and STUN disabled.
3817TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3818 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003819 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003820 cricket::PORTALLOCATOR_DISABLE_STUN |
3821 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003822 TestLoopbackCall();
3823}
3824
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003825TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003826 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003827 cricket::PORTALLOCATOR_DISABLE_STUN |
3828 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3829 cricket::PORTALLOCATOR_DISABLE_RELAY);
3830
3831 // best connection is IPv6 since it has higher network preference.
3832 LoopbackNetworkConfiguration config;
3833 config.test_ipv6_network_ = true;
3834 config.best_connection_after_initial_ice_converged_ =
3835 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3836
3837 TestLoopbackCall(config);
3838}
3839
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003840// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003841TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003842 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3843 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003844 TestLoopbackCall();
3845}
3846
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003847TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003848 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003849 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003851 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003852 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003853}
3854
Henrik Boström87713d02015-08-25 09:53:21 +02003855TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003856 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003857 options_.disable_sctp_data_channels = false;
3858
Henrik Boström87713d02015-08-25 09:53:21 +02003859 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003860
3861 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003862 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3863}
3864
3865// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3866// before and after BUNDLE is negotiated.
3867TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003868 SetFactoryDtlsSrtp();
3869 InitWithDtls(GetParam());
3870
3871 // Initially these fields should be empty.
3872 EXPECT_FALSE(session_->sctp_content_name());
3873 EXPECT_FALSE(session_->sctp_transport_name());
3874
3875 // Create offer with audio/video/data.
3876 // Default bundle policy is "balanced", so data should be using its own
3877 // transport.
3878 SendAudioVideoStream1();
3879 CreateDataChannel();
3880 InitiateCall();
3881 ASSERT_TRUE(session_->sctp_content_name());
3882 ASSERT_TRUE(session_->sctp_transport_name());
3883 EXPECT_EQ("data", *session_->sctp_content_name());
3884 EXPECT_EQ("data", *session_->sctp_transport_name());
3885
3886 // Create answer that finishes BUNDLE negotiation, which means everything
3887 // should be bundled on the first transport (audio).
3888 cricket::MediaSessionOptions answer_options;
3889 answer_options.recv_video = true;
3890 answer_options.bundle_enabled = true;
3891 answer_options.data_channel_type = cricket::DCT_SCTP;
3892 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3893 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3894 ASSERT_TRUE(session_->sctp_content_name());
3895 ASSERT_TRUE(session_->sctp_transport_name());
3896 EXPECT_EQ("data", *session_->sctp_content_name());
3897 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003898}
3899
Henrik Boström87713d02015-08-25 09:53:21 +02003900TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003901 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003902
kwibergd1fe2812016-04-27 06:47:29 -07003903 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003904 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003905 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3906}
3907
Henrik Boström87713d02015-08-25 09:53:21 +02003908TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003909 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003910 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003911
3912 // Create remote offer with SCTP.
3913 cricket::MediaSessionOptions options;
3914 options.data_channel_type = cricket::DCT_SCTP;
3915 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003916 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003917 SetRemoteDescriptionWithoutError(offer);
3918
3919 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003920 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003921 EXPECT_TRUE(answer != NULL);
3922 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3923 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003924}
3925
deadbeef953c2ce2017-01-09 14:53:41 -08003926// Test that if DTLS is disabled, we don't end up with an SctpTransport
3927// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003928TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003929 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003930 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003931
3932 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003933 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3934 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003935}
3936
deadbeef953c2ce2017-01-09 14:53:41 -08003937// Test that if DTLS is enabled, we end up with an SctpTransport created
3938// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003939TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003940 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003941
3942 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003943 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3944 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003945}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946
deadbeef953c2ce2017-01-09 14:53:41 -08003947// Test that if SCTP is disabled, we don't end up with an SctpTransport
3948// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003949TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003950 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003951 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003952
3953 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003954 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3955 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003956}
3957
Henrik Boström87713d02015-08-25 09:53:21 +02003958TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003959 const int new_send_port = 9998;
3960 const int new_recv_port = 7775;
3961
Henrik Boström87713d02015-08-25 09:53:21 +02003962 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003963 SetFactoryDtlsSrtp();
3964
3965 // By default, don't actually add the codecs to desc_factory_; they don't
3966 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3967 // let the session description get parsed. That'll get the proper codecs
3968 // into the stream.
3969 cricket::MediaSessionOptions options;
3970 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3971 "stream1", new_send_port, options);
3972
3973 // SetRemoteDescription will take the ownership of the offer.
3974 SetRemoteDescriptionWithoutError(offer);
3975
htaa2a49d92016-03-04 02:51:39 -08003976 SessionDescriptionInterface* answer =
3977 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003978 ASSERT_TRUE(answer != NULL);
3979
3980 // Now set the local description, which'll take ownership of the answer.
3981 SetLocalDescriptionWithoutError(answer);
3982
3983 // TEST PLAN: Set the port number to something new, set it in the SDP,
3984 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003985 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003986 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003987 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3988 EXPECT_EQ(
3989 new_recv_port,
3990 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3991 EXPECT_EQ(
3992 new_send_port,
3993 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003994}
3995
deadbeef953c2ce2017-01-09 14:53:41 -08003996// Verifies that when a session's SctpTransport receives an OPEN message,
3997// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07003998// config.
3999TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004000 InitWithDtls(GetParam());
4001
4002 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004003 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4004 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004005
deadbeef953c2ce2017-01-09 14:53:41 -08004006 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004007 webrtc::DataChannelInit config;
4008 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004009 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004010 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4011 cricket::ReceiveDataParams params;
4012 params.ssrc = config.id;
4013 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004014 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4015 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004016
deadbeef953c2ce2017-01-09 14:53:41 -08004017 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004018 EXPECT_EQ(config.id, last_data_channel_config_.id);
4019 EXPECT_FALSE(last_data_channel_config_.negotiated);
4020 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4021 last_data_channel_config_.open_handshake_role);
4022}
4023
4024TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004025 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004026 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004027
htaa2a49d92016-03-04 02:51:39 -08004028 configuration_.certificates.push_back(certificate);
4029 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004030 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4031
4032 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4033}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004034
Henrik Boström87713d02015-08-25 09:53:21 +02004035// Verifies that CreateOffer succeeds when CreateOffer is called before async
4036// identity generation is finished (even if a certificate is provided this is
4037// an async op).
4038TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004039 InitWithDtls(GetParam());
4040
Henrik Boströmd8281982015-08-27 10:12:24 +02004041 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004042 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004043 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004044
wu@webrtc.org91053e72013-08-10 07:18:04 +00004045 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004046 VerifyNoCryptoParams(offer->description(), true);
4047 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048}
4049
4050// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004051// identity generation is finished (even if a certificate is provided this is
4052// an async op).
4053TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004054 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004055 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056
4057 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004058 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004059 std::unique_ptr<JsepSessionDescription> offer(
4060 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061 ASSERT_TRUE(offer.get() != NULL);
4062 SetRemoteDescriptionWithoutError(offer.release());
4063
kwibergd1fe2812016-04-27 06:47:29 -07004064 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004066 VerifyNoCryptoParams(answer->description(), true);
4067 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068}
4069
4070// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004071// identity generation is finished (even if a certificate is provided this is
4072// an async op).
4073TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004074 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004075
Henrik Boströmd8281982015-08-27 10:12:24 +02004076 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004077
kwibergd1fe2812016-04-27 06:47:29 -07004078 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004079 EXPECT_TRUE(offer != NULL);
4080}
4081
4082// Verifies that CreateOffer fails when CreateOffer is called after async
4083// identity generation fails.
4084TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004085 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004086
Henrik Boströmd8281982015-08-27 10:12:24 +02004087 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004088
kwibergd1fe2812016-04-27 06:47:29 -07004089 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004090 EXPECT_TRUE(offer == NULL);
4091}
4092
4093// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4094// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004095TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004096 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004097 VerifyMultipleAsyncCreateDescription(GetParam(),
4098 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099}
4100
4101// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4102// before async identity generation fails.
4103TEST_F(WebRtcSessionTest,
4104 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004105 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4106 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004107}
4108
4109// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4110// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004111TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004112 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004113 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004114 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115}
4116
4117// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4118// before async identity generation fails.
4119TEST_F(WebRtcSessionTest,
4120 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004121 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4122 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004123}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004124
4125// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4126// offer has no SDES crypto but only DTLS fingerprint.
4127TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4128 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004129 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004130 // Create a remote offer with secured transport disabled.
4131 cricket::MediaSessionOptions options;
4132 JsepSessionDescription* offer(CreateRemoteOffer(
4133 options, cricket::SEC_DISABLED));
4134 // Adds a DTLS fingerprint to the remote offer.
4135 cricket::SessionDescription* sdp = offer->description();
4136 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4137 ASSERT_TRUE(audio != NULL);
4138 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4139 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 rtc::SSLFingerprint::CreateFromRfc4572(
4141 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004142 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004143 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004144}
4145
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004146TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004147 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004148 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004149 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004150 SessionDescriptionInterface* offer = CreateOffer();
4151
4152 SetLocalDescriptionWithoutError(offer);
4153
4154 voice_channel_ = media_engine_->GetVoiceChannel(0);
4155
4156 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004157 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004158 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004159}
4160
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004161// Tests that we can renegotiate new media content with ICE candidates in the
4162// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004163TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004164 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004165 SetFactoryDtlsSrtp();
4166
deadbeefab9b2d12015-10-14 11:33:11 -07004167 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004168 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169 SetLocalDescriptionWithoutError(offer);
4170
4171 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4172 SetRemoteDescriptionWithoutError(answer);
4173
4174 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004175 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4177
4178 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004179 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004180 candidate1.set_component(1);
4181 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4182 candidate1);
4183 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4184 SetRemoteDescriptionWithoutError(offer);
4185
htaa2a49d92016-03-04 02:51:39 -08004186 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004187 SetLocalDescriptionWithoutError(answer);
4188}
4189
4190// Tests that we can renegotiate new media content with ICE candidates separated
4191// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004192TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004193 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004194 SetFactoryDtlsSrtp();
4195
deadbeefab9b2d12015-10-14 11:33:11 -07004196 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004197 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004198 SetLocalDescriptionWithoutError(offer);
4199
4200 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4201 SetRemoteDescriptionWithoutError(answer);
4202
4203 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004204 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004205 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4206 SetRemoteDescriptionWithoutError(offer);
4207
4208 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004209 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004210 candidate1.set_component(1);
4211 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4212 candidate1);
4213 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4214
htaa2a49d92016-03-04 02:51:39 -08004215 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004216 SetLocalDescriptionWithoutError(answer);
4217}
honghaiz7f777492016-02-02 21:54:01 -08004218
zhihuang9763d562016-08-05 11:14:50 -07004219#ifdef HAVE_QUIC
4220TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4221 configuration_.enable_quic = true;
4222 InitWithDtls(GetParam());
4223 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4224 SessionDescriptionInterface* offer = CreateOffer();
4225 ASSERT_TRUE(offer);
4226 ASSERT_TRUE(offer->description());
4227 SetLocalDescriptionWithoutError(offer);
4228 cricket::MediaSessionOptions options;
4229 options.recv_audio = true;
4230 options.recv_video = true;
4231 SessionDescriptionInterface* answer =
4232 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4233 ASSERT_TRUE(answer);
4234 ASSERT_TRUE(answer->description());
4235 SetRemoteDescriptionWithoutError(answer);
4236}
4237#endif // HAVE_QUIC
4238
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004239// Tests that RTX codec is removed from the answer when it isn't supported
4240// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004241TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004243 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004244 std::string offer_sdp(kSdpWithRtx);
4245
4246 SessionDescriptionInterface* offer =
4247 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4248 EXPECT_TRUE(offer->ToString(&offer_sdp));
4249
4250 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004251 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004252 SetRemoteDescriptionWithoutError(offer);
4253
htaa2a49d92016-03-04 02:51:39 -08004254 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004255 // Answer SDP does not contain the RTX codec.
4256 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004257 SetLocalDescriptionWithoutError(answer);
4258}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004259
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004260// This verifies that the voice channel after bundle has both options from video
4261// and voice channels.
4262TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4263 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004264 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004265
4266 PeerConnectionInterface::RTCOfferAnswerOptions options;
4267 options.use_rtp_mux = true;
4268
4269 SessionDescriptionInterface* offer = CreateOffer(options);
4270 SetLocalDescriptionWithoutError(offer);
4271
4272 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4273 rtc::Socket::Option::OPT_SNDBUF, 4000);
4274
4275 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4276 rtc::Socket::Option::OPT_RCVBUF, 8000);
4277
4278 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004279 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004280 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4281 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004282 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004283 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4284
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4287 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004288 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004289 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4290
deadbeefcbecd352015-09-23 11:50:27 -07004291 EXPECT_NE(session_->voice_rtp_transport_channel(),
4292 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004293
deadbeefab9b2d12015-10-14 11:33:11 -07004294 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004295 SessionDescriptionInterface* answer =
4296 CreateRemoteAnswer(session_->local_description());
4297 SetRemoteDescriptionWithoutError(answer);
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004300 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4301 EXPECT_EQ(4000, option_val);
4302
deadbeefcbecd352015-09-23 11:50:27 -07004303 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004304 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4305 EXPECT_EQ(8000, option_val);
4306}
4307
tommi0f620f42015-07-09 03:25:02 -07004308// Test creating a session, request multiple offers, destroy the session
4309// and make sure we got success/failure callbacks for all of the requests.
4310// Background: crbug.com/507307
4311TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4312 Init();
4313
4314 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4315 PeerConnectionInterface::RTCOfferAnswerOptions options;
4316 options.offer_to_receive_audio =
4317 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004318 cricket::MediaSessionOptions session_options;
4319 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004320
4321 for (auto& o : observers) {
4322 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004323 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004324 }
4325
4326 session_.reset();
4327
tommi0f620f42015-07-09 03:25:02 -07004328 for (auto& o : observers) {
4329 // We expect to have received a notification now even if the session was
4330 // terminated. The offer creation may or may not have succeeded, but we
4331 // must have received a notification which, so the only invalid state
4332 // is kInit.
4333 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4334 }
4335}
4336
stefanc1aeaf02015-10-15 07:26:07 -07004337TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4338 TestPacketOptions();
4339}
4340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004341// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4342// currently fails because upon disconnection and reconnection OnIceComplete is
4343// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004344
deadbeefcbecd352015-09-23 11:50:27 -07004345INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4346 WebRtcSessionTest,
4347 testing::Values(ALREADY_GENERATED,
4348 DTLS_IDENTITY_STORE));