blob: 497daffc32f11b10cbe021f790c46ca2c643ce00 [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"
skvlad11a9cbf2016-10-07 11:53:05 -070018#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/fakemediaengine.h"
20#include "webrtc/media/base/fakevideorenderer.h"
21#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010022#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080023#include "webrtc/media/sctp/sctptransportinternal.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080024#include "webrtc/p2p/base/packettransportinternal.h"
kjellandera96e2d72016-02-04 23:52:28 -080025#include "webrtc/p2p/base/stunserver.h"
26#include "webrtc/p2p/base/teststunserver.h"
27#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080028#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010030#include "webrtc/pc/channelmanager.h"
31#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080032#include "webrtc/pc/peerconnection.h"
33#include "webrtc/pc/sctputils.h"
34#include "webrtc/pc/test/fakertccertificategenerator.h"
35#include "webrtc/pc/videotrack.h"
36#include "webrtc/pc/webrtcsession.h"
37#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020038#include "webrtc/rtc_base/checks.h"
39#include "webrtc/rtc_base/fakenetwork.h"
40#include "webrtc/rtc_base/firewallsocketserver.h"
41#include "webrtc/rtc_base/gunit.h"
42#include "webrtc/rtc_base/logging.h"
43#include "webrtc/rtc_base/network.h"
44#include "webrtc/rtc_base/ssladapter.h"
45#include "webrtc/rtc_base/sslidentity.h"
46#include "webrtc/rtc_base/sslstreamadapter.h"
47#include "webrtc/rtc_base/stringutils.h"
48#include "webrtc/rtc_base/thread.h"
49#include "webrtc/rtc_base/virtualsocketserver.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;
Zhi Huang2a5e4262017-09-14 01:15:03 -070073using webrtc::kMlineMismatchInAnswer;
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
zhihuang1c378ed2017-08-17 14:10:50 -0700146static constexpr bool kStopped = true;
147static constexpr bool kActive = false;
148
Henrik Boström87713d02015-08-25 09:53:21 +0200149enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
150
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151class MockIceObserver : public webrtc::IceObserver {
152 public:
153 MockIceObserver()
154 : oncandidatesready_(false),
155 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
156 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
157 }
158
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200159 virtual ~MockIceObserver() = default;
160
zstein6dfd53a2017-03-06 13:49:03 -0800161 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800162 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700164 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 }
perkjdfb769d2016-02-09 03:09:43 -0800166 void OnIceGatheringChange(
167 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 // We can never transition back to "new".
169 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
170 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800171 oncandidatesready_ =
172 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174
175 // Found a new candidate.
jbauch81bf7b02017-03-25 08:31:12 -0700176 void OnIceCandidate(
177 std::unique_ptr<webrtc::IceCandidateInterface> candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 switch (candidate->sdp_mline_index()) {
179 case kMediaContentIndex0:
180 mline_0_candidates_.push_back(candidate->candidate());
181 break;
182 case kMediaContentIndex1:
183 mline_1_candidates_.push_back(candidate->candidate());
184 break;
185 default:
nissec80e7412017-01-11 05:56:46 -0800186 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // The ICE gathering state should always be Gathering when a candidate is
190 // received (or possibly Completed in the case of the final candidate).
191 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
192 }
193
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 // Some local candidates are removed.
195 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700196 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 num_candidates_removed_ += candidates.size();
198 }
199
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 bool oncandidatesready_;
201 std::vector<cricket::Candidate> mline_0_candidates_;
202 std::vector<cricket::Candidate> mline_1_candidates_;
203 PeerConnectionInterface::IceConnectionState ice_connection_state_;
204 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700205 std::vector<PeerConnectionInterface::IceConnectionState>
206 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700207 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208};
209
deadbeef953c2ce2017-01-09 14:53:41 -0800210// Used for tests in this file to verify that WebRtcSession responds to signals
211// from the SctpTransport correctly, and calls Start with the correct
212// local/remote ports.
213class FakeSctpTransport : public cricket::SctpTransportInternal {
214 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800215 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800216 bool Start(int local_port, int remote_port) override {
217 local_port_ = local_port;
218 remote_port_ = remote_port;
219 return true;
220 }
221 bool OpenStream(int sid) override { return true; }
222 bool ResetStream(int sid) override { return true; }
223 bool SendData(const cricket::SendDataParams& params,
224 const rtc::CopyOnWriteBuffer& payload,
225 cricket::SendDataResult* result = nullptr) override {
226 return true;
227 }
228 bool ReadyToSendData() override { return true; }
229 void set_debug_name_for_testing(const char* debug_name) override {}
230
231 int local_port() const { return local_port_; }
232 int remote_port() const { return remote_port_; }
233
234 private:
235 int local_port_ = -1;
236 int remote_port_ = -1;
237};
238
239class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
240 public:
241 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800242 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800243 last_fake_sctp_transport_ = new FakeSctpTransport();
244 return std::unique_ptr<cricket::SctpTransportInternal>(
245 last_fake_sctp_transport_);
246 }
247
248 FakeSctpTransport* last_fake_sctp_transport() {
249 return last_fake_sctp_transport_;
250 }
251
252 private:
253 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
254};
255
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256class WebRtcSessionForTest : public webrtc::WebRtcSession {
257 public:
zhihuang29ff8442016-07-27 11:07:25 -0700258 WebRtcSessionForTest(
nisseeaabdf62017-05-05 02:23:02 -0700259 webrtc::Call* fake_call,
260 cricket::ChannelManager* channel_manager,
261 const cricket::MediaConfig& media_config,
262 webrtc::RtcEventLog* event_log,
zhihuang29ff8442016-07-27 11:07:25 -0700263 rtc::Thread* network_thread,
264 rtc::Thread* worker_thread,
265 rtc::Thread* signaling_thread,
266 cricket::PortAllocator* port_allocator,
267 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800268 std::unique_ptr<cricket::TransportController> transport_controller,
269 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
nisseeaabdf62017-05-05 02:23:02 -0700270 : WebRtcSession(fake_call, channel_manager, media_config, event_log,
danilchape9021a32016-05-17 01:52:02 -0700271 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700272 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700273 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700274 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800275 std::move(transport_controller),
276 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 RegisterIceObserver(ice_observer);
278 }
279 virtual ~WebRtcSessionForTest() {}
280
deadbeefcbecd352015-09-23 11:50:27 -0700281 // Note that these methods are only safe to use if the signaling thread
282 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800283 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700284 return rtp_transport_channel(voice_channel());
285 }
286
deadbeef5bd5ca32017-02-10 11:31:50 -0800287 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700288 return rtcp_transport_channel(voice_channel());
289 }
290
deadbeef5bd5ca32017-02-10 11:31:50 -0800291 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return rtp_transport_channel(video_channel());
293 }
294
deadbeef5bd5ca32017-02-10 11:31:50 -0800295 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700296 return rtcp_transport_channel(video_channel());
297 }
298
deadbeefcbecd352015-09-23 11:50:27 -0700299 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800300 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800301 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700302 if (!ch) {
303 return nullptr;
304 }
zhihuangb2cdd932017-01-19 16:54:25 -0800305 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700306 }
307
deadbeef5bd5ca32017-02-10 11:31:50 -0800308 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800309 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700310 if (!ch) {
311 return nullptr;
312 }
zhihuangb2cdd932017-01-19 16:54:25 -0800313 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700314 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315};
316
wu@webrtc.org91053e72013-08-10 07:18:04 +0000317class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000318 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000320 enum State {
321 kInit,
322 kFailed,
323 kSucceeded,
324 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000325 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000326
327 // CreateSessionDescriptionObserver implementation.
328 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000329 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000330 state_ = kSucceeded;
331 }
332 virtual void OnFailure(const std::string& error) {
333 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
335
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000336 SessionDescriptionInterface* description() { return description_.get(); }
337
338 SessionDescriptionInterface* ReleaseDescription() {
339 return description_.release();
340 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
wu@webrtc.org91053e72013-08-10 07:18:04 +0000342 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343
wu@webrtc.org91053e72013-08-10 07:18:04 +0000344 protected:
345 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346
347 private:
kwibergd1fe2812016-04-27 06:47:29 -0700348 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000349 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350};
351
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800352class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000353 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800354 FakeAudioSource() : sink_(NULL) {}
355 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000356 if (sink_)
357 sink_->OnClose();
358 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000359
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000360 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000361
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800362 const cricket::AudioSource::Sink* sink() const { return sink_; }
363
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000364 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800365 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000366};
367
Henrik Boström87713d02015-08-25 09:53:21 +0200368class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700369 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
370 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 protected:
372 // TODO Investigate why ChannelManager crashes, if it's created
373 // after stun_server.
374 WebRtcSessionTest()
deadbeef98e186c2017-05-16 18:00:06 -0700375 : vss_(new rtc::VirtualSocketServer()),
nisse7eaa4ea2017-05-08 05:25:41 -0700376 fss_(new rtc::FirewallSocketServer(vss_.get())),
377 thread_(fss_.get()),
378 media_engine_(new cricket::FakeMediaEngine()),
stefanc1aeaf02015-10-15 07:26:07 -0700379 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800380 channel_manager_(new cricket::ChannelManager(
381 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
382 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
383 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700384 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700385 tdesc_factory_(new cricket::TransportDescriptionFactory()),
386 desc_factory_(
387 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
388 tdesc_factory_.get())),
stefanc1aeaf02015-10-15 07:26:07 -0700389 stun_socket_addr_(
390 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
391 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
392 stun_socket_addr_)),
393 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
394 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000395 cricket::ServerAddresses stun_servers;
396 stun_servers.insert(stun_socket_addr_);
397 allocator_.reset(new cricket::BasicPortAllocator(
398 &network_manager_,
399 stun_servers,
400 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000401 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700402 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 EXPECT_TRUE(channel_manager_->Init());
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000404 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
407 void AddInterface(const SocketAddress& addr) {
408 network_manager_.AddInterface(addr);
409 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700410 void RemoveInterface(const SocketAddress& addr) {
411 network_manager_.RemoveInterface(addr);
412 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413
Henrik Boströmd79599d2016-06-01 13:58:50 +0200414 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
415 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
416 // options. When DTLS is enabled a certificate will be used if provided,
417 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800419 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef7914b8c2017-04-21 03:23:33 -0700420 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy,
421 const rtc::CryptoOptions& crypto_options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800423 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
nisseeaabdf62017-05-05 02:23:02 -0700424 session_.reset(new WebRtcSessionForTest(&fake_call_,
425 channel_manager_.get(), cricket::MediaConfig(), &event_log_,
426 rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700427 rtc::Thread::Current(), allocator_.get(), &observer_,
428 std::unique_ptr<cricket::TransportController>(
deadbeef7914b8c2017-04-21 03:23:33 -0700429 new cricket::TransportController(
430 rtc::Thread::Current(), rtc::Thread::Current(),
431 allocator_.get(),
432 /*redetermine_role_on_ice_restart=*/true, crypto_options)),
deadbeef953c2ce2017-01-09 14:53:41 -0800433 std::unique_ptr<FakeSctpTransportFactory>(
434 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700435 session_->SignalDataChannelOpenMessage.connect(
436 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
zhihuang4dfb8ce2016-11-23 10:30:12 -0800438 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
440 observer_.ice_connection_state_);
441 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
442 observer_.ice_gathering_state_);
443
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200444 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800445 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700446 session_->set_metrics_observer(metrics_observer_);
deadbeef7914b8c2017-04-21 03:23:33 -0700447 crypto_options_ = crypto_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 }
449
deadbeefab9b2d12015-10-14 11:33:11 -0700450 void OnDataChannelOpenMessage(const std::string& label,
451 const InternalDataChannelInit& config) {
452 last_data_channel_label_ = label;
453 last_data_channel_config_ = config;
454 }
455
zhihuang4dfb8ce2016-11-23 10:30:12 -0800456 void Init() {
deadbeef7914b8c2017-04-21 03:23:33 -0700457 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
458 rtc::CryptoOptions());
zhihuang4dfb8ce2016-11-23 10:30:12 -0800459 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000460
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 void InitWithBundlePolicy(
462 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800463 configuration_.bundle_policy = bundle_policy;
464 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700465 }
466
467 void InitWithRtcpMuxPolicy(
468 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
469 PeerConnectionInterface::RTCConfiguration configuration;
deadbeef7914b8c2017-04-21 03:23:33 -0700470 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions());
471 }
472
473 void InitWithCryptoOptions(const rtc::CryptoOptions& crypto_options) {
474 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
475 crypto_options);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000476 }
477
Henrik Boström87713d02015-08-25 09:53:21 +0200478 // Successfully init with DTLS; with a certificate generated and supplied or
479 // with a store that generates it for us.
480 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200481 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200482 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800483 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200484 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200485 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200486 cert_generator.reset(new FakeRTCCertificateGenerator());
487 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200488 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700489 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200490 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800491 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700492 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
493 rtc::CryptoOptions());
Henrik Boström87713d02015-08-25 09:53:21 +0200494 }
495
496 // Init with DTLS with a store that will fail to generate a certificate.
497 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200498 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
499 new FakeRTCCertificateGenerator());
500 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800501 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700502 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
503 rtc::CryptoOptions());
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000504 }
505
jbauchcb560652016-08-04 05:20:32 -0700506 void InitWithGcm() {
507 rtc::CryptoOptions crypto_options;
508 crypto_options.enable_gcm_crypto_suites = true;
deadbeef7914b8c2017-04-21 03:23:33 -0700509 InitWithCryptoOptions(crypto_options);
jbauchcb560652016-08-04 05:20:32 -0700510 }
511
zhihuang1c378ed2017-08-17 14:10:50 -0700512 // The following convenience functions can be applied for both local side and
513 // remote side. The flags can be overwritten for different use cases.
deadbeefab9b2d12015-10-14 11:33:11 -0700514 void SendAudioVideoStream1() {
515 send_stream_1_ = true;
516 send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700517 local_send_audio_ = true;
518 local_send_video_ = true;
519 remote_send_audio_ = true;
520 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700521 }
522
523 void SendAudioVideoStream2() {
524 send_stream_1_ = false;
525 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700526 local_send_audio_ = true;
527 local_send_video_ = true;
528 remote_send_audio_ = true;
529 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700530 }
531
532 void SendAudioVideoStream1And2() {
533 send_stream_1_ = true;
534 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700535 local_send_audio_ = true;
536 local_send_video_ = true;
537 remote_send_audio_ = true;
538 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700539 }
540
541 void SendNothing() {
542 send_stream_1_ = false;
543 send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700544 local_send_audio_ = false;
545 local_send_video_ = false;
546 remote_send_audio_ = false;
547 remote_send_video_ = false;
deadbeefab9b2d12015-10-14 11:33:11 -0700548 }
549
550 void SendAudioOnlyStream2() {
551 send_stream_1_ = false;
552 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700553 local_send_audio_ = true;
554 local_send_video_ = false;
555 remote_send_audio_ = true;
556 remote_send_video_ = false;
deadbeefab9b2d12015-10-14 11:33:11 -0700557 }
558
559 void SendVideoOnlyStream2() {
560 send_stream_1_ = false;
561 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700562 local_send_audio_ = false;
563 local_send_video_ = true;
564 remote_send_audio_ = false;
565 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700566 }
567
zhihuang1c378ed2017-08-17 14:10:50 -0700568 // Helper function used to add a specific media section to the
569 // |session_options|.
570 void AddMediaSection(cricket::MediaType type,
571 const std::string& mid,
572 cricket::MediaContentDirection direction,
573 bool stopped,
574 cricket::MediaSessionOptions* opts) {
575 opts->media_description_options.push_back(cricket::MediaDescriptionOptions(
576 type, mid,
577 cricket::RtpTransceiverDirection::FromMediaContentDirection(direction),
578 stopped));
579 }
580
581 // Add the media sections to the options from |offered_media_sections_| when
582 // creating an answer or a new offer.
583 // This duplicates a lot of logic from PeerConnection but this can be fixed
584 // when PeerConnection and WebRtcSession are merged.
585 void AddExistingMediaSectionsAndSendersToOptions(
586 cricket::MediaSessionOptions* session_options,
587 bool send_audio,
588 bool recv_audio,
589 bool send_video,
590 bool recv_video) {
591 int num_sim_layer = 1;
592 for (auto media_description_options : offered_media_sections_) {
593 if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) {
594 bool stopped = !send_audio && !recv_audio;
595 auto media_desc_options = cricket::MediaDescriptionOptions(
596 cricket::MEDIA_TYPE_AUDIO, media_description_options.mid,
597 cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped);
598 if (send_stream_1_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700599 media_desc_options.AddAudioSender(kAudioTrack1, {kStream1});
zhihuang1c378ed2017-08-17 14:10:50 -0700600 }
601 if (send_stream_2_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700602 media_desc_options.AddAudioSender(kAudioTrack2, {kStream2});
zhihuang1c378ed2017-08-17 14:10:50 -0700603 }
604 session_options->media_description_options.push_back(
605 media_desc_options);
606 } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) {
607 bool stopped = !send_video && !recv_video;
608 auto media_desc_options = cricket::MediaDescriptionOptions(
609 cricket::MEDIA_TYPE_VIDEO, media_description_options.mid,
610 cricket::RtpTransceiverDirection(send_video, recv_video), stopped);
611 if (send_stream_1_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700612 media_desc_options.AddVideoSender(kVideoTrack1, {kStream1},
zhihuang1c378ed2017-08-17 14:10:50 -0700613 num_sim_layer);
614 }
615 if (send_stream_2_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700616 media_desc_options.AddVideoSender(kVideoTrack2, {kStream2},
zhihuang1c378ed2017-08-17 14:10:50 -0700617 num_sim_layer);
618 }
619 session_options->media_description_options.push_back(
620 media_desc_options);
621 } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) {
622 session_options->media_description_options.push_back(
623 cricket::MediaDescriptionOptions(
624 cricket::MEDIA_TYPE_DATA, media_description_options.mid,
625 // Direction for data sections is meaningless, but legacy
626 // endpoints might expect sendrecv.
627 cricket::RtpTransceiverDirection(true, true), false));
628 } else {
629 RTC_NOTREACHED();
630 }
deadbeefab9b2d12015-10-14 11:33:11 -0700631 }
zhihuang1c378ed2017-08-17 14:10:50 -0700632 }
633
634 // Add the existing media sections first and then add new media sections if
635 // needed.
636 void AddMediaSectionsAndSendersToOptions(
637 cricket::MediaSessionOptions* session_options,
638 bool send_audio,
639 bool recv_audio,
640 bool send_video,
641 bool recv_video) {
642 AddExistingMediaSectionsAndSendersToOptions(
643 session_options, send_audio, recv_audio, send_video, recv_video);
644
645 if (!session_options->has_audio() && (send_audio || recv_audio)) {
646 cricket::MediaDescriptionOptions media_desc_options =
647 cricket::MediaDescriptionOptions(
648 cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
649 cricket::RtpTransceiverDirection(send_audio, recv_audio),
650 kActive);
651 if (send_stream_1_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700652 media_desc_options.AddAudioSender(kAudioTrack1, {kStream1});
zhihuang1c378ed2017-08-17 14:10:50 -0700653 }
654 if (send_stream_2_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700655 media_desc_options.AddAudioSender(kAudioTrack2, {kStream2});
zhihuang1c378ed2017-08-17 14:10:50 -0700656 }
657 session_options->media_description_options.push_back(media_desc_options);
658 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700659 }
zhihuang1c378ed2017-08-17 14:10:50 -0700660
661 if (!session_options->has_video() && (send_video || recv_video)) {
662 cricket::MediaDescriptionOptions media_desc_options =
663 cricket::MediaDescriptionOptions(
664 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
665 cricket::RtpTransceiverDirection(send_video, recv_video),
666 kActive);
667 int num_sim_layer = 1;
668 if (send_stream_1_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700669 media_desc_options.AddVideoSender(kVideoTrack1, {kStream1},
zhihuang1c378ed2017-08-17 14:10:50 -0700670 num_sim_layer);
671 }
672 if (send_stream_2_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700673 media_desc_options.AddVideoSender(kVideoTrack2, {kStream2},
zhihuang1c378ed2017-08-17 14:10:50 -0700674 num_sim_layer);
675 }
676 session_options->media_description_options.push_back(media_desc_options);
677 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700678 }
zhihuang1c378ed2017-08-17 14:10:50 -0700679
680 if (!session_options->has_data() &&
681 (data_channel_ ||
682 session_options->data_channel_type != cricket::DCT_NONE)) {
683 cricket::MediaDescriptionOptions media_desc_options =
684 cricket::MediaDescriptionOptions(
685 cricket::MEDIA_TYPE_DATA, cricket::CN_DATA,
686 cricket::RtpTransceiverDirection(true, true), kActive);
687 if (session_options->data_channel_type == cricket::DCT_RTP) {
688 media_desc_options.AddRtpDataChannel(data_channel_->label(),
689 data_channel_->label());
690 }
691 session_options->media_description_options.push_back(media_desc_options);
692 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700693 }
694 }
695
696 void GetOptionsForOffer(
697 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
698 cricket::MediaSessionOptions* session_options) {
zhihuang1c378ed2017-08-17 14:10:50 -0700699 ExtractSharedMediaSessionOptions(rtc_options, session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700700
zhihuang1c378ed2017-08-17 14:10:50 -0700701 // |recv_X| is true by default if |offer_to_receive_X| is undefined.
702 bool recv_audio = rtc_options.offer_to_receive_audio != 0;
703 bool recv_video = rtc_options.offer_to_receive_video != 0;
704
705 AddMediaSectionsAndSendersToOptions(session_options, local_send_audio_,
706 recv_audio, local_send_video_,
707 recv_video);
deadbeefc80741f2015-10-22 13:14:45 -0700708 session_options->bundle_enabled =
709 session_options->bundle_enabled &&
710 (session_options->has_audio() || session_options->has_video() ||
711 session_options->has_data());
712
zhihuang1c378ed2017-08-17 14:10:50 -0700713 session_options->crypto_options = crypto_options_;
714 }
715
716 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
717 AddExistingMediaSectionsAndSendersToOptions(
718 session_options, local_send_audio_, local_recv_audio_,
719 local_send_video_, local_recv_video_);
720
721 session_options->bundle_enabled =
722 session_options->bundle_enabled &&
723 (session_options->has_audio() || session_options->has_video() ||
724 session_options->has_data());
725
726 if (session_->data_channel_type() != cricket::DCT_RTP) {
727 session_options->data_channel_type = session_->data_channel_type();
olka3c747662017-08-17 06:50:32 -0700728 }
729
zhihuanga77e6bb2017-08-14 18:17:48 -0700730 session_options->crypto_options = crypto_options_;
731 }
732
zhihuang1c378ed2017-08-17 14:10:50 -0700733 void GetOptionsForRemoteAnswer(
734 cricket::MediaSessionOptions* session_options) {
735 bool recv_audio = local_send_audio_ || remote_recv_audio_;
736 bool recv_video = local_send_video_ || remote_recv_video_;
737 bool send_audio = false;
738 bool send_video = false;
zhihuanga77e6bb2017-08-14 18:17:48 -0700739
zhihuang1c378ed2017-08-17 14:10:50 -0700740 AddExistingMediaSectionsAndSendersToOptions(
741 session_options, send_audio, recv_audio, send_video, recv_video);
742
zhihuanga77e6bb2017-08-14 18:17:48 -0700743 session_options->bundle_enabled =
744 session_options->bundle_enabled &&
745 (session_options->has_audio() || session_options->has_video() ||
746 session_options->has_data());
747
748 if (session_->data_channel_type() != cricket::DCT_RTP) {
749 session_options->data_channel_type = session_->data_channel_type();
deadbeefab9b2d12015-10-14 11:33:11 -0700750 }
jbauchcb560652016-08-04 05:20:32 -0700751
deadbeef7914b8c2017-04-21 03:23:33 -0700752 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700753 }
754
zhihuang1c378ed2017-08-17 14:10:50 -0700755 void GetOptionsForAudioOnlyRemoteOffer(
756 cricket::MediaSessionOptions* session_options) {
757 remote_recv_audio_ = true;
758 remote_recv_video_ = false;
759 GetOptionsForRemoteOffer(session_options);
760 }
761
762 void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) {
763 AddMediaSectionsAndSendersToOptions(session_options, remote_send_audio_,
764 remote_recv_audio_, remote_send_video_,
765 remote_recv_video_);
766 session_options->bundle_enabled =
767 (session_options->has_audio() || session_options->has_video() ||
768 session_options->has_data());
769
770 if (session_->data_channel_type() != cricket::DCT_RTP) {
771 session_options->data_channel_type = session_->data_channel_type();
772 }
773
774 session_options->crypto_options = crypto_options_;
775 }
776
deadbeefab9b2d12015-10-14 11:33:11 -0700777 // Creates a local offer and applies it. Starts ICE.
778 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 // to decide which streams to create.
780 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000781 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 SetLocalDescriptionWithoutError(offer);
783 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
784 observer_.ice_gathering_state_,
785 kIceCandidatesTimeout);
786 }
787
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000788 SessionDescriptionInterface* CreateOffer() {
789 PeerConnectionInterface::RTCOfferAnswerOptions options;
790 options.offer_to_receive_audio =
791 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000792 return CreateOffer(options);
793 }
794
wu@webrtc.org91053e72013-08-10 07:18:04 +0000795 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800796 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000797 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000798 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700799 cricket::MediaSessionOptions session_options;
800 GetOptionsForOffer(options, &session_options);
801 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000802 EXPECT_TRUE_WAIT(
803 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000804 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000805 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000806 }
807
808 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800809 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000810 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000811 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800812 cricket::MediaSessionOptions session_options = options;
813 GetOptionsForAnswer(&session_options);
htaa2a49d92016-03-04 02:51:39 -0800814 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000815 EXPECT_TRUE_WAIT(
816 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000817 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000818 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000819 }
820
htaa2a49d92016-03-04 02:51:39 -0800821 SessionDescriptionInterface* CreateAnswer() {
822 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -0700823 options.bundle_enabled = true;
htaa2a49d92016-03-04 02:51:39 -0800824 return CreateAnswer(options);
825 }
826
wu@webrtc.org364f2042013-11-20 21:49:41 +0000827 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 return (session_->voice_channel() != NULL &&
829 session_->video_channel() != NULL);
830 }
831
jbauchcb560652016-08-04 05:20:32 -0700832 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
833 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 ASSERT_TRUE(session_.get() != NULL);
835 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
836 ASSERT_TRUE(content != NULL);
837 const cricket::AudioContentDescription* audio_content =
838 static_cast<const cricket::AudioContentDescription*>(
839 content->description);
840 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700841 if (!gcm_enabled) {
842 ASSERT_EQ(1U, audio_content->cryptos().size());
843 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
844 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
845 audio_content->cryptos()[0].cipher_suite);
846 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
847 audio_content->protocol());
848 } else {
849 // The offer contains 3 possible crypto suites, the answer 1.
850 EXPECT_LE(1U, audio_content->cryptos().size());
851 EXPECT_NE(2U, audio_content->cryptos().size());
852 EXPECT_GE(3U, audio_content->cryptos().size());
853 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
854 ASSERT_EQ("AEAD_AES_256_GCM",
855 audio_content->cryptos()[0].cipher_suite);
856 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
857 audio_content->protocol());
858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859
860 content = cricket::GetFirstVideoContent(sdp);
861 ASSERT_TRUE(content != NULL);
862 const cricket::VideoContentDescription* video_content =
863 static_cast<const cricket::VideoContentDescription*>(
864 content->description);
865 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700866 if (!gcm_enabled) {
867 ASSERT_EQ(1U, video_content->cryptos().size());
868 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
869 video_content->cryptos()[0].cipher_suite);
870 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
871 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
872 video_content->protocol());
873 } else {
874 // The offer contains 3 possible crypto suites, the answer 1.
875 EXPECT_LE(1U, video_content->cryptos().size());
876 EXPECT_NE(2U, video_content->cryptos().size());
877 EXPECT_GE(3U, video_content->cryptos().size());
878 ASSERT_EQ("AEAD_AES_256_GCM",
879 video_content->cryptos()[0].cipher_suite);
880 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
881 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
882 video_content->protocol());
883 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 }
885
886 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
887 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
888 ASSERT_TRUE(content != NULL);
889 const cricket::AudioContentDescription* audio_content =
890 static_cast<const cricket::AudioContentDescription*>(
891 content->description);
892 ASSERT_TRUE(audio_content != NULL);
893 ASSERT_EQ(0U, audio_content->cryptos().size());
894
895 content = cricket::GetFirstVideoContent(sdp);
896 ASSERT_TRUE(content != NULL);
897 const cricket::VideoContentDescription* video_content =
898 static_cast<const cricket::VideoContentDescription*>(
899 content->description);
900 ASSERT_TRUE(video_content != NULL);
901 ASSERT_EQ(0U, video_content->cryptos().size());
902
903 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700904 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700906 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 video_content->protocol());
908 } else {
909 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
910 audio_content->protocol());
911 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
912 video_content->protocol());
913 }
914 }
915
916 // Set the internal fake description factories to do DTLS-SRTP.
917 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000918 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000920 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200921 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800922 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700923 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800924 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
926 }
927
928 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
929 bool expected) {
930 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
931 ASSERT_TRUE(audio != NULL);
932 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 const TransportInfo* video = sdp->GetTransportInfoByName("video");
934 ASSERT_TRUE(video != NULL);
935 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 }
937
938 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000939 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -0700941 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000942 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000944 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000946 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
947 offer);
htaa2a49d92016-03-04 02:51:39 -0800948 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 // Answer should be NULL as no crypto params in offer.
950 ASSERT_TRUE(answer == NULL);
951 }
952
953 void VerifyAnswerFromCryptoOffer() {
954 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -0700955 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700957 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
959 ASSERT_TRUE(offer.get() != NULL);
960 VerifyCryptoParams(offer->description());
961 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700962 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 ASSERT_TRUE(answer.get() != NULL);
964 VerifyCryptoParams(answer->description());
965 }
966
deadbeef0ed85b22016-02-23 17:24:52 -0800967 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
968 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800970 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 }
972
973 const cricket::ContentInfos& contents = desc1->contents();
974 cricket::ContentInfos::const_iterator it = contents.begin();
975
976 for (; it != contents.end(); ++it) {
977 const cricket::TransportDescription* transport_desc1 =
978 desc1->GetTransportDescriptionByName(it->name);
979 const cricket::TransportDescription* transport_desc2 =
980 desc2->GetTransportDescriptionByName(it->name);
981 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800982 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 }
984 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
985 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800986 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 }
988 }
deadbeef0ed85b22016-02-23 17:24:52 -0800989 return true;
990 }
991
992 // Compares ufrag/password only for the specified |media_type|.
993 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
994 const cricket::SessionDescription* desc2,
995 cricket::MediaType media_type) {
996 if (desc1->contents().size() != desc2->contents().size()) {
997 return false;
998 }
999
1000 const cricket::ContentInfo* cinfo =
1001 cricket::GetFirstMediaContent(desc1->contents(), media_type);
1002 const cricket::TransportDescription* transport_desc1 =
1003 desc1->GetTransportDescriptionByName(cinfo->name);
1004 const cricket::TransportDescription* transport_desc2 =
1005 desc2->GetTransportDescriptionByName(cinfo->name);
1006 if (!transport_desc1 || !transport_desc2) {
1007 return false;
1008 }
1009 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
1010 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
1011 return false;
1012 }
1013 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001015
1016 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
1017 std::string *sdp) {
1018 const cricket::SessionDescription* desc = current_desc->description();
1019 EXPECT_TRUE(current_desc->ToString(sdp));
1020
1021 const cricket::ContentInfos& contents = desc->contents();
1022 cricket::ContentInfos::const_iterator it = contents.begin();
1023 // Replace ufrag and pwd lines with empty strings.
1024 for (; it != contents.end(); ++it) {
1025 const cricket::TransportDescription* transport_desc =
1026 desc->GetTransportDescriptionByName(it->name);
1027 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
1028 + "\r\n";
1029 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
1030 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001032 "", 0,
1033 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001034 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001035 "", 0,
1036 sdp);
1037 }
1038 }
1039
deadbeef0ed85b22016-02-23 17:24:52 -08001040 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
1041 const std::string& ufrag,
1042 const std::string& pwd) {
1043 cricket::SessionDescription* desc = current_desc->description();
1044 for (TransportInfo& transport_info : desc->transport_infos()) {
1045 cricket::TransportDescription& transport_desc =
1046 transport_info.description;
1047 transport_desc.ice_ufrag = ufrag;
1048 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00001049 }
1050 }
1051
deadbeef0ed85b22016-02-23 17:24:52 -08001052 // Sets ufrag/pwd for specified |media_type|.
1053 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
1054 cricket::MediaType media_type,
1055 const std::string& ufrag,
1056 const std::string& pwd) {
1057 cricket::SessionDescription* desc = current_desc->description();
1058 const cricket::ContentInfo* cinfo =
1059 cricket::GetFirstMediaContent(desc->contents(), media_type);
1060 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
1061 cricket::TransportDescription* transport_desc =
1062 &transport_info->description;
1063 transport_desc->ice_ufrag = ufrag;
1064 transport_desc->ice_pwd = pwd;
1065 }
1066
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // Creates a remote offer and and applies it as a remote description,
1068 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -07001069 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 // to decide which local and remote streams to create.
1071 void CreateAndSetRemoteOfferAndLocalAnswer() {
1072 SessionDescriptionInterface* offer = CreateRemoteOffer();
1073 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08001074 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 SetLocalDescriptionWithoutError(answer);
1076 }
1077 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
zhihuang1c378ed2017-08-17 14:10:50 -07001078 ASSERT_TRUE(session_->SetLocalDescription(desc, nullptr));
deadbeefcbecd352015-09-23 11:50:27 -07001079 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 }
1081 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -07001082 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 SetLocalDescriptionWithoutError(desc);
1084 EXPECT_EQ(expected_state, session_->state());
1085 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001086 void SetLocalDescriptionExpectError(const std::string& action,
1087 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 SessionDescriptionInterface* desc) {
1089 std::string error;
1090 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001091 std::string sdp_type = "local ";
1092 sdp_type.append(action);
1093 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 EXPECT_NE(std::string::npos, error.find(expected_error));
1095 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001096 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
1097 SessionDescriptionInterface* desc) {
1098 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
1099 expected_error, desc);
1100 }
1101 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
1102 SessionDescriptionInterface* desc) {
1103 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
1104 expected_error, desc);
1105 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
zhihuang1c378ed2017-08-17 14:10:50 -07001107 ASSERT_TRUE(session_->SetRemoteDescription(desc, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 }
1109 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -07001110 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 SetRemoteDescriptionWithoutError(desc);
1112 EXPECT_EQ(expected_state, session_->state());
1113 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001114 void SetRemoteDescriptionExpectError(const std::string& action,
1115 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 SessionDescriptionInterface* desc) {
1117 std::string error;
1118 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001119 std::string sdp_type = "remote ";
1120 sdp_type.append(action);
1121 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 EXPECT_NE(std::string::npos, error.find(expected_error));
1123 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001124 void SetRemoteDescriptionOfferExpectError(
1125 const std::string& expected_error, SessionDescriptionInterface* desc) {
1126 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
1127 expected_error, desc);
1128 }
1129 void SetRemoteDescriptionPranswerExpectError(
1130 const std::string& expected_error, SessionDescriptionInterface* desc) {
1131 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
1132 expected_error, desc);
1133 }
1134 void SetRemoteDescriptionAnswerExpectError(
1135 const std::string& expected_error, SessionDescriptionInterface* desc) {
1136 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
1137 expected_error, desc);
1138 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139
1140 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
1141 SessionDescriptionInterface** nocrypto_answer) {
1142 // Create a SDP without Crypto.
1143 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001144 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 options.bundle_enabled = true;
1146 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1147 ASSERT_TRUE(*offer != NULL);
1148 VerifyCryptoParams((*offer)->description());
1149
zhihuang1c378ed2017-08-17 14:10:50 -07001150 cricket::MediaSessionOptions answer_options;
1151 GetOptionsForRemoteAnswer(&answer_options);
1152 *nocrypto_answer =
1153 CreateRemoteAnswer(*offer, answer_options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 EXPECT_TRUE(*nocrypto_answer != NULL);
1155 }
1156
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001157 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1158 SessionDescriptionInterface** nodtls_answer) {
1159 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001160 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
1161 cricket::MD_RECVONLY, kActive, &options);
1162 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
1163 cricket::MD_RECVONLY, kActive, &options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001164 options.bundle_enabled = true;
1165
kwibergd1fe2812016-04-27 06:47:29 -07001166 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001167 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1168
1169 *nodtls_answer =
1170 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1171 EXPECT_TRUE(*nodtls_answer != NULL);
1172 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1173 VerifyCryptoParams((*nodtls_answer)->description());
1174
1175 SetFactoryDtlsSrtp();
1176 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1177 ASSERT_TRUE(*offer != NULL);
1178 VerifyFingerprintStatus((*offer)->description(), true);
1179 VerifyCryptoParams((*offer)->description());
1180 }
1181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 JsepSessionDescription* CreateRemoteOfferWithVersion(
1183 cricket::MediaSessionOptions options,
1184 cricket::SecurePolicy secure_policy,
1185 const std::string& session_version,
1186 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001187 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 const cricket::SessionDescription* cricket_desc = NULL;
1189 if (current_desc) {
1190 cricket_desc = current_desc->description();
1191 session_id = current_desc->session_id();
1192 }
1193
1194 desc_factory_->set_secure(secure_policy);
1195 JsepSessionDescription* offer(
1196 new JsepSessionDescription(JsepSessionDescription::kOffer));
1197 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1198 session_id, session_version)) {
1199 delete offer;
1200 offer = NULL;
1201 }
1202 return offer;
1203 }
1204 JsepSessionDescription* CreateRemoteOffer(
1205 cricket::MediaSessionOptions options) {
1206 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1207 kSessionVersion, NULL);
1208 }
1209 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001210 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1211 return CreateRemoteOfferWithVersion(
1212 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 }
1214 JsepSessionDescription* CreateRemoteOffer(
1215 cricket::MediaSessionOptions options,
1216 const SessionDescriptionInterface* current_desc) {
1217 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1218 kSessionVersion, current_desc);
1219 }
1220
Steve Anton6d64e9a2017-09-12 09:44:05 -07001221 SessionDescriptionInterface* CreateRemoteOfferWithSctpPort(
1222 const char* sctp_stream_name,
1223 int new_port,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001224 cricket::MediaSessionOptions options) {
1225 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07001226 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001227 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1228 }
1229
1230 // Takes ownership of offer_basis (and deletes it).
Steve Anton6d64e9a2017-09-12 09:44:05 -07001231 SessionDescriptionInterface* ChangeSDPSctpPort(
1232 int new_port,
1233 webrtc::SessionDescriptionInterface* offer_basis) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001234 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1235 // SessionDescription from the mutated string.
1236 const char* default_port_str = "5000";
1237 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001238 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001239 std::string offer_str;
1240 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001241 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001242 new_port_str, strlen(new_port_str),
1243 &offer_str);
Steve Anton6d64e9a2017-09-12 09:44:05 -07001244 SessionDescriptionInterface* offer =
1245 CreateSessionDescription(offer_basis->type(), offer_str, nullptr);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001246 delete offer_basis;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001247 return offer;
1248 }
1249
deadbeefab9b2d12015-10-14 11:33:11 -07001250 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 // before this function to decide which streams to create.
1252 JsepSessionDescription* CreateRemoteOffer() {
1253 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001254 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 return CreateRemoteOffer(options, session_->remote_description());
1256 }
1257
1258 JsepSessionDescription* CreateRemoteAnswer(
1259 const SessionDescriptionInterface* offer,
1260 cricket::MediaSessionOptions options,
1261 cricket::SecurePolicy policy) {
1262 desc_factory_->set_secure(policy);
1263 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001264 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 JsepSessionDescription* answer(
1266 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1267 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1268 options, NULL),
1269 session_id, kSessionVersion)) {
1270 delete answer;
1271 answer = NULL;
1272 }
1273 return answer;
1274 }
1275
1276 JsepSessionDescription* CreateRemoteAnswer(
1277 const SessionDescriptionInterface* offer,
1278 cricket::MediaSessionOptions options) {
1279 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1280 }
1281
deadbeefab9b2d12015-10-14 11:33:11 -07001282 // Creates an answer session description.
1283 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 // to decide which streams to create.
1285 JsepSessionDescription* CreateRemoteAnswer(
1286 const SessionDescriptionInterface* offer) {
1287 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001288 GetOptionsForAnswer(&options);
zhihuang1c378ed2017-08-17 14:10:50 -07001289 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1291 }
1292
1293 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001294 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001295 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001296 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001297
1298 PeerConnectionInterface::RTCOfferAnswerOptions options;
1299 options.use_rtp_mux = bundle;
1300
1301 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1303 // and answer.
1304 SetLocalDescriptionWithoutError(offer);
1305
kwibergd1fe2812016-04-27 06:47:29 -07001306 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001307 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 std::string sdp;
1309 EXPECT_TRUE(answer->ToString(&sdp));
1310
1311 size_t expected_candidate_num = 2;
1312 if (!rtcp_mux) {
1313 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1314 // for rtp and rtcp.
1315 expected_candidate_num = 4;
1316 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 const std::string kRtcpMux = "a=rtcp-mux";
1318 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001319 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 kXRtcpMux.c_str(), kXRtcpMux.length(),
1321 &sdp);
1322 }
1323
1324 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1325 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326
1327 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001328 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1330 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001331 if (bundle) {
1332 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1333 } else {
1334 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 }
1336 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337
zhihuang3a334652016-05-05 18:37:49 -07001338 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1339 const std::string& codec_name) {
1340 for (const auto& content : desc->description()->contents()) {
1341 if (static_cast<cricket::MediaContentDescription*>(content.description)
1342 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1343 const auto* mdesc =
1344 static_cast<cricket::VideoContentDescription*>(content.description);
1345 for (const auto& codec : mdesc->codecs()) {
1346 if (codec.name == codec_name) {
1347 return true;
1348 }
1349 }
1350 }
1351 }
1352 return false;
1353 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001354 // Helper class to configure loopback network and verify Best
1355 // Connection using right IP protocol for TestLoopbackCall
1356 // method. LoopbackNetworkManager applies firewall rules to block
1357 // all ping traffic once ICE completed, and remove them to observe
1358 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1359 // verifies the best connection is using the right IP protocol after
1360 // initial ICE convergences.
1361
1362 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001363 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001364 LoopbackNetworkConfiguration()
1365 : test_ipv6_network_(false),
1366 test_extra_ipv4_network_(false),
1367 best_connection_after_initial_ice_converged_(1, 0) {}
1368
1369 // Used to track the expected best connection count in each IP protocol.
1370 struct ExpectedBestConnection {
1371 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1372 : ipv4_count_(ipv4_count),
1373 ipv6_count_(ipv6_count) {}
1374
1375 int ipv4_count_;
1376 int ipv6_count_;
1377 };
1378
1379 bool test_ipv6_network_;
1380 bool test_extra_ipv4_network_;
1381 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1382
1383 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001384 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001385 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1386 }
1387
1388 private:
jbauchac8869e2015-07-03 01:36:14 -07001389 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001390 const ExpectedBestConnection& expected) const {
1391 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001392 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1393 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001394 expected.ipv4_count_);
1395 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001396 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1397 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001398 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001399 // This is used in the loopback call so there is only single host to host
1400 // candidate pair.
1401 EXPECT_EQ(metrics_observer->GetEnumCounter(
1402 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1403 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001404 0);
1405 EXPECT_EQ(metrics_observer->GetEnumCounter(
1406 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1407 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001408 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001409 }
1410 };
1411
1412 class LoopbackNetworkManager {
1413 public:
1414 LoopbackNetworkManager(WebRtcSessionTest* session,
1415 const LoopbackNetworkConfiguration& config)
1416 : config_(config) {
1417 session->AddInterface(
1418 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1419 if (config_.test_extra_ipv4_network_) {
1420 session->AddInterface(
1421 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1422 }
1423 if (config_.test_ipv6_network_) {
1424 session->AddInterface(
1425 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1426 }
1427 }
1428
1429 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1430 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1431 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1432 if (config_.test_extra_ipv4_network_) {
1433 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1434 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1435 }
1436 if (config_.test_ipv6_network_) {
1437 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1438 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1439 }
1440 }
1441
1442 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1443
1444 private:
1445 LoopbackNetworkConfiguration config_;
1446 };
1447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 // The method sets up a call from the session to itself, in a loopback
1449 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001450 // disconnection, and then a permanent disconnection.
1451 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1453 // While running the call, this method also checks if the session goes through
1454 // the correct sequence of ICE states when a connection is established,
1455 // broken, and re-established.
1456 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001457 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1458 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001460
stefanc1aeaf02015-10-15 07:26:07 -07001461 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001462 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001463 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001464 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465
1466 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1467 observer_.ice_gathering_state_);
1468 SetLocalDescriptionWithoutError(offer);
1469 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1470 observer_.ice_connection_state_);
1471 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001472 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1474 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001475 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476
1477 std::string sdp;
1478 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001479 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1480 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 ASSERT_TRUE(desc != NULL);
1482 SetRemoteDescriptionWithoutError(desc);
1483
1484 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001485 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001486
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001487 // The ice connection state is "Connected" too briefly to catch in a test.
1488 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001489 observer_.ice_connection_state_, kIceCandidatesTimeout);
1490 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491
stefanc1aeaf02015-10-15 07:26:07 -07001492 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1493 LoopbackNetworkManager loopback_network_manager(this, config);
1494 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001495 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 // Adding firewall rule to block ping requests, which should cause
1497 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001498
1499 loopback_network_manager.ApplyFirewallRules(fss_.get());
1500
1501 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1503 observer_.ice_connection_state_,
1504 kIceCandidatesTimeout);
1505
jbauchac8869e2015-07-03 01:36:14 -07001506 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001507
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001509 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001511 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001512 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 observer_.ice_connection_state_,
1514 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001515
1516 // Now we block ping requests and wait until the ICE connection transitions
1517 // to the Failed state. This will take at least 30 seconds because it must
1518 // wait for the Port to timeout.
1519 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001520
1521 loopback_network_manager.ApplyFirewallRules(fss_.get());
1522 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001523 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001524 observer_.ice_connection_state_,
1525 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 }
1527
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001528 void TestLoopbackCall() {
1529 LoopbackNetworkConfiguration config;
1530 TestLoopbackCall(config);
1531 }
1532
stefanc1aeaf02015-10-15 07:26:07 -07001533 void TestPacketOptions() {
stefanc1aeaf02015-10-15 07:26:07 -07001534 LoopbackNetworkConfiguration config;
1535 LoopbackNetworkManager loopback_network_manager(this, config);
1536
1537 SetupLoopbackCall();
1538
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001539 // Wait for channel to be ready for sending.
1540 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001541 uint8_t test_packet[15] = {0};
1542 rtc::PacketOptions options;
1543 options.packet_id = 10;
1544 media_engine_->GetVideoChannel(0)
1545 ->SendRtp(test_packet, sizeof(test_packet), options);
1546
1547 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001548 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1549 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001550 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1551 }
1552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1554 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001555 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1556 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001557
1558 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001559 std::vector<cricket::AudioCodec> codecs =
1560 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 codecs.push_back(kCNCodec1);
1562 codecs.push_back(kCNCodec2);
1563 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001564 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 }
1566
1567 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1568 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001569 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001571 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001572 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1574 if (audio_content_desc->codecs()[i].name == "CN")
1575 return false;
1576 }
1577 return true;
1578 }
1579
deadbeefab9b2d12015-10-14 11:33:11 -07001580 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001581 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001582 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001583 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1584 data_channel_ = DataChannel::Create(
1585 session_.get(), session_->data_channel_type(), "datachannel", dci);
1586 }
1587
1588 void SetLocalDescriptionWithDataChannel() {
1589 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001590 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 SetLocalDescriptionWithoutError(offer);
1592 }
1593
wu@webrtc.org91053e72013-08-10 07:18:04 +00001594 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001595 RTCCertificateGenerationMethod cert_gen_method,
1596 CreateSessionDescriptionRequest::Type type) {
1597 InitWithDtls(cert_gen_method);
1598 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1599 }
1600
1601 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1602 CreateSessionDescriptionRequest::Type type) {
1603 InitWithDtlsIdentityGenFail();
1604 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1605 }
1606
1607 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001608 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001609 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001610 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001611 if (type == CreateSessionDescriptionRequest::kAnswer) {
1612 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001613 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07001614 std::unique_ptr<JsepSessionDescription> offer(
1615 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001616 ASSERT_TRUE(offer.get() != NULL);
1617 SetRemoteDescriptionWithoutError(offer.release());
1618 }
1619
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001620 PeerConnectionInterface::RTCOfferAnswerOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001621 cricket::MediaSessionOptions offer_session_options;
1622 cricket::MediaSessionOptions answer_session_options;
1623 GetOptionsForOffer(options, &offer_session_options);
1624 GetOptionsForAnswer(&answer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001625 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001626 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001627 observers[kNumber];
1628 for (int i = 0; i < kNumber; ++i) {
1629 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1630 if (type == CreateSessionDescriptionRequest::kOffer) {
zhihuang1c378ed2017-08-17 14:10:50 -07001631 session_->CreateOffer(observers[i], options, offer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001632 } else {
zhihuang1c378ed2017-08-17 14:10:50 -07001633 session_->CreateAnswer(observers[i], answer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001634 }
1635 }
1636
1637 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1638 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1639 WebRtcSessionCreateSDPObserverForTest::kFailed;
1640
1641 for (int i = 0; i < kNumber; ++i) {
1642 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1643 if (success) {
1644 EXPECT_TRUE(observers[i]->description() != NULL);
1645 } else {
1646 EXPECT_TRUE(observers[i]->description() == NULL);
1647 }
1648 }
1649 }
1650
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001651 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001652 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001653 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001654 turn_server.credentials = credentials;
1655 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001656 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001657 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001658 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001659 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001660 }
1661
skvlad11a9cbf2016-10-07 11:53:05 -07001662 webrtc::RtcEventLogNullImpl event_log_;
nisse7eaa4ea2017-05-08 05:25:41 -07001663 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1664 std::unique_ptr<rtc::FirewallSocketServer> fss_;
1665 rtc::AutoSocketServerThread thread_;
deadbeef112b2e92017-02-10 20:13:37 -08001666 // |media_engine_| and |data_engine_| are actually owned by
1667 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 cricket::FakeMediaEngine* media_engine_;
1669 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001670 // Actually owned by session_.
1671 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001672 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001673 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001674 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1675 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001676 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001677 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001678 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001679 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001680 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001681 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001682 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001683 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 MockIceObserver observer_;
1685 cricket::FakeVideoMediaChannel* video_channel_;
1686 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001687 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001688 // The following flags affect options created for CreateOffer/CreateAnswer.
1689 bool send_stream_1_ = false;
1690 bool send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -07001691 bool local_send_audio_ = false;
1692 bool local_send_video_ = false;
1693 bool local_recv_audio_ = true;
1694 bool local_recv_video_ = true;
1695 bool remote_send_audio_ = false;
1696 bool remote_send_video_ = false;
1697 bool remote_recv_audio_ = true;
1698 bool remote_recv_video_ = true;
1699 std::vector<cricket::MediaDescriptionOptions> offered_media_sections_;
deadbeefab9b2d12015-10-14 11:33:11 -07001700 rtc::scoped_refptr<DataChannel> data_channel_;
1701 // Last values received from data channel creation signal.
1702 std::string last_data_channel_label_;
1703 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001704 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705};
1706
Henrik Boström87713d02015-08-25 09:53:21 +02001707TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1708 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001709 // SDES is disabled when DTLS is on.
1710 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711}
1712
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001714 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001715 // SDES is required if DTLS is off.
1716 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001717}
1718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1720 TestSessionCandidatesWithBundleRtcpMux(false, false);
1721}
1722
1723// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1724// with rtcp-mux and/or bundle.
1725TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1726 TestSessionCandidatesWithBundleRtcpMux(false, true);
1727}
1728
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1730 TestSessionCandidatesWithBundleRtcpMux(true, true);
1731}
1732
1733TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001734 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1735 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001736 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001737 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 InitiateCall();
1739 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1740 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1741 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1742}
1743
deadbeeff5f03e82016-06-06 11:16:06 -07001744TEST_F(WebRtcSessionTest, TestStunError) {
1745 rtc::ScopedFakeClock clock;
1746
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001747 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1748 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001749 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001750 rtc::FP_UDP,
1751 rtc::FD_ANY,
1752 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001753 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001754 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001756 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001757 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1758 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1760 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001761 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1762 // warning.
1763 session_->Close();
1764 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765}
1766
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001767TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001768 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001769 SessionDescriptionInterface* offer = NULL;
1770 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1771 std::string unknown_action;
1772 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1773 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1774}
1775
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776// Test creating offers and receive answers and make sure the
1777// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001779 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001780 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001781 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 const std::string session_id_orig = offer->session_id();
1783 const std::string session_version_orig = offer->session_version();
1784 SetLocalDescriptionWithoutError(offer);
1785
deadbeefab9b2d12015-10-14 11:33:11 -07001786 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 SessionDescriptionInterface* answer =
1788 CreateRemoteAnswer(session_->local_description());
1789 SetRemoteDescriptionWithoutError(answer);
1790
1791 video_channel_ = media_engine_->GetVideoChannel(0);
1792 voice_channel_ = media_engine_->GetVoiceChannel(0);
1793
1794 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1795 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1796
1797 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1798 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1799
1800 ASSERT_EQ(1u, video_channel_->send_streams().size());
1801 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1802 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1803 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1804
1805 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001806 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001807 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808
1809 // Verify the session id is the same and the session version is
1810 // increased.
1811 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001812 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1813 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814
1815 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001816 EXPECT_EQ(0u, video_channel_->send_streams().size());
1817 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818
deadbeefab9b2d12015-10-14 11:33:11 -07001819 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 answer = CreateRemoteAnswer(session_->local_description());
1821 SetRemoteDescriptionWithoutError(answer);
1822
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 // Make sure the receive streams have not changed.
1824 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1825 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1826 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1827 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1828}
1829
1830// Test receiving offers and creating answers and make sure the
1831// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001833 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001834 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001835 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001836 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 SetRemoteDescriptionWithoutError(offer);
1838
deadbeefab9b2d12015-10-14 11:33:11 -07001839 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001840 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001841 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 SetLocalDescriptionWithoutError(answer);
1843
1844 const std::string session_id_orig = answer->session_id();
1845 const std::string session_version_orig = answer->session_version();
1846
1847 video_channel_ = media_engine_->GetVideoChannel(0);
1848 voice_channel_ = media_engine_->GetVoiceChannel(0);
1849
htaa2a49d92016-03-04 02:51:39 -08001850 ASSERT_TRUE(video_channel_);
1851 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1853 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1854
1855 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1856 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1857
1858 ASSERT_EQ(1u, video_channel_->send_streams().size());
1859 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1860 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1861 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1862
deadbeefab9b2d12015-10-14 11:33:11 -07001863 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001864 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 SetRemoteDescriptionWithoutError(offer);
1866
1867 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001868 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001869 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870
1871 // Verify the session id is the same and the session version is
1872 // increased.
1873 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001874 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1875 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 SetLocalDescriptionWithoutError(answer);
1877
1878 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1879 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1880 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1881 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1882 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1883 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1884
1885 // Make sure we have no send streams.
1886 EXPECT_EQ(0u, video_channel_->send_streams().size());
1887 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1888}
1889
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001890TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001891 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001892 media_engine_->set_fail_create_channel(true);
1893
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001894 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001895 ASSERT_TRUE(offer != NULL);
1896 // SetRemoteDescription and SetLocalDescription will take the ownership of
1897 // the offer.
1898 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001899 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001900 ASSERT_TRUE(offer != NULL);
1901 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1902}
1903
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904//
1905// Tests for creating/setting SDP under different SDES/DTLS polices:
1906//
1907// --DTLS off and SDES on
1908// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1909// set local/remote offer/answer with crypto --> success
1910// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1911// failure
1912// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1913// failure
1914// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1915// failure
1916//
1917// --DTLS on and SDES off
1918// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1919// set local/remote offer/answer with DTLS fingerprint --> success
1920// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1921// fingerprint --> failure
1922// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1923// --> failure
1924// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1925// --> failure
1926//
1927// --Encryption disabled: DTLS off and SDES off
1928// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1929// answer without SDES or DTLS --> success
1930// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1931// answer without SDES or DTLS --> success
1932//
1933
1934// Test that we return a failure when applying a remote/local offer that doesn't
1935// have cryptos enabled when DTLS is off.
1936TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001937 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001939 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 JsepSessionDescription* offer = CreateRemoteOffer(
1941 options, cricket::SEC_DISABLED);
1942 ASSERT_TRUE(offer != NULL);
1943 VerifyNoCryptoParams(offer->description(), false);
1944 // SetRemoteDescription and SetLocalDescription will take the ownership of
1945 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001946 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1948 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001949 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950}
1951
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001952// Test that we return a failure when applying a local answer that doesn't have
1953// cryptos enabled when DTLS is off.
1954TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001955 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 SessionDescriptionInterface* offer = NULL;
1957 SessionDescriptionInterface* answer = NULL;
1958 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1959 // SetRemoteDescription and SetLocalDescription will take the ownership of
1960 // the offer.
1961 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001962 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963}
1964
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001965// Test we will return fail when apply an remote answer that doesn't have
1966// crypto enabled when DTLS is off.
1967TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001968 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969 SessionDescriptionInterface* offer = NULL;
1970 SessionDescriptionInterface* answer = NULL;
1971 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1972 // SetRemoteDescription and SetLocalDescription will take the ownership of
1973 // the offer.
1974 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001975 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976}
1977
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001978// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1979// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001980TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001981 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001982 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 SetFactoryDtlsSrtp();
1984 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001985 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001986 JsepSessionDescription* offer =
1987 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 ASSERT_TRUE(offer != NULL);
1989 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001990 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991
1992 // SetRemoteDescription will take the ownership of the offer.
1993 SetRemoteDescriptionWithoutError(offer);
1994
1995 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001996 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 ASSERT_TRUE(answer != NULL);
1998 VerifyFingerprintStatus(answer->description(), true);
1999 // Check that we don't have an a=crypto line in the answer.
2000 VerifyNoCryptoParams(answer->description(), true);
2001
2002 // Now set the local description, which should work, even without a=crypto.
2003 SetLocalDescriptionWithoutError(answer);
2004}
2005
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002006// Test that we set a local offer with a DTLS fingerprint when DTLS is on
2007// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02002008TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07002009 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02002010 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002011 SetFactoryDtlsSrtp();
2012
2013 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002014 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002015 ASSERT_TRUE(offer != NULL);
2016 VerifyFingerprintStatus(offer->description(), true);
2017 // Check that we don't have an a=crypto line in the offer.
2018 VerifyNoCryptoParams(offer->description(), true);
2019
2020 // Now set the local description, which should work, even without a=crypto.
2021 SetLocalDescriptionWithoutError(offer);
2022
2023 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002024 GetOptionsForAnswer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002025 JsepSessionDescription* answer =
2026 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2027 ASSERT_TRUE(answer != NULL);
2028 VerifyFingerprintStatus(answer->description(), true);
2029 VerifyNoCryptoParams(answer->description(), true);
2030
2031 // SetRemoteDescription will take the ownership of the answer.
2032 SetRemoteDescriptionWithoutError(answer);
2033}
2034
2035// Test that if we support DTLS and the other side didn't offer a fingerprint,
2036// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02002037TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002038 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002040 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002041 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 JsepSessionDescription* offer = CreateRemoteOffer(
2043 options, cricket::SEC_REQUIRED);
2044 ASSERT_TRUE(offer != NULL);
2045 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002046 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002048 // SetRemoteDescription will take the ownership of the offer.
2049 SetRemoteDescriptionOfferExpectError(
2050 kSdpWithoutDtlsFingerprint, offer);
2051
2052 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
2053 // SetLocalDescription will take the ownership of the offer.
2054 SetLocalDescriptionOfferExpectError(
2055 kSdpWithoutDtlsFingerprint, offer);
2056}
2057
2058// Test that we return a failure when applying a local answer that doesn't have
2059// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02002060TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002061 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002062 SessionDescriptionInterface* offer = NULL;
2063 SessionDescriptionInterface* answer = NULL;
2064 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
2065
2066 // SetRemoteDescription and SetLocalDescription will take the ownership of
2067 // the offer and answer.
2068 SetRemoteDescriptionWithoutError(offer);
2069 SetLocalDescriptionAnswerExpectError(
2070 kSdpWithoutDtlsFingerprint, answer);
2071}
2072
2073// Test that we return a failure when applying a remote answer that doesn't have
2074// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02002075TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002076 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002077 SessionDescriptionInterface* offer = CreateOffer();
zhihuang1c378ed2017-08-17 14:10:50 -07002078 cricket::MediaSessionOptions offer_options;
2079 GetOptionsForRemoteOffer(&offer_options);
2080
kwibergd1fe2812016-04-27 06:47:29 -07002081 std::unique_ptr<SessionDescriptionInterface> temp_offer(
zhihuang1c378ed2017-08-17 14:10:50 -07002082 CreateRemoteOffer(offer_options, cricket::SEC_ENABLED));
2083
2084 cricket::MediaSessionOptions answer_options;
2085 GetOptionsForAnswer(&answer_options);
2086 JsepSessionDescription* answer = CreateRemoteAnswer(
2087 temp_offer.get(), answer_options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002088
2089 // SetRemoteDescription and SetLocalDescription will take the ownership of
2090 // the offer and answer.
2091 SetLocalDescriptionWithoutError(offer);
2092 SetRemoteDescriptionAnswerExpectError(
2093 kSdpWithoutDtlsFingerprint, answer);
2094}
2095
2096// Test that we create a local offer without SDES or DTLS and accept a remote
2097// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002098TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002100 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002101 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002102
2103 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002105 ASSERT_TRUE(offer != NULL);
2106 VerifyFingerprintStatus(offer->description(), false);
2107 // Check that we don't have an a=crypto line in the offer.
2108 VerifyNoCryptoParams(offer->description(), false);
2109
2110 // Now set the local description, which should work, even without a=crypto.
2111 SetLocalDescriptionWithoutError(offer);
2112
2113 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002114 GetOptionsForAnswer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002115 JsepSessionDescription* answer =
2116 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2117 ASSERT_TRUE(answer != NULL);
2118 VerifyFingerprintStatus(answer->description(), false);
2119 VerifyNoCryptoParams(answer->description(), false);
2120
2121 // SetRemoteDescription will take the ownership of the answer.
2122 SetRemoteDescriptionWithoutError(answer);
2123}
2124
2125// Test that we create a local answer without SDES or DTLS and accept a remote
2126// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002127TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002128 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002129 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002130
2131 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002132 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002133 JsepSessionDescription* offer =
2134 CreateRemoteOffer(options, cricket::SEC_DISABLED);
2135 ASSERT_TRUE(offer != NULL);
2136 VerifyFingerprintStatus(offer->description(), false);
2137 VerifyNoCryptoParams(offer->description(), false);
2138
2139 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 SetRemoteDescriptionWithoutError(offer);
2141
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002142 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08002143 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 ASSERT_TRUE(answer != NULL);
2145 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002146 // Check that we don't have an a=crypto line in the answer.
2147 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002149 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 SetLocalDescriptionWithoutError(answer);
2151}
2152
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002153// Test that we can create and set an answer correctly when different
2154// SSL roles have been negotiated for different transports.
2155// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
2156TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
2157 SendAudioVideoStream1();
2158 InitWithDtls(GetParam());
2159 SetFactoryDtlsSrtp();
2160
2161 SessionDescriptionInterface* offer = CreateOffer();
2162 SetLocalDescriptionWithoutError(offer);
2163
2164 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002165 GetOptionsForAnswer(&options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002166
2167 // First, negotiate different SSL roles.
2168 SessionDescriptionInterface* answer =
2169 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2170 TransportInfo* audio_transport_info =
2171 answer->description()->GetTransportInfoByName("audio");
2172 audio_transport_info->description.connection_role =
2173 cricket::CONNECTIONROLE_ACTIVE;
2174 TransportInfo* video_transport_info =
2175 answer->description()->GetTransportInfoByName("video");
2176 video_transport_info->description.connection_role =
2177 cricket::CONNECTIONROLE_PASSIVE;
2178 SetRemoteDescriptionWithoutError(answer);
2179
2180 // Now create an offer in the reverse direction, and ensure the initial
2181 // offerer responds with an answer with correct SSL roles.
2182 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2183 kSessionVersion,
2184 session_->remote_description());
2185 SetRemoteDescriptionWithoutError(offer);
2186
zhihuang1c378ed2017-08-17 14:10:50 -07002187 cricket::MediaSessionOptions answer_options;
2188 answer_options.bundle_enabled = true;
2189 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002190 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2191 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2192 audio_transport_info->description.connection_role);
2193 video_transport_info = answer->description()->GetTransportInfoByName("video");
2194 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2195 video_transport_info->description.connection_role);
2196 SetLocalDescriptionWithoutError(answer);
2197
2198 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2199 // audio is transferred over to video in the answer that completes the BUNDLE
2200 // negotiation.
2201 options.bundle_enabled = true;
2202 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2203 kSessionVersion,
2204 session_->remote_description());
2205 SetRemoteDescriptionWithoutError(offer);
zhihuang1c378ed2017-08-17 14:10:50 -07002206 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002207 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2208 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2209 audio_transport_info->description.connection_role);
2210 video_transport_info = answer->description()->GetTransportInfoByName("video");
2211 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2212 video_transport_info->description.connection_role);
2213 SetLocalDescriptionWithoutError(answer);
2214}
2215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002217 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002218 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002220 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 SetLocalDescriptionWithoutError(offer);
2222
2223 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002224 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 SetLocalDescriptionWithoutError(offer2);
2226}
2227
2228TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002229 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002230 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002232 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 SetRemoteDescriptionWithoutError(offer);
2234
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002235 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 SetRemoteDescriptionWithoutError(offer2);
2237}
2238
2239TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002240 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002241 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002242 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002244 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002245 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2246 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247}
2248
2249TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002250 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002251 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002252 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002254 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002255 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002256 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257}
2258
2259TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002260 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002261 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002263 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264
htaa2a49d92016-03-04 02:51:39 -08002265 JsepSessionDescription* pranswer =
2266 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002268 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269
deadbeefab9b2d12015-10-14 11:33:11 -07002270 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002271 JsepSessionDescription* pranswer2 =
2272 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2274
deadbeefd59daf82015-10-14 15:02:44 -07002275 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276
deadbeefab9b2d12015-10-14 11:33:11 -07002277 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002278 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002279 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280}
2281
2282TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002283 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002284 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002285 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002286 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287
2288 JsepSessionDescription* pranswer =
2289 CreateRemoteAnswer(session_->local_description());
2290 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2291
2292 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002293 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294
deadbeefab9b2d12015-10-14 11:33:11 -07002295 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 JsepSessionDescription* pranswer2 =
2297 CreateRemoteAnswer(session_->local_description());
2298 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2299
2300 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002301 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302
deadbeefab9b2d12015-10-14 11:33:11 -07002303 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 SessionDescriptionInterface* answer =
2305 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002306 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307}
2308
2309TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002310 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002311 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002312 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 SessionDescriptionInterface* answer =
2315 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002316 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2317 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318}
2319
2320TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002321 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002322 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002323 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 SessionDescriptionInterface* answer =
2326 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002327 SetRemoteDescriptionAnswerExpectError(
2328 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329}
2330
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002331// Tests that the remote candidates are added and removed successfully.
2332TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002333 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002334 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002336 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
zhihuang38989e52017-03-21 11:04:53 -07002337 "", "", "local", 0, "");
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002338 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2340
deadbeefd59daf82015-10-14 15:02:44 -07002341 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2343
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002344 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002346
2347 // Fail since we have not set a remote description.
2348 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
2350 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2351 session_->local_description());
2352 SetRemoteDescriptionWithoutError(answer);
2353
deadbeefd59daf82015-10-14 15:02:44 -07002354 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2355 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002356 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002357 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2358 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 // Verifying the candidates are copied properly from internal vector.
2361 const SessionDescriptionInterface* remote_desc =
2362 session_->remote_description();
2363 ASSERT_TRUE(remote_desc != NULL);
2364 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2365 const IceCandidateCollection* candidates =
2366 remote_desc->candidates(kMediaContentIndex0);
2367 ASSERT_EQ(2u, candidates->count());
2368 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2369 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2370 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2371 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2372
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002373 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2374 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 candidate.set_component(2);
2376 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2377 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002378 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
2380 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2381 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002382
2383 // Remove candidate1 and candidate2
2384 std::vector<cricket::Candidate> remote_candidates;
2385 remote_candidates.push_back(ice_candidate1.candidate());
2386 remote_candidates.push_back(ice_candidate2.candidate());
2387 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2388 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389}
2390
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002391// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392// that it is retained if the remote session description is changed.
2393TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002394 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 cricket::Candidate candidate1;
2396 candidate1.set_component(1);
2397 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2398 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002399 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 CreateAndSetRemoteOfferAndLocalAnswer();
2401
2402 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2403 const SessionDescriptionInterface* remote_desc =
2404 session_->remote_description();
2405 ASSERT_TRUE(remote_desc != NULL);
2406 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2407 const IceCandidateCollection* candidates =
2408 remote_desc->candidates(kMediaContentIndex0);
2409 ASSERT_EQ(1u, candidates->count());
2410 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2411
2412 // Update the RemoteSessionDescription with a new session description and
2413 // a candidate and check that the new remote session description contains both
2414 // candidates.
2415 SessionDescriptionInterface* offer = CreateRemoteOffer();
2416 cricket::Candidate candidate2;
2417 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2418 candidate2);
2419 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2420 SetRemoteDescriptionWithoutError(offer);
2421
2422 remote_desc = session_->remote_description();
2423 ASSERT_TRUE(remote_desc != NULL);
2424 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2425 candidates = remote_desc->candidates(kMediaContentIndex0);
2426 ASSERT_EQ(2u, candidates->count());
2427 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2428 // Username and password have be updated with the TransportInfo of the
2429 // SessionDescription, won't be equal to the original one.
2430 candidate2.set_username(candidates->at(0)->candidate().username());
2431 candidate2.set_password(candidates->at(0)->candidate().password());
2432 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2433 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2434 // No need to verify the username and password.
2435 candidate1.set_username(candidates->at(1)->candidate().username());
2436 candidate1.set_password(candidates->at(1)->candidate().password());
2437 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2438
2439 // Test that the candidate is ignored if we can add the same candidate again.
2440 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2441}
2442
2443// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002444// that they are retained if the local session description is changed. And if
2445// continual gathering is enabled, they are removed from the local session
2446// description when the network is down.
2447TEST_F(WebRtcSessionTest,
2448 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002449 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002450 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002451 // Enable Continual Gathering.
2452 cricket::IceConfig config;
2453 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2454 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002455 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 CreateAndSetRemoteOfferAndLocalAnswer();
2457
2458 const SessionDescriptionInterface* local_desc = session_->local_description();
2459 const IceCandidateCollection* candidates =
2460 local_desc->candidates(kMediaContentIndex0);
2461 ASSERT_TRUE(candidates != NULL);
2462 EXPECT_EQ(0u, candidates->count());
2463
deadbeefb60a8192016-08-24 15:15:00 -07002464 // Since we're using continual gathering, we won't get "gathering done".
2465 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466
2467 local_desc = session_->local_description();
2468 candidates = local_desc->candidates(kMediaContentIndex0);
2469 ASSERT_TRUE(candidates != NULL);
2470 EXPECT_LT(0u, candidates->count());
2471 candidates = local_desc->candidates(1);
2472 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002473 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474
2475 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002476 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 CreateAndSetRemoteOfferAndLocalAnswer();
2478
2479 local_desc = session_->local_description();
2480 candidates = local_desc->candidates(kMediaContentIndex0);
2481 ASSERT_TRUE(candidates != NULL);
2482 EXPECT_LT(0u, candidates->count());
2483 candidates = local_desc->candidates(1);
2484 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002485 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002486
2487 candidates = local_desc->candidates(kMediaContentIndex0);
2488 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002489 // Bring down the network interface to trigger candidate removals.
2490 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2491 // Verify that all local candidates are removed.
2492 EXPECT_EQ(0, observer_.num_candidates_removed_);
2493 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2494 kIceCandidatesTimeout);
2495 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2496}
2497
2498// Tests that if continual gathering is disabled, local candidates won't be
2499// removed when the interface is turned down.
2500TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2501 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2502 Init();
2503 SendAudioVideoStream1();
2504 CreateAndSetRemoteOfferAndLocalAnswer();
2505
2506 const SessionDescriptionInterface* local_desc = session_->local_description();
2507 const IceCandidateCollection* candidates =
2508 local_desc->candidates(kMediaContentIndex0);
2509 ASSERT_TRUE(candidates != NULL);
2510 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2511
2512 size_t num_local_candidates = candidates->count();
2513 EXPECT_LT(0u, num_local_candidates);
2514 // By default, Continual Gathering is disabled.
2515 // Bring down the network interface.
2516 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2517 // Verify that the local candidates are not removed.
2518 rtc::Thread::Current()->ProcessMessages(1000);
2519 EXPECT_EQ(0, observer_.num_candidates_removed_);
2520 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521}
2522
2523// Test that we can set a remote session description with remote candidates.
2524TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002525 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526
2527 cricket::Candidate candidate1;
2528 candidate1.set_component(1);
2529 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2530 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002531 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002532 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533
2534 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2535 SetRemoteDescriptionWithoutError(offer);
2536
2537 const SessionDescriptionInterface* remote_desc =
2538 session_->remote_description();
2539 ASSERT_TRUE(remote_desc != NULL);
2540 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2541 const IceCandidateCollection* candidates =
2542 remote_desc->candidates(kMediaContentIndex0);
2543 ASSERT_EQ(1u, candidates->count());
2544 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2545
htaa2a49d92016-03-04 02:51:39 -08002546 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 SetLocalDescriptionWithoutError(answer);
2548}
2549
2550// Test that offers and answers contains ice candidates when Ice candidates have
2551// been gathered.
2552TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002553 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002554 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002555 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 // Ice is started but candidates are not provided until SetLocalDescription
2557 // is called.
2558 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2559 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2560 CreateAndSetRemoteOfferAndLocalAnswer();
2561 // Wait until at least one local candidate has been collected.
2562 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2563 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002564
kwibergd1fe2812016-04-27 06:47:29 -07002565 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002566
zhihuang1c378ed2017-08-17 14:10:50 -07002567 ASSERT_TRUE(local_offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2569 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570
2571 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2572 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002573 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2575 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 SetLocalDescriptionWithoutError(answer);
2577}
2578
2579// Verifies TransportProxy and media channels are created with content names
2580// present in the SessionDescription.
2581TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002582 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002583 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002584 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585
2586 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002587 // "video". Goal is to modify these content names and verify transport
2588 // channels
2589 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 // present in SDP.
2591 std::string sdp;
2592 EXPECT_TRUE(offer->ToString(&sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593
2594 SessionDescriptionInterface* modified_offer =
2595 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2596
2597 SetRemoteDescriptionWithoutError(modified_offer);
2598
zhihuang1c378ed2017-08-17 14:10:50 -07002599 cricket::MediaSessionOptions answer_options;
2600 answer_options.bundle_enabled = false;
2601 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 SetLocalDescriptionWithoutError(answer);
2603
deadbeef5bd5ca32017-02-10 11:31:50 -08002604 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002605 session_->voice_rtp_transport_channel();
2606 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002607 EXPECT_EQ(voice_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07002608 "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002609 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002610 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002611 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002612 EXPECT_EQ(video_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07002613 "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2615 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2616}
2617
2618// Test that an offer contains the correct media content descriptions based on
2619// the send streams when no constraints have been set.
2620TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002622 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002623
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 ASSERT_TRUE(offer != NULL);
2625 const cricket::ContentInfo* content =
2626 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002627 ASSERT_TRUE(content != NULL);
2628 EXPECT_EQ(
2629 cricket::MD_RECVONLY,
2630 static_cast<const cricket::AudioContentDescription*>(content->description)
2631 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002633 ASSERT_TRUE(content != NULL);
2634 EXPECT_EQ(
2635 cricket::MD_RECVONLY,
2636 static_cast<const cricket::VideoContentDescription*>(content->description)
2637 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638}
2639
2640// Test that an offer contains the correct media content descriptions based on
2641// the send streams when no constraints have been set.
2642TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002643 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002645 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002646 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 const cricket::ContentInfo* content =
2649 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002650 ASSERT_TRUE(content != NULL);
2651 EXPECT_EQ(
2652 cricket::MD_SENDRECV,
2653 static_cast<const cricket::AudioContentDescription*>(content->description)
2654 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002656 ASSERT_TRUE(content != NULL);
2657 EXPECT_EQ(
2658 cricket::MD_RECVONLY,
2659 static_cast<const cricket::VideoContentDescription*>(content->description)
2660 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661
2662 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002663 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002664 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 content = cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002666 ASSERT_TRUE(content != NULL);
2667 EXPECT_EQ(
2668 cricket::MD_SENDRECV,
2669 static_cast<const cricket::AudioContentDescription*>(content->description)
2670 ->direction());
2671
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002673 ASSERT_TRUE(content != NULL);
2674 EXPECT_EQ(
2675 cricket::MD_SENDRECV,
2676 static_cast<const cricket::VideoContentDescription*>(content->description)
2677 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002678}
2679
2680// Test that an offer contains no media content descriptions if
2681// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2682TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002683 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002684 PeerConnectionInterface::RTCOfferAnswerOptions options;
2685 options.offer_to_receive_audio = 0;
2686 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687
kwibergd1fe2812016-04-27 06:47:29 -07002688 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002689
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 ASSERT_TRUE(offer != NULL);
2691 const cricket::ContentInfo* content =
2692 cricket::GetFirstAudioContent(offer->description());
2693 EXPECT_TRUE(content == NULL);
2694 content = cricket::GetFirstVideoContent(offer->description());
2695 EXPECT_TRUE(content == NULL);
2696}
2697
2698// Test that an offer contains only audio media content descriptions if
2699// kOfferToReceiveAudio constraints are set to true.
2700TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002701 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002702 PeerConnectionInterface::RTCOfferAnswerOptions options;
2703 options.offer_to_receive_audio =
2704 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
zhihuang1c378ed2017-08-17 14:10:50 -07002705 options.offer_to_receive_video = 0;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002706
kwibergd1fe2812016-04-27 06:47:29 -07002707 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708
2709 const cricket::ContentInfo* content =
2710 cricket::GetFirstAudioContent(offer->description());
2711 EXPECT_TRUE(content != NULL);
2712 content = cricket::GetFirstVideoContent(offer->description());
2713 EXPECT_TRUE(content == NULL);
2714}
2715
2716// Test that an offer contains audio and video media content descriptions if
2717// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2718TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002719 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002721 PeerConnectionInterface::RTCOfferAnswerOptions options;
2722 options.offer_to_receive_audio =
2723 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2724 options.offer_to_receive_video =
2725 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2726
kwibergd1fe2812016-04-27 06:47:29 -07002727 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002728
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 const cricket::ContentInfo* content =
2730 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002731 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002732
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 content = cricket::GetFirstVideoContent(offer->description());
2734 EXPECT_TRUE(content != NULL);
2735
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002736 // Sets constraints to false and verifies that audio/video contents are
2737 // removed.
2738 options.offer_to_receive_audio = 0;
2739 options.offer_to_receive_video = 0;
zhihuang1c378ed2017-08-17 14:10:50 -07002740 // Remove the media sections added in previous offer.
2741 offered_media_sections_.clear();
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002742 offer.reset(CreateOffer(options));
2743
2744 content = cricket::GetFirstAudioContent(offer->description());
2745 EXPECT_TRUE(content == NULL);
2746 content = cricket::GetFirstVideoContent(offer->description());
2747 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748}
2749
2750// Test that an answer can not be created if the last remote description is not
2751// an offer.
2752TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002753 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002754 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 SetLocalDescriptionWithoutError(offer);
2756 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2757 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002758 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759}
2760
2761// Test that an answer contains the correct media content descriptions when no
2762// constraints have been set.
2763TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002766 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002768 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769 const cricket::ContentInfo* content =
2770 cricket::GetFirstAudioContent(answer->description());
2771 ASSERT_TRUE(content != NULL);
2772 EXPECT_FALSE(content->rejected);
2773
2774 content = cricket::GetFirstVideoContent(answer->description());
2775 ASSERT_TRUE(content != NULL);
2776 EXPECT_FALSE(content->rejected);
2777}
2778
2779// Test that an answer contains the correct media content descriptions when no
2780// constraints have been set and the offer only contain audio.
2781TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002782 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783 // Create a remote offer with audio only.
2784 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002785 GetOptionsForAudioOnlyRemoteOffer(&options);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002786
kwibergd1fe2812016-04-27 06:47:29 -07002787 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2789 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2790
2791 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002792 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793 const cricket::ContentInfo* content =
2794 cricket::GetFirstAudioContent(answer->description());
2795 ASSERT_TRUE(content != NULL);
2796 EXPECT_FALSE(content->rejected);
2797
2798 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2799}
2800
2801// Test that an answer contains the correct media content descriptions when no
2802// constraints have been set.
2803TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002804 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002806 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 SetRemoteDescriptionWithoutError(offer.release());
2808 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002809 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002810 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 const cricket::ContentInfo* content =
2812 cricket::GetFirstAudioContent(answer->description());
2813 ASSERT_TRUE(content != NULL);
2814 EXPECT_FALSE(content->rejected);
2815
2816 content = cricket::GetFirstVideoContent(answer->description());
2817 ASSERT_TRUE(content != NULL);
2818 EXPECT_FALSE(content->rejected);
2819}
2820
2821// Test that an answer contains the correct media content descriptions when
2822// constraints have been set but no stream is sent.
2823TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002824 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002825 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002826 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827 SetRemoteDescriptionWithoutError(offer.release());
2828
htaa2a49d92016-03-04 02:51:39 -08002829 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07002830 remote_send_audio_ = false;
2831 remote_send_video_ = false;
2832 local_recv_audio_ = false;
2833 local_recv_video_ = false;
kwibergd1fe2812016-04-27 06:47:29 -07002834 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002835 CreateAnswer(session_options));
2836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 const cricket::ContentInfo* content =
2838 cricket::GetFirstAudioContent(answer->description());
2839 ASSERT_TRUE(content != NULL);
2840 EXPECT_TRUE(content->rejected);
2841
2842 content = cricket::GetFirstVideoContent(answer->description());
2843 ASSERT_TRUE(content != NULL);
2844 EXPECT_TRUE(content->rejected);
2845}
2846
2847// Test that an answer contains the correct media content descriptions when
2848// constraints have been set and streams are sent.
2849TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002850 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002852 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853 SetRemoteDescriptionWithoutError(offer.release());
2854
htaa2a49d92016-03-04 02:51:39 -08002855 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002857 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002858 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859
2860 // TODO(perkj): Should the direction be set to SEND_ONLY?
2861 const cricket::ContentInfo* content =
2862 cricket::GetFirstAudioContent(answer->description());
2863 ASSERT_TRUE(content != NULL);
2864 EXPECT_FALSE(content->rejected);
2865
2866 // TODO(perkj): Should the direction be set to SEND_ONLY?
2867 content = cricket::GetFirstVideoContent(answer->description());
2868 ASSERT_TRUE(content != NULL);
2869 EXPECT_FALSE(content->rejected);
2870}
2871
2872TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2873 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002874 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002875 PeerConnectionInterface::RTCOfferAnswerOptions options;
2876 options.offer_to_receive_audio =
2877 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2878 options.voice_activity_detection = false;
2879
kwibergd1fe2812016-04-27 06:47:29 -07002880 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 const cricket::ContentInfo* content =
2883 cricket::GetFirstAudioContent(offer->description());
2884 EXPECT_TRUE(content != NULL);
2885 EXPECT_TRUE(VerifyNoCNCodecs(content));
2886}
2887
2888TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2889 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002890 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002892 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893 SetRemoteDescriptionWithoutError(offer.release());
2894
htaa2a49d92016-03-04 02:51:39 -08002895 cricket::MediaSessionOptions options;
2896 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002897 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898 const cricket::ContentInfo* content =
2899 cricket::GetFirstAudioContent(answer->description());
2900 ASSERT_TRUE(content != NULL);
2901 EXPECT_TRUE(VerifyNoCNCodecs(content));
2902}
2903
2904// This test verifies the call setup when remote answer with audio only and
2905// later updates with video.
2906TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002907 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2909 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2910
deadbeefab9b2d12015-10-14 11:33:11 -07002911 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002912 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913
2914 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002915 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2916 cricket::MD_RECVONLY, kActive, &options);
2917 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2918 cricket::MD_INACTIVE, kStopped, &options);
2919 local_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2921
2922 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2923 // and answer;
2924 SetLocalDescriptionWithoutError(offer);
2925 SetRemoteDescriptionWithoutError(answer);
2926
2927 video_channel_ = media_engine_->GetVideoChannel(0);
2928 voice_channel_ = media_engine_->GetVoiceChannel(0);
2929
zhihuang1c378ed2017-08-17 14:10:50 -07002930 ASSERT_TRUE(video_channel_ == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931
2932 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2933 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2934 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2935
2936 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002937 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07002938 local_recv_video_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 CreateAndSetRemoteOfferAndLocalAnswer();
2940
2941 video_channel_ = media_engine_->GetVideoChannel(0);
2942 voice_channel_ = media_engine_->GetVoiceChannel(0);
2943
zhihuang1c378ed2017-08-17 14:10:50 -07002944 ASSERT_TRUE(video_channel_ != nullptr);
2945 ASSERT_TRUE(voice_channel_ != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946
2947 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2948 ASSERT_EQ(1u, video_channel_->send_streams().size());
2949 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2950 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2951 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2952 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2953 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2954 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2955
2956 // Change session back to audio only.
zhihuang1c378ed2017-08-17 14:10:50 -07002957 // The remote side doesn't send and recv video.
deadbeefab9b2d12015-10-14 11:33:11 -07002958 SendAudioOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07002959 remote_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960 CreateAndSetRemoteOfferAndLocalAnswer();
2961
zhihuang1c378ed2017-08-17 14:10:50 -07002962 video_channel_ = media_engine_->GetVideoChannel(0);
2963 voice_channel_ = media_engine_->GetVoiceChannel(0);
2964
2965 // The audio is expected to be rejected.
2966 EXPECT_TRUE(video_channel_ == nullptr);
2967
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2969 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2970 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2971 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2972}
2973
2974// This test verifies the call setup when remote answer with video only and
2975// later updates with audio.
2976TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002977 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2979 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002980 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002981 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982
2983 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002984 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2985 cricket::MD_INACTIVE, kStopped, &options);
2986 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2987 cricket::MD_RECVONLY, kActive, &options);
2988 local_recv_audio_ = false;
2989 SessionDescriptionInterface* answer =
2990 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991
2992 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2993 // and answer.
2994 SetLocalDescriptionWithoutError(offer);
2995 SetRemoteDescriptionWithoutError(answer);
2996
2997 video_channel_ = media_engine_->GetVideoChannel(0);
2998 voice_channel_ = media_engine_->GetVoiceChannel(0);
2999
3000 ASSERT_TRUE(voice_channel_ == NULL);
3001 ASSERT_TRUE(video_channel_ != NULL);
3002
3003 EXPECT_EQ(0u, video_channel_->recv_streams().size());
3004 ASSERT_EQ(1u, video_channel_->send_streams().size());
3005 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
3006
3007 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07003008 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07003009 local_recv_audio_ = true;
3010 SessionDescriptionInterface* offer2 = CreateRemoteOffer();
3011 SetRemoteDescriptionWithoutError(offer2);
3012 cricket::MediaSessionOptions answer_options;
3013 // Disable the bundling here. If the media is bundled on audio
3014 // transport, then we can't reject the audio because switching the bundled
3015 // transport is not currently supported.
3016 // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704)
3017 answer_options.bundle_enabled = false;
3018 SessionDescriptionInterface* answer2 = CreateAnswer(answer_options);
3019 SetLocalDescriptionWithoutError(answer2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020
3021 voice_channel_ = media_engine_->GetVoiceChannel(0);
olka3c747662017-08-17 06:50:32 -07003022
zhihuang1c378ed2017-08-17 14:10:50 -07003023 ASSERT_TRUE(voice_channel_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003024 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
3025 ASSERT_EQ(1u, voice_channel_->send_streams().size());
3026 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
3027 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
3028
3029 // Change session back to video only.
zhihuang1c378ed2017-08-17 14:10:50 -07003030 // The remote side doesn't send and recv audio.
deadbeefab9b2d12015-10-14 11:33:11 -07003031 SendVideoOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07003032 remote_recv_audio_ = false;
3033 SessionDescriptionInterface* offer3 = CreateRemoteOffer();
3034 SetRemoteDescriptionWithoutError(offer3);
3035 SessionDescriptionInterface* answer3 = CreateAnswer(answer_options);
3036 SetLocalDescriptionWithoutError(answer3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003037
3038 video_channel_ = media_engine_->GetVideoChannel(0);
3039 voice_channel_ = media_engine_->GetVoiceChannel(0);
3040
zhihuang1c378ed2017-08-17 14:10:50 -07003041 // The video is expected to be rejected.
3042 EXPECT_TRUE(voice_channel_ == nullptr);
3043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 ASSERT_EQ(1u, video_channel_->recv_streams().size());
3045 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
3046 ASSERT_EQ(1u, video_channel_->send_streams().size());
3047 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
3048}
3049
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003051 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003052 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003053 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003054 VerifyCryptoParams(offer->description());
3055 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07003056 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057 VerifyCryptoParams(answer->description());
3058}
3059
jbauchcb560652016-08-04 05:20:32 -07003060TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
3061 InitWithGcm();
3062 SendAudioVideoStream1();
3063 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
3064 VerifyCryptoParams(offer->description(), true);
3065 SetRemoteDescriptionWithoutError(offer.release());
3066 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3067 VerifyCryptoParams(answer->description(), true);
3068}
3069
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003071 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003072 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003073 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003074 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075 VerifyNoCryptoParams(offer->description(), false);
3076}
3077
3078TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003079 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080 VerifyAnswerFromNonCryptoOffer();
3081}
3082
3083TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003084 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 VerifyAnswerFromCryptoOffer();
3086}
3087
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003088// This test verifies that setLocalDescription fails if
3089// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
3090TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003092 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003093 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003094
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003095 std::string sdp;
3096 RemoveIceUfragPwdLines(offer.get(), &sdp);
3097 SessionDescriptionInterface* modified_offer =
3098 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003099 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003100}
3101
3102// This test verifies that setRemoteDescription fails if
3103// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
3104TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003105 Init();
kwibergd1fe2812016-04-27 06:47:29 -07003106 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003107 std::string sdp;
3108 RemoveIceUfragPwdLines(offer.get(), &sdp);
3109 SessionDescriptionInterface* modified_offer =
3110 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003111 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003112}
3113
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003114// This test verifies that setLocalDescription fails if local offer has
3115// too short ice ufrag and pwd strings.
3116TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003117 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003118 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003119 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003120 // Modifying ice ufrag and pwd in local offer with strings smaller than the
3121 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08003122 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003123 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08003124 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003125
3126 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08003127 offer.reset(CreateOffer());
3128 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
3129 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003130}
3131
3132// This test verifies that setRemoteDescription fails if remote offer has
3133// too short ice ufrag and pwd strings.
3134TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003135 Init();
kwibergd1fe2812016-04-27 06:47:29 -07003136 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003137 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
3138 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08003139 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003140 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08003141 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003142
deadbeef0ed85b22016-02-23 17:24:52 -08003143 offer.reset(CreateRemoteOffer());
3144 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
3145 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003146}
3147
Honghai Zhang04e91462015-12-11 14:26:22 -08003148// Test that if the remote offer indicates the peer requested ICE restart (via
3149// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3150TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07003151 Init();
honghaiz503726c2015-07-31 12:37:38 -07003152
3153 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07003154 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08003155 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003156 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3157 0, "", "", "relay", 0, "");
3158 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3159 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003160 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3161 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003162 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3163
3164 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003165 offer.reset(CreateRemoteOffer());
3166 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003167 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3168 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3169 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003170 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
3171 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003172 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3173
3174 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003175 offer.reset(CreateRemoteOffer());
3176 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003177 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3178 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3179 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003180 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
3181 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003182 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3183
3184 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003185 offer.reset(CreateRemoteOffer());
3186 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3187 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003188 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3189}
3190
Honghai Zhang04e91462015-12-11 14:26:22 -08003191// Test that if the remote answer indicates the peer requested ICE restart (via
3192// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3193TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
3194 Init();
3195 SessionDescriptionInterface* offer = CreateOffer();
3196 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08003197
3198 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07003199 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08003200 answer->set_type(JsepSessionDescription::kPrAnswer);
3201 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003202 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3203 0, "", "", "relay", 0, "");
3204 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3205 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003206 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
3207 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003208 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3209
3210 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003211 answer.reset(CreateRemoteAnswer(offer));
3212 answer->set_type(JsepSessionDescription::kPrAnswer);
3213 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003214 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3215 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3216 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003217 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3218 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003219 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3220
3221 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003222 answer.reset(CreateRemoteAnswer(offer));
3223 answer->set_type(JsepSessionDescription::kPrAnswer);
3224 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003225 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3226 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3227 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003228 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3229 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003230 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3231
3232 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003233 answer.reset(CreateRemoteAnswer(offer));
3234 answer->set_type(JsepSessionDescription::kPrAnswer);
3235 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3236 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003237 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3238}
3239
Donald Curtisd4f769d2015-05-28 09:48:21 -07003240// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003241// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003242TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3243 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3244
3245 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003246 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003247
zhihuang1c378ed2017-08-17 14:10:50 -07003248 cricket::MediaSessionOptions offer_options;
3249 GetOptionsForRemoteOffer(&offer_options);
3250 offer_options.bundle_enabled = true;
Donald Curtisd4f769d2015-05-28 09:48:21 -07003251
zhihuang1c378ed2017-08-17 14:10:50 -07003252 SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003253 SetRemoteDescriptionWithoutError(offer);
3254
zhihuang1c378ed2017-08-17 14:10:50 -07003255 cricket::MediaSessionOptions answer_options;
3256 answer_options.bundle_enabled = true;
3257 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003258 SetLocalDescriptionWithoutError(answer);
3259
deadbeefcbecd352015-09-23 11:50:27 -07003260 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3261 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003262
deadbeefcbecd352015-09-23 11:50:27 -07003263 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003264 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003265
3266 // Checks if one of the transport channels contains a connection using a given
3267 // port.
eladalon1cc5fc32017-08-23 04:15:18 -07003268 auto connection_with_remote_port = [this](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003269 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3270 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003271 for (auto& chan_stat : kv.second.channel_stats) {
3272 for (auto& conn_info : chan_stat.connection_infos) {
3273 if (conn_info.remote_candidate.address().port() == port) {
3274 return true;
3275 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003276 }
3277 }
3278 }
3279 return false;
3280 };
3281
3282 EXPECT_FALSE(connection_with_remote_port(5000));
3283 EXPECT_FALSE(connection_with_remote_port(5001));
3284 EXPECT_FALSE(connection_with_remote_port(6000));
3285
3286 // The way the *_WAIT checks work is they only wait if the condition fails,
3287 // which does not help in the case where state is not changing. This is
3288 // problematic in this test since we want to verify that adding a video
3289 // candidate does _not_ change state. So we interleave candidates and assume
3290 // that messages are executed in the order they were posted.
3291
3292 // First audio candidate.
3293 cricket::Candidate candidate0;
3294 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3295 candidate0.set_component(1);
3296 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003297 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003298 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3299 candidate0);
3300 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3301
3302 // Video candidate.
3303 cricket::Candidate candidate1;
3304 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3305 candidate1.set_component(1);
3306 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003307 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003308 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3309 candidate1);
3310 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3311
3312 // Second audio candidate.
3313 cricket::Candidate candidate2;
3314 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3315 candidate2.set_component(1);
3316 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003317 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003318 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3319 candidate2);
3320 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3321
3322 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3323 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3324
3325 // No need here for a _WAIT check since we are checking that state hasn't
3326 // changed: if this is false we would be doing waits for nothing and if this
3327 // is true then there will be no messages processed anyways.
3328 EXPECT_FALSE(connection_with_remote_port(6000));
3329}
3330
deadbeefcbecd352015-09-23 11:50:27 -07003331// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003332TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3333 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003334 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003335
3336 PeerConnectionInterface::RTCOfferAnswerOptions options;
3337 options.use_rtp_mux = true;
3338
3339 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003341
deadbeefcbecd352015-09-23 11:50:27 -07003342 EXPECT_NE(session_->voice_rtp_transport_channel(),
3343 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003344
deadbeefab9b2d12015-10-14 11:33:11 -07003345 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003346 SessionDescriptionInterface* answer =
3347 CreateRemoteAnswer(session_->local_description());
3348 SetRemoteDescriptionWithoutError(answer);
3349
deadbeefcbecd352015-09-23 11:50:27 -07003350 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3351 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003352}
3353
deadbeefcbecd352015-09-23 11:50:27 -07003354// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003355TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3356 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003357 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003358
Donald Curtis0e209b02015-03-24 09:29:54 -07003359 PeerConnectionInterface::RTCOfferAnswerOptions options;
3360 options.use_rtp_mux = true;
3361
3362 SessionDescriptionInterface* offer = CreateOffer(options);
3363 SetLocalDescriptionWithoutError(offer);
3364
deadbeefcbecd352015-09-23 11:50:27 -07003365 EXPECT_NE(session_->voice_rtp_transport_channel(),
3366 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003367
deadbeefab9b2d12015-10-14 11:33:11 -07003368 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003369
3370 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003371 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003372 CreateRemoteAnswer(session_->local_description()));
3373 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3374 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3375 JsepSessionDescription* modified_answer =
3376 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3377 modified_answer->Initialize(answer_copy, "1", "1");
3378 SetRemoteDescriptionWithoutError(modified_answer); //
3379
deadbeefcbecd352015-09-23 11:50:27 -07003380 EXPECT_NE(session_->voice_rtp_transport_channel(),
3381 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003382}
3383
3384// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3385TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3386 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003387 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003388
3389 PeerConnectionInterface::RTCOfferAnswerOptions options;
3390 options.use_rtp_mux = true;
3391
3392 SessionDescriptionInterface* offer = CreateOffer(options);
3393 SetLocalDescriptionWithoutError(offer);
3394
deadbeefcbecd352015-09-23 11:50:27 -07003395 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3396 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003397
deadbeefab9b2d12015-10-14 11:33:11 -07003398 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003399 SessionDescriptionInterface* answer =
3400 CreateRemoteAnswer(session_->local_description());
3401 SetRemoteDescriptionWithoutError(answer);
3402
deadbeefcbecd352015-09-23 11:50:27 -07003403 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3404 session_->video_rtp_transport_channel());
3405}
3406
3407// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3408// audio content in the answer.
3409TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3410 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003411 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003412
3413 PeerConnectionInterface::RTCOfferAnswerOptions options;
3414 options.use_rtp_mux = true;
3415
3416 SessionDescriptionInterface* offer = CreateOffer(options);
3417 SetLocalDescriptionWithoutError(offer);
3418
3419 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3420 session_->video_rtp_transport_channel());
3421
zhihuang1c378ed2017-08-17 14:10:50 -07003422 SendVideoOnlyStream2();
3423 local_send_audio_ = false;
3424 remote_recv_audio_ = false;
deadbeefcbecd352015-09-23 11:50:27 -07003425 cricket::MediaSessionOptions recv_options;
zhihuang1c378ed2017-08-17 14:10:50 -07003426 GetOptionsForRemoteAnswer(&recv_options);
deadbeefcbecd352015-09-23 11:50:27 -07003427 SessionDescriptionInterface* answer =
3428 CreateRemoteAnswer(session_->local_description(), recv_options);
3429 SetRemoteDescriptionWithoutError(answer);
3430
deadbeefd59daf82015-10-14 15:02:44 -07003431 EXPECT_TRUE(nullptr == session_->voice_channel());
3432 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003433
deadbeefd59daf82015-10-14 15:02:44 -07003434 session_->Close();
3435 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3436 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3437 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3438 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003439}
3440
3441// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3442TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3443 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003444 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003445
Donald Curtis0e209b02015-03-24 09:29:54 -07003446 PeerConnectionInterface::RTCOfferAnswerOptions options;
3447 options.use_rtp_mux = true;
3448
3449 SessionDescriptionInterface* offer = CreateOffer(options);
3450 SetLocalDescriptionWithoutError(offer);
3451
deadbeefcbecd352015-09-23 11:50:27 -07003452 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3453 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003454
deadbeefab9b2d12015-10-14 11:33:11 -07003455 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003456
3457 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003458 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 CreateRemoteAnswer(session_->local_description()));
3460 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3461 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3462 JsepSessionDescription* modified_answer =
3463 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3464 modified_answer->Initialize(answer_copy, "1", "1");
3465 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466
deadbeefcbecd352015-09-23 11:50:27 -07003467 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3468 session_->video_rtp_transport_channel());
3469}
3470
3471// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3472TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3473 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003474 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003475
3476 SessionDescriptionInterface* offer = CreateRemoteOffer();
3477 SetRemoteDescriptionWithoutError(offer);
3478
3479 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3480 session_->video_rtp_transport_channel());
3481
deadbeefab9b2d12015-10-14 11:33:11 -07003482 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003483 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003484 SetLocalDescriptionWithoutError(answer);
3485
3486 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3487 session_->video_rtp_transport_channel());
3488}
3489
3490// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3491TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3492 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003493 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003494
3495 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003496 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003497 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3498 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3499 JsepSessionDescription* modified_offer =
3500 new JsepSessionDescription(JsepSessionDescription::kOffer);
3501 modified_offer->Initialize(offer_copy, "1", "1");
3502
3503 // Expect an error when applying the remote description
3504 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3505 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003506}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507
Peter Thatcher4eddf182015-04-30 10:55:59 -07003508// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003509TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3510 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003511 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512
zhihuang1c378ed2017-08-17 14:10:50 -07003513 PeerConnectionInterface::RTCOfferAnswerOptions rtc_options;
3514 rtc_options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515
zhihuang1c378ed2017-08-17 14:10:50 -07003516 SessionDescriptionInterface* offer = CreateOffer(rtc_options);
Donald Curtis0e209b02015-03-24 09:29:54 -07003517 SetLocalDescriptionWithoutError(offer);
3518
deadbeefcbecd352015-09-23 11:50:27 -07003519 EXPECT_NE(session_->voice_rtp_transport_channel(),
3520 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003521
deadbeefab9b2d12015-10-14 11:33:11 -07003522 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003523 SessionDescriptionInterface* answer =
3524 CreateRemoteAnswer(session_->local_description());
3525 SetRemoteDescriptionWithoutError(answer);
3526
3527 // This should lead to an audio-only call but isn't implemented
3528 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003529 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3530 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003531}
3532
deadbeefcbecd352015-09-23 11:50:27 -07003533// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003534TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3535 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003536 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003537 PeerConnectionInterface::RTCOfferAnswerOptions options;
3538 options.use_rtp_mux = true;
3539
3540 SessionDescriptionInterface* offer = CreateOffer(options);
3541 SetLocalDescriptionWithoutError(offer);
3542
deadbeefcbecd352015-09-23 11:50:27 -07003543 EXPECT_NE(session_->voice_rtp_transport_channel(),
3544 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003545
deadbeefab9b2d12015-10-14 11:33:11 -07003546 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003547
3548 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003549 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003550 CreateRemoteAnswer(session_->local_description()));
3551 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3552 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3553 JsepSessionDescription* modified_answer =
3554 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3555 modified_answer->Initialize(answer_copy, "1", "1");
3556 SetRemoteDescriptionWithoutError(modified_answer); //
3557
deadbeefcbecd352015-09-23 11:50:27 -07003558 EXPECT_NE(session_->voice_rtp_transport_channel(),
3559 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560}
3561
Peter Thatcher4eddf182015-04-30 10:55:59 -07003562// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3563TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3564 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003565 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003566
3567 PeerConnectionInterface::RTCOfferAnswerOptions options;
3568 options.use_rtp_mux = true;
3569
3570 SessionDescriptionInterface* offer = CreateOffer(options);
3571 SetRemoteDescriptionWithoutError(offer);
3572
deadbeefcbecd352015-09-23 11:50:27 -07003573 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3574 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003575}
3576
skvlad6c87a672016-05-17 17:49:52 -07003577// Adding a new channel to a BUNDLE which is already connected should directly
3578// assign the bundle transport to the channel, without first setting a
3579// disconnected non-bundle transport and then replacing it. The application
3580// should not receive any changes in the ICE state.
3581TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3582 LoopbackNetworkConfiguration config;
3583 LoopbackNetworkManager loopback_network_manager(this, config);
3584 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3585 // connected. Disabling either of these two means that we need to wait for the
3586 // answer to find out if more transports are needed.
3587 configuration_.bundle_policy =
3588 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003589 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07003590 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003591
3592 // Negotiate an audio channel with MAX_BUNDLE enabled.
3593 SendAudioOnlyStream2();
3594 SessionDescriptionInterface* offer = CreateOffer();
3595 SetLocalDescriptionWithoutError(offer);
3596 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3597 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3598 std::string sdp;
3599 offer->ToString(&sdp);
3600 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3601 JsepSessionDescription::kAnswer, sdp, nullptr);
3602 ASSERT_TRUE(answer != NULL);
3603 SetRemoteDescriptionWithoutError(answer);
3604
3605 // Wait for the ICE state to stabilize.
3606 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3607 observer_.ice_connection_state_, kIceCandidatesTimeout);
3608 observer_.ice_connection_state_history_.clear();
3609
3610 // Now add a video channel which should be using the same bundle transport.
3611 SendAudioVideoStream2();
3612 offer = CreateOffer();
3613 offer->ToString(&sdp);
3614 SetLocalDescriptionWithoutError(offer);
3615 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3616 sdp, nullptr);
3617 ASSERT_TRUE(answer != NULL);
3618 SetRemoteDescriptionWithoutError(answer);
3619
3620 // Wait for ICE state to stabilize
3621 rtc::Thread::Current()->ProcessMessages(0);
3622 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3623 observer_.ice_connection_state_, kIceCandidatesTimeout);
3624
3625 // No ICE state changes are expected to happen.
3626 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3627}
3628
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003629TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3630 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003632
3633 PeerConnectionInterface::RTCOfferAnswerOptions options;
3634 SessionDescriptionInterface* offer = CreateOffer(options);
3635 SetLocalDescriptionWithoutError(offer);
3636
deadbeefcbecd352015-09-23 11:50:27 -07003637 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3638 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003639
deadbeefab9b2d12015-10-14 11:33:11 -07003640 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003641 SessionDescriptionInterface* answer =
3642 CreateRemoteAnswer(session_->local_description());
3643 SetRemoteDescriptionWithoutError(answer);
3644
deadbeefcbecd352015-09-23 11:50:27 -07003645 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3646 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003647}
3648
3649TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3650 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003651 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003652
3653 PeerConnectionInterface::RTCOfferAnswerOptions options;
3654 SessionDescriptionInterface* offer = CreateOffer(options);
3655 SetLocalDescriptionWithoutError(offer);
3656
deadbeefcbecd352015-09-23 11:50:27 -07003657 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3658 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003659
deadbeefab9b2d12015-10-14 11:33:11 -07003660 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003661 SessionDescriptionInterface* answer =
3662 CreateRemoteAnswer(session_->local_description());
3663 SetRemoteDescriptionWithoutError(answer);
3664
deadbeefcbecd352015-09-23 11:50:27 -07003665 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3666 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003667}
3668
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003669// This test verifies that SetLocalDescription and SetRemoteDescription fails
3670// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3671TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003672 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003673 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003674
3675 PeerConnectionInterface::RTCOfferAnswerOptions options;
3676 options.use_rtp_mux = true;
3677
3678 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003679 std::string offer_str;
3680 offer->ToString(&offer_str);
3681 // Disable rtcp-mux
3682 const std::string rtcp_mux = "rtcp-mux";
3683 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003684 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003685 xrtcp_mux.c_str(), xrtcp_mux.length(),
3686 &offer_str);
Steve Anton6d64e9a2017-09-12 09:44:05 -07003687 SessionDescriptionInterface* local_offer = CreateSessionDescription(
3688 SessionDescriptionInterface::kOffer, offer_str, nullptr);
3689 ASSERT_TRUE(local_offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003690 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
Steve Anton6d64e9a2017-09-12 09:44:05 -07003691
3692 SessionDescriptionInterface* remote_offer = CreateSessionDescription(
3693 SessionDescriptionInterface::kOffer, offer_str, nullptr);
3694 ASSERT_TRUE(remote_offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003695 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
Steve Anton6d64e9a2017-09-12 09:44:05 -07003696
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003697 // Trying unmodified SDP.
3698 SetLocalDescriptionWithoutError(offer);
3699}
3700
jbauchcb560652016-08-04 05:20:32 -07003701TEST_F(WebRtcSessionTest, SetSetupGcm) {
3702 InitWithGcm();
3703 SendAudioVideoStream1();
3704 CreateAndSetRemoteOfferAndLocalAnswer();
3705}
3706
deadbeefd59daf82015-10-14 15:02:44 -07003707// This test verifies the |initial_offerer| flag when session initiates the
3708// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003710 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003711 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003712 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003713 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3714 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003715 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003717 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003718}
3719
deadbeefd59daf82015-10-14 15:02:44 -07003720// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003721TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003722 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003723 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003724 SessionDescriptionInterface* offer = CreateRemoteOffer();
3725 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003726 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003727
deadbeefd59daf82015-10-14 15:02:44 -07003728 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003729 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003730 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003731}
3732
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003733// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3734TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003735 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003736 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003737 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003738 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003739 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 CreateRemoteAnswer(session_->local_description()));
3741
3742 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3743 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003744 JsepSessionDescription* modified_answer =
3745 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
3747 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3748 answer->session_id(),
3749 answer->session_version()));
Zhi Huang2a5e4262017-09-14 01:15:03 -07003750 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
3751 modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003752
wu@webrtc.org4e393072014-04-07 17:04:35 +00003753 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754 std::string sdp;
3755 EXPECT_TRUE(answer->ToString(&sdp));
3756 const std::string kAudioMid = "a=mid:audio";
3757 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003758 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003759 kAudioMidReplaceStr.c_str(),
3760 kAudioMidReplaceStr.length(),
3761 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003762 SessionDescriptionInterface* modified_answer1 =
3763 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
Zhi Huang2a5e4262017-09-14 01:15:03 -07003764 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
3765 modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766
wu@webrtc.org4e393072014-04-07 17:04:35 +00003767 // Different media types.
3768 EXPECT_TRUE(answer->ToString(&sdp));
3769 const std::string kAudioMline = "m=audio";
3770 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003771 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003772 kAudioMlineReplaceStr.c_str(),
3773 kAudioMlineReplaceStr.length(),
3774 &sdp);
3775 SessionDescriptionInterface* modified_answer2 =
3776 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
Zhi Huang2a5e4262017-09-14 01:15:03 -07003777 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
3778 modified_answer2);
wu@webrtc.org4e393072014-04-07 17:04:35 +00003779
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003780 SetRemoteDescriptionWithoutError(answer.release());
3781}
3782
3783// Verifying remote offer and local answer have matching m-lines as per
3784// RFC 3264.
3785TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003786 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003787 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003788 SessionDescriptionInterface* offer = CreateRemoteOffer();
3789 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003790 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003791
3792 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3793 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003794 JsepSessionDescription* modified_answer =
3795 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
3797 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3798 answer->session_id(),
3799 answer->session_version()));
Zhi Huang2a5e4262017-09-14 01:15:03 -07003800 SetLocalDescriptionAnswerExpectError(kMlineMismatchInAnswer, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003801 SetLocalDescriptionWithoutError(answer);
3802}
3803
3804// This test verifies that WebRtcSession does not start candidate allocation
3805// before SetLocalDescription is called.
3806TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003807 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003808 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003809 SessionDescriptionInterface* offer = CreateRemoteOffer();
3810 cricket::Candidate candidate;
3811 candidate.set_component(1);
3812 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3813 candidate);
3814 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3815 cricket::Candidate candidate1;
3816 candidate1.set_component(1);
3817 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3818 candidate1);
3819 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3820 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003821 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3822 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003823
3824 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003825 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003826 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3827 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3828
htaa2a49d92016-03-04 02:51:39 -08003829 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003830 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003831 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3832}
3833
3834// This test verifies that crypto parameter is updated in local session
3835// description as per security policy set in MediaSessionDescriptionFactory.
3836TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003837 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003838 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003839 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003840
3841 // Making sure SetLocalDescription correctly sets crypto value in
3842 // SessionDescription object after de-serialization of sdp string. The value
3843 // will be set as per MediaSessionDescriptionFactory.
3844 std::string offer_str;
3845 offer->ToString(&offer_str);
3846 SessionDescriptionInterface* jsep_offer_str =
3847 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3848 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003849 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3850 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003851}
3852
3853// This test verifies the crypto parameter when security is disabled.
3854TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003855 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003856 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003857 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003858 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003859
3860 // Making sure SetLocalDescription correctly sets crypto value in
3861 // SessionDescription object after de-serialization of sdp string. The value
3862 // will be set as per MediaSessionDescriptionFactory.
3863 std::string offer_str;
3864 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003865 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003866 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3867 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003868 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3869 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870}
3871
3872// This test verifies that an answer contains new ufrag and password if an offer
3873// with new ufrag and password is received.
3874TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003875 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003876 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003877 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07003878 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003879 SetRemoteDescriptionWithoutError(offer.release());
3880
deadbeefab9b2d12015-10-14 11:33:11 -07003881 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003882 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003883 SetLocalDescriptionWithoutError(answer.release());
3884
3885 // Receive an offer with new ufrag and password.
zhihuang1c378ed2017-08-17 14:10:50 -07003886 for (size_t i = 0; i < options.media_description_options.size(); ++i) {
3887 options.media_description_options[i].transport_options.ice_restart = true;
deadbeef0ed85b22016-02-23 17:24:52 -08003888 }
zhihuang1c378ed2017-08-17 14:10:50 -07003889
kwibergd1fe2812016-04-27 06:47:29 -07003890 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003891 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003892 SetRemoteDescriptionWithoutError(updated_offer1.release());
3893
kwibergd1fe2812016-04-27 06:47:29 -07003894 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003895
deadbeef0ed85b22016-02-23 17:24:52 -08003896 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3897 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003898
deadbeef0ed85b22016-02-23 17:24:52 -08003899 // Even a second answer (created before the description is set) should have
3900 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003901 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003902
3903 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3904 session_->local_description()->description()));
3905
3906 SetLocalDescriptionWithoutError(updated_answer2.release());
3907}
3908
3909// This test verifies that an answer contains new ufrag and password if an offer
3910// that changes either the ufrag or password (but not both) is received.
3911// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3912// a=ice-pwd attributes compared to the previous SDP from the peer, it
3913// indicates that ICE is restarting for this media stream."
3914TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3915 Init();
3916 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003917 GetOptionsForRemoteOffer(&options);
deadbeef0ed85b22016-02-23 17:24:52 -08003918 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003919 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003920 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3921 SetRemoteDescriptionWithoutError(offer.release());
3922
3923 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003924 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003925 SetLocalDescriptionWithoutError(answer.release());
3926
3927 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003928 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003929 CreateRemoteOffer(options, session_->remote_description()));
3930 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3931 "original_password12345");
3932 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3933
kwibergd1fe2812016-04-27 06:47:29 -07003934 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003935 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3936 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003937 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003938
3939 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003940 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003941 CreateRemoteOffer(options, session_->remote_description()));
3942 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3943 "modified_password12345");
3944 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3945
kwibergd1fe2812016-04-27 06:47:29 -07003946 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003947 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3948 session_->local_description()->description()));
3949 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003950}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003951
wu@webrtc.org91053e72013-08-10 07:18:04 +00003952// This test verifies that an answer contains old ufrag and password if an offer
3953// with old ufrag and password is received.
3954TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003955 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003956 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003957 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07003958 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003959 SetRemoteDescriptionWithoutError(offer.release());
3960
deadbeefab9b2d12015-10-14 11:33:11 -07003961 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003962 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003963 SetLocalDescriptionWithoutError(answer.release());
3964
3965 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003966 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003967 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003968 SetRemoteDescriptionWithoutError(updated_offer2.release());
3969
kwibergd1fe2812016-04-27 06:47:29 -07003970 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003971
deadbeef0ed85b22016-02-23 17:24:52 -08003972 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3973 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003974
3975 SetLocalDescriptionWithoutError(updated_answer2.release());
3976}
3977
deadbeef0ed85b22016-02-23 17:24:52 -08003978// This test verifies that if an offer does an ICE restart on some, but not all
3979// media sections, the answer will change the ufrag/password in the correct
3980// media sections.
3981TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3982 Init();
3983 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003984 GetOptionsForRemoteOffer(&options);
deadbeef0ed85b22016-02-23 17:24:52 -08003985 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003986 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003987
3988 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3989 "aaaaaaaaaaaaaaaaaaaaaa");
3990 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3991 "bbbbbbbbbbbbbbbbbbbbbb");
3992 SetRemoteDescriptionWithoutError(offer.release());
3993
3994 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003995 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003996 SetLocalDescriptionWithoutError(answer.release());
3997
3998 // Receive an offer with new ufrag and password, but only for the video media
3999 // section.
kwibergd1fe2812016-04-27 06:47:29 -07004000 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08004001 CreateRemoteOffer(options, session_->remote_description()));
4002 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
4003 "cccccccccccccccccccccc");
4004 SetRemoteDescriptionWithoutError(updated_offer.release());
4005
kwibergd1fe2812016-04-27 06:47:29 -07004006 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08004007
4008 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
4009 session_->local_description()->description(),
4010 cricket::MEDIA_TYPE_AUDIO));
4011
4012 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
4013 session_->local_description()->description(),
4014 cricket::MEDIA_TYPE_VIDEO));
4015
4016 SetLocalDescriptionWithoutError(updated_answer.release());
4017}
4018
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004019TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004020 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004021 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004022 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004023 const std::string session_id_orig = offer->session_id();
4024 const std::string session_version_orig = offer->session_version();
4025 SetLocalDescriptionWithoutError(offer);
4026
4027 video_channel_ = media_engine_->GetVideoChannel(0);
4028 video_channel_->set_fail_set_send_codecs(true);
4029
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00004030 SessionDescriptionInterface* answer =
4031 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004032 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07004033
4034 // Test that after a content error, setting any description will
4035 // result in an error.
4036 video_channel_->set_fail_set_send_codecs(false);
4037 answer = CreateRemoteAnswer(session_->local_description());
4038 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
4039 offer = CreateRemoteOffer();
4040 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004041}
4042
4043// Runs the loopback call test with BUNDLE and STUN disabled.
4044TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
4045 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004046 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004047 cricket::PORTALLOCATOR_DISABLE_STUN |
4048 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004049 TestLoopbackCall();
4050}
4051
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004052TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004053 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004054 cricket::PORTALLOCATOR_DISABLE_STUN |
4055 cricket::PORTALLOCATOR_ENABLE_IPV6 |
4056 cricket::PORTALLOCATOR_DISABLE_RELAY);
4057
4058 // best connection is IPv6 since it has higher network preference.
4059 LoopbackNetworkConfiguration config;
4060 config.test_ipv6_network_ = true;
4061 config.best_connection_after_initial_ice_converged_ =
4062 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
4063
4064 TestLoopbackCall(config);
4065}
4066
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00004067// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00004068TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004069 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
4070 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00004071 TestLoopbackCall();
4072}
4073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004074TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08004075 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004076 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004077 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08004078 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08004079 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004080}
4081
Henrik Boström87713d02015-08-25 09:53:21 +02004082TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08004083 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00004084 options_.disable_sctp_data_channels = false;
4085
Henrik Boström87713d02015-08-25 09:53:21 +02004086 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004087
4088 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004089 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
4090}
4091
4092// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
4093// before and after BUNDLE is negotiated.
4094TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08004095 SetFactoryDtlsSrtp();
4096 InitWithDtls(GetParam());
4097
4098 // Initially these fields should be empty.
4099 EXPECT_FALSE(session_->sctp_content_name());
4100 EXPECT_FALSE(session_->sctp_transport_name());
4101
4102 // Create offer with audio/video/data.
4103 // Default bundle policy is "balanced", so data should be using its own
4104 // transport.
4105 SendAudioVideoStream1();
4106 CreateDataChannel();
4107 InitiateCall();
4108 ASSERT_TRUE(session_->sctp_content_name());
4109 ASSERT_TRUE(session_->sctp_transport_name());
4110 EXPECT_EQ("data", *session_->sctp_content_name());
4111 EXPECT_EQ("data", *session_->sctp_transport_name());
4112
4113 // Create answer that finishes BUNDLE negotiation, which means everything
4114 // should be bundled on the first transport (audio).
4115 cricket::MediaSessionOptions answer_options;
deadbeef953c2ce2017-01-09 14:53:41 -08004116 answer_options.bundle_enabled = true;
4117 answer_options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07004118 GetOptionsForAnswer(&answer_options);
deadbeef953c2ce2017-01-09 14:53:41 -08004119 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
4120 session_->local_description(), answer_options, cricket::SEC_DISABLED));
4121 ASSERT_TRUE(session_->sctp_content_name());
4122 ASSERT_TRUE(session_->sctp_transport_name());
4123 EXPECT_EQ("data", *session_->sctp_content_name());
4124 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004125}
4126
Henrik Boström87713d02015-08-25 09:53:21 +02004127TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02004128 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004129
kwibergd1fe2812016-04-27 06:47:29 -07004130 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004131 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004132 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
4133}
4134
Henrik Boström87713d02015-08-25 09:53:21 +02004135TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004136 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02004137 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004138
4139 // Create remote offer with SCTP.
4140 cricket::MediaSessionOptions options;
4141 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07004142 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004143 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004144 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004145 SetRemoteDescriptionWithoutError(offer);
4146
4147 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07004148 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004149 EXPECT_TRUE(answer != NULL);
4150 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
4151 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004152}
4153
deadbeef953c2ce2017-01-09 14:53:41 -08004154// Test that if DTLS is disabled, we don't end up with an SctpTransport
4155// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004156TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004157 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004158 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004159
4160 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004161 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4162 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004163}
4164
deadbeef953c2ce2017-01-09 14:53:41 -08004165// Test that if DTLS is enabled, we end up with an SctpTransport created
4166// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004167TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02004168 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004169
4170 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004171 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4172 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004173}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004174
deadbeef953c2ce2017-01-09 14:53:41 -08004175// Test that if SCTP is disabled, we don't end up with an SctpTransport
4176// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004177TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00004178 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004179 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004180
4181 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004182 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4183 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004184}
4185
Henrik Boström87713d02015-08-25 09:53:21 +02004186TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004187 const int new_send_port = 9998;
4188 const int new_recv_port = 7775;
4189
Henrik Boström87713d02015-08-25 09:53:21 +02004190 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004191 SetFactoryDtlsSrtp();
4192
4193 // By default, don't actually add the codecs to desc_factory_; they don't
4194 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4195 // let the session description get parsed. That'll get the proper codecs
4196 // into the stream.
4197 cricket::MediaSessionOptions options;
Steve Anton6d64e9a2017-09-12 09:44:05 -07004198 SessionDescriptionInterface* offer =
4199 CreateRemoteOfferWithSctpPort("stream1", new_send_port, options);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004200
4201 // SetRemoteDescription will take the ownership of the offer.
4202 SetRemoteDescriptionWithoutError(offer);
4203
htaa2a49d92016-03-04 02:51:39 -08004204 SessionDescriptionInterface* answer =
4205 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004206 ASSERT_TRUE(answer != NULL);
4207
4208 // Now set the local description, which'll take ownership of the answer.
4209 SetLocalDescriptionWithoutError(answer);
4210
4211 // TEST PLAN: Set the port number to something new, set it in the SDP,
4212 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08004213 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07004214 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004215 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
4216 EXPECT_EQ(
4217 new_recv_port,
4218 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
4219 EXPECT_EQ(
4220 new_send_port,
4221 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004222}
4223
deadbeef953c2ce2017-01-09 14:53:41 -08004224// Verifies that when a session's SctpTransport receives an OPEN message,
4225// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004226// config.
4227TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004228 InitWithDtls(GetParam());
4229
4230 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004231 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4232 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004233
deadbeef953c2ce2017-01-09 14:53:41 -08004234 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004235 webrtc::DataChannelInit config;
4236 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004237 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004238 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4239 cricket::ReceiveDataParams params;
4240 params.ssrc = config.id;
4241 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004242 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4243 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004244
deadbeef953c2ce2017-01-09 14:53:41 -08004245 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004246 EXPECT_EQ(config.id, last_data_channel_config_.id);
4247 EXPECT_FALSE(last_data_channel_config_.negotiated);
4248 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4249 last_data_channel_config_.open_handshake_role);
4250}
4251
4252TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004253 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004254 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004255
htaa2a49d92016-03-04 02:51:39 -08004256 configuration_.certificates.push_back(certificate);
4257 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004258 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4259
4260 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4261}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004262
Henrik Boström87713d02015-08-25 09:53:21 +02004263// Verifies that CreateOffer succeeds when CreateOffer is called before async
4264// identity generation is finished (even if a certificate is provided this is
4265// an async op).
4266TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004267 InitWithDtls(GetParam());
4268
Henrik Boströmd8281982015-08-27 10:12:24 +02004269 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004270 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004271 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004272
wu@webrtc.org91053e72013-08-10 07:18:04 +00004273 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004274 VerifyNoCryptoParams(offer->description(), true);
4275 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004276}
4277
4278// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004279// identity generation is finished (even if a certificate is provided this is
4280// an async op).
4281TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004282 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004283 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004284
4285 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004286 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07004287 std::unique_ptr<JsepSessionDescription> offer(
4288 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004289 ASSERT_TRUE(offer.get() != NULL);
4290 SetRemoteDescriptionWithoutError(offer.release());
4291
kwibergd1fe2812016-04-27 06:47:29 -07004292 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004293 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004294 VerifyNoCryptoParams(answer->description(), true);
4295 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004296}
4297
4298// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004299// identity generation is finished (even if a certificate is provided this is
4300// an async op).
4301TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004302 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004303
Henrik Boströmd8281982015-08-27 10:12:24 +02004304 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004305
kwibergd1fe2812016-04-27 06:47:29 -07004306 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004307 EXPECT_TRUE(offer != NULL);
4308}
4309
4310// Verifies that CreateOffer fails when CreateOffer is called after async
4311// identity generation fails.
4312TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004313 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004314
Henrik Boströmd8281982015-08-27 10:12:24 +02004315 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004316
kwibergd1fe2812016-04-27 06:47:29 -07004317 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004318 EXPECT_TRUE(offer == NULL);
4319}
4320
4321// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4322// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004323TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004324 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004325 VerifyMultipleAsyncCreateDescription(GetParam(),
4326 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004327}
4328
4329// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4330// before async identity generation fails.
4331TEST_F(WebRtcSessionTest,
4332 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004333 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4334 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004335}
4336
4337// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4338// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004339TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004340 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004341 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004342 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004343}
4344
4345// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4346// before async identity generation fails.
4347TEST_F(WebRtcSessionTest,
4348 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004349 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4350 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004351}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004352
4353// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4354// offer has no SDES crypto but only DTLS fingerprint.
4355TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4356 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004357 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004358 // Create a remote offer with secured transport disabled.
4359 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004360 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004361 JsepSessionDescription* offer(CreateRemoteOffer(
4362 options, cricket::SEC_DISABLED));
4363 // Adds a DTLS fingerprint to the remote offer.
4364 cricket::SessionDescription* sdp = offer->description();
4365 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4366 ASSERT_TRUE(audio != NULL);
4367 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4368 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004369 rtc::SSLFingerprint::CreateFromRfc4572(
4370 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004371 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004372 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004373}
4374
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004375TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004376 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004377 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004378 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004379 SessionDescriptionInterface* offer = CreateOffer();
4380
4381 SetLocalDescriptionWithoutError(offer);
4382
4383 voice_channel_ = media_engine_->GetVoiceChannel(0);
4384
4385 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004386 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004387 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004388}
4389
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004390// Tests that we can renegotiate new media content with ICE candidates in the
4391// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004392TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004393 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004394 SetFactoryDtlsSrtp();
4395
deadbeefab9b2d12015-10-14 11:33:11 -07004396 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004397 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004398 SetLocalDescriptionWithoutError(offer);
4399
4400 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4401 SetRemoteDescriptionWithoutError(answer);
4402
4403 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004404 GetOptionsForRemoteOffer(&options);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004405 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4406
4407 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004408 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004409 candidate1.set_component(1);
4410 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4411 candidate1);
4412 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4413 SetRemoteDescriptionWithoutError(offer);
4414
htaa2a49d92016-03-04 02:51:39 -08004415 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004416 SetLocalDescriptionWithoutError(answer);
4417}
4418
4419// Tests that we can renegotiate new media content with ICE candidates separated
4420// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004421TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004422 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004423 SetFactoryDtlsSrtp();
4424
deadbeefab9b2d12015-10-14 11:33:11 -07004425 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004426 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004427 SetLocalDescriptionWithoutError(offer);
4428
4429 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4430 SetRemoteDescriptionWithoutError(answer);
4431
4432 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004433 GetOptionsForRemoteOffer(&options);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004434 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4435 SetRemoteDescriptionWithoutError(offer);
4436
4437 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004438 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004439 candidate1.set_component(1);
4440 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4441 candidate1);
4442 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4443
htaa2a49d92016-03-04 02:51:39 -08004444 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004445 SetLocalDescriptionWithoutError(answer);
4446}
honghaiz7f777492016-02-02 21:54:01 -08004447
zhihuang9763d562016-08-05 11:14:50 -07004448#ifdef HAVE_QUIC
4449TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4450 configuration_.enable_quic = true;
4451 InitWithDtls(GetParam());
4452 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4453 SessionDescriptionInterface* offer = CreateOffer();
4454 ASSERT_TRUE(offer);
4455 ASSERT_TRUE(offer->description());
4456 SetLocalDescriptionWithoutError(offer);
4457 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004458 GetOptionsForAnswer(&options);
zhihuang9763d562016-08-05 11:14:50 -07004459 SessionDescriptionInterface* answer =
4460 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4461 ASSERT_TRUE(answer);
4462 ASSERT_TRUE(answer->description());
4463 SetRemoteDescriptionWithoutError(answer);
4464}
4465#endif // HAVE_QUIC
4466
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004467// Tests that RTX codec is removed from the answer when it isn't supported
4468// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004469TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004470 Init();
zhihuang1c378ed2017-08-17 14:10:50 -07004471 // Send video only to match the |kSdpWithRtx|.
4472 SendVideoOnlyStream2();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004473 std::string offer_sdp(kSdpWithRtx);
4474
4475 SessionDescriptionInterface* offer =
4476 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4477 EXPECT_TRUE(offer->ToString(&offer_sdp));
4478
4479 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004480 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004481 SetRemoteDescriptionWithoutError(offer);
4482
zhihuang1c378ed2017-08-17 14:10:50 -07004483 // |offered_media_sections_| is used when creating answer.
4484 offered_media_sections_.push_back(cricket::MediaDescriptionOptions(
4485 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
4486 cricket::RtpTransceiverDirection(true, true), false));
4487 // Don't create media section for audio in the answer.
htaa2a49d92016-03-04 02:51:39 -08004488 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004489 // Answer SDP does not contain the RTX codec.
4490 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004491 SetLocalDescriptionWithoutError(answer);
4492}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004493
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004494// This verifies that the voice channel after bundle has both options from video
4495// and voice channels.
4496TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4497 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004498 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004499
4500 PeerConnectionInterface::RTCOfferAnswerOptions options;
4501 options.use_rtp_mux = true;
4502
4503 SessionDescriptionInterface* offer = CreateOffer(options);
4504 SetLocalDescriptionWithoutError(offer);
4505
4506 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4507 rtc::Socket::Option::OPT_SNDBUF, 4000);
4508
4509 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4510 rtc::Socket::Option::OPT_RCVBUF, 8000);
4511
4512 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004513 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004514 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4515 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004516 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004517 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4518
deadbeefcbecd352015-09-23 11:50:27 -07004519 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004520 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4521 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004522 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004523 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4524
deadbeefcbecd352015-09-23 11:50:27 -07004525 EXPECT_NE(session_->voice_rtp_transport_channel(),
4526 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004527
deadbeefab9b2d12015-10-14 11:33:11 -07004528 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004529 SessionDescriptionInterface* answer =
4530 CreateRemoteAnswer(session_->local_description());
4531 SetRemoteDescriptionWithoutError(answer);
4532
deadbeefcbecd352015-09-23 11:50:27 -07004533 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004534 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4535 EXPECT_EQ(4000, option_val);
4536
deadbeefcbecd352015-09-23 11:50:27 -07004537 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004538 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4539 EXPECT_EQ(8000, option_val);
4540}
4541
tommi0f620f42015-07-09 03:25:02 -07004542// Test creating a session, request multiple offers, destroy the session
4543// and make sure we got success/failure callbacks for all of the requests.
4544// Background: crbug.com/507307
4545TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4546 Init();
4547
4548 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4549 PeerConnectionInterface::RTCOfferAnswerOptions options;
4550 options.offer_to_receive_audio =
4551 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004552 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07004553 GetOptionsForOffer(options, &session_options);
tommi0f620f42015-07-09 03:25:02 -07004554 for (auto& o : observers) {
4555 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004556 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004557 }
4558
4559 session_.reset();
4560
tommi0f620f42015-07-09 03:25:02 -07004561 for (auto& o : observers) {
4562 // We expect to have received a notification now even if the session was
4563 // terminated. The offer creation may or may not have succeeded, but we
4564 // must have received a notification which, so the only invalid state
4565 // is kInit.
4566 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4567 }
4568}
4569
stefanc1aeaf02015-10-15 07:26:07 -07004570TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4571 TestPacketOptions();
4572}
4573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004574// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4575// currently fails because upon disconnection and reconnection OnIceComplete is
4576// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004577
deadbeefcbecd352015-09-23 11:50:27 -07004578INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4579 WebRtcSessionTest,
4580 testing::Values(ALREADY_GENERATED,
4581 DTLS_IDENTITY_STORE));