blob: 20883270b2cdfc625a0320da18bfc7dd783dda59 [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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000074using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000075using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000076using webrtc::kSdpWithoutDtlsFingerprint;
77using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000079using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000080using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000082typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
83
wu@webrtc.org364f2042013-11-20 21:49:41 +000084static const int kClientAddrPort = 0;
85static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000086static const char kClientIPv6AddrHost1[] =
87 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000088static const char kClientAddrHost2[] = "22.22.22.22";
89static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000090static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
91static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000092static const char kTurnUsername[] = "test";
93static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
95static const char kSessionVersion[] = "1";
96
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097// Media index of candidates belonging to the first media content.
98static const int kMediaContentIndex0 = 0;
99static const char kMediaContentName0[] = "audio";
100
101// Media index of candidates belonging to the second media content.
102static const int kMediaContentIndex1 = 1;
103static const char kMediaContentName1[] = "video";
104
deadbeef953c2ce2017-01-09 14:53:41 -0800105static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106static const int kIceCandidatesTimeout = 10000;
107
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000108static const char kFakeDtlsFingerprint[] =
109 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
110 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
111
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000112static const char kTooLongIceUfragPwd[] =
113 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
114 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
115 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
116 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
117
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000118static const char kSdpWithRtx[] =
119 "v=0\r\n"
120 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
121 "s=-\r\n"
122 "t=0 0\r\n"
123 "a=msid-semantic: WMS stream1\r\n"
124 "m=video 9 RTP/SAVPF 0 96\r\n"
125 "c=IN IP4 0.0.0.0\r\n"
126 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
127 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
128 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
129 "a=mid:video\r\n"
130 "a=sendrecv\r\n"
131 "a=rtcp-mux\r\n"
132 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
133 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
134 "a=rtpmap:0 fake_video_codec/90000\r\n"
135 "a=rtpmap:96 rtx/90000\r\n"
136 "a=fmtp:96 apt=0\r\n";
137
deadbeefab9b2d12015-10-14 11:33:11 -0700138static const char kStream1[] = "stream1";
139static const char kVideoTrack1[] = "video1";
140static const char kAudioTrack1[] = "audio1";
141
142static const char kStream2[] = "stream2";
143static const char kVideoTrack2[] = "video2";
144static const char kAudioTrack2[] = "audio2";
145
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
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001221 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1222 const char* sctp_stream_name, int new_port,
1223 cricket::MediaSessionOptions options) {
1224 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07001225 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001226 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1227 }
1228
1229 // Takes ownership of offer_basis (and deletes it).
1230 JsepSessionDescription* ChangeSDPSctpPort(
1231 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1232 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1233 // SessionDescription from the mutated string.
1234 const char* default_port_str = "5000";
1235 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001236 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001237 std::string offer_str;
1238 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001239 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001240 new_port_str, strlen(new_port_str),
1241 &offer_str);
1242 JsepSessionDescription* offer = new JsepSessionDescription(
1243 offer_basis->type());
1244 delete offer_basis;
1245 offer->Initialize(offer_str, NULL);
1246 return offer;
1247 }
1248
deadbeefab9b2d12015-10-14 11:33:11 -07001249 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // before this function to decide which streams to create.
1251 JsepSessionDescription* CreateRemoteOffer() {
1252 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001253 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 return CreateRemoteOffer(options, session_->remote_description());
1255 }
1256
1257 JsepSessionDescription* CreateRemoteAnswer(
1258 const SessionDescriptionInterface* offer,
1259 cricket::MediaSessionOptions options,
1260 cricket::SecurePolicy policy) {
1261 desc_factory_->set_secure(policy);
1262 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001263 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 JsepSessionDescription* answer(
1265 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1266 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1267 options, NULL),
1268 session_id, kSessionVersion)) {
1269 delete answer;
1270 answer = NULL;
1271 }
1272 return answer;
1273 }
1274
1275 JsepSessionDescription* CreateRemoteAnswer(
1276 const SessionDescriptionInterface* offer,
1277 cricket::MediaSessionOptions options) {
1278 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1279 }
1280
deadbeefab9b2d12015-10-14 11:33:11 -07001281 // Creates an answer session description.
1282 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 // to decide which streams to create.
1284 JsepSessionDescription* CreateRemoteAnswer(
1285 const SessionDescriptionInterface* offer) {
1286 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001287 GetOptionsForAnswer(&options);
zhihuang1c378ed2017-08-17 14:10:50 -07001288 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1290 }
1291
1292 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001293 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001294 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001295 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001296
1297 PeerConnectionInterface::RTCOfferAnswerOptions options;
1298 options.use_rtp_mux = bundle;
1299
1300 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1302 // and answer.
1303 SetLocalDescriptionWithoutError(offer);
1304
kwibergd1fe2812016-04-27 06:47:29 -07001305 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001306 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 std::string sdp;
1308 EXPECT_TRUE(answer->ToString(&sdp));
1309
1310 size_t expected_candidate_num = 2;
1311 if (!rtcp_mux) {
1312 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1313 // for rtp and rtcp.
1314 expected_candidate_num = 4;
1315 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 const std::string kRtcpMux = "a=rtcp-mux";
1317 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001318 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 kXRtcpMux.c_str(), kXRtcpMux.length(),
1320 &sdp);
1321 }
1322
1323 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1324 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325
1326 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001327 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1329 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001330 if (bundle) {
1331 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1332 } else {
1333 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 }
1335 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336
zhihuang3a334652016-05-05 18:37:49 -07001337 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1338 const std::string& codec_name) {
1339 for (const auto& content : desc->description()->contents()) {
1340 if (static_cast<cricket::MediaContentDescription*>(content.description)
1341 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1342 const auto* mdesc =
1343 static_cast<cricket::VideoContentDescription*>(content.description);
1344 for (const auto& codec : mdesc->codecs()) {
1345 if (codec.name == codec_name) {
1346 return true;
1347 }
1348 }
1349 }
1350 }
1351 return false;
1352 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001353 // Helper class to configure loopback network and verify Best
1354 // Connection using right IP protocol for TestLoopbackCall
1355 // method. LoopbackNetworkManager applies firewall rules to block
1356 // all ping traffic once ICE completed, and remove them to observe
1357 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1358 // verifies the best connection is using the right IP protocol after
1359 // initial ICE convergences.
1360
1361 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001362 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001363 LoopbackNetworkConfiguration()
1364 : test_ipv6_network_(false),
1365 test_extra_ipv4_network_(false),
1366 best_connection_after_initial_ice_converged_(1, 0) {}
1367
1368 // Used to track the expected best connection count in each IP protocol.
1369 struct ExpectedBestConnection {
1370 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1371 : ipv4_count_(ipv4_count),
1372 ipv6_count_(ipv6_count) {}
1373
1374 int ipv4_count_;
1375 int ipv6_count_;
1376 };
1377
1378 bool test_ipv6_network_;
1379 bool test_extra_ipv4_network_;
1380 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1381
1382 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001383 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001384 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1385 }
1386
1387 private:
jbauchac8869e2015-07-03 01:36:14 -07001388 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001389 const ExpectedBestConnection& expected) const {
1390 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001391 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1392 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001393 expected.ipv4_count_);
1394 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001395 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1396 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001397 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001398 // This is used in the loopback call so there is only single host to host
1399 // candidate pair.
1400 EXPECT_EQ(metrics_observer->GetEnumCounter(
1401 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1402 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001403 0);
1404 EXPECT_EQ(metrics_observer->GetEnumCounter(
1405 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1406 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001407 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001408 }
1409 };
1410
1411 class LoopbackNetworkManager {
1412 public:
1413 LoopbackNetworkManager(WebRtcSessionTest* session,
1414 const LoopbackNetworkConfiguration& config)
1415 : config_(config) {
1416 session->AddInterface(
1417 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1418 if (config_.test_extra_ipv4_network_) {
1419 session->AddInterface(
1420 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1421 }
1422 if (config_.test_ipv6_network_) {
1423 session->AddInterface(
1424 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1425 }
1426 }
1427
1428 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1429 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1430 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1431 if (config_.test_extra_ipv4_network_) {
1432 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1433 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1434 }
1435 if (config_.test_ipv6_network_) {
1436 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1437 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1438 }
1439 }
1440
1441 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1442
1443 private:
1444 LoopbackNetworkConfiguration config_;
1445 };
1446
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 // The method sets up a call from the session to itself, in a loopback
1448 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001449 // disconnection, and then a permanent disconnection.
1450 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1452 // While running the call, this method also checks if the session goes through
1453 // the correct sequence of ICE states when a connection is established,
1454 // broken, and re-established.
1455 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001456 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1457 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001459
stefanc1aeaf02015-10-15 07:26:07 -07001460 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001461 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001462 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001463 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464
1465 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1466 observer_.ice_gathering_state_);
1467 SetLocalDescriptionWithoutError(offer);
1468 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1469 observer_.ice_connection_state_);
1470 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001471 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1473 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001474 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475
1476 std::string sdp;
1477 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001478 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1479 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 ASSERT_TRUE(desc != NULL);
1481 SetRemoteDescriptionWithoutError(desc);
1482
1483 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001484 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001485
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001486 // The ice connection state is "Connected" too briefly to catch in a test.
1487 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001488 observer_.ice_connection_state_, kIceCandidatesTimeout);
1489 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490
stefanc1aeaf02015-10-15 07:26:07 -07001491 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1492 LoopbackNetworkManager loopback_network_manager(this, config);
1493 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001494 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 // Adding firewall rule to block ping requests, which should cause
1496 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001497
1498 loopback_network_manager.ApplyFirewallRules(fss_.get());
1499
1500 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1502 observer_.ice_connection_state_,
1503 kIceCandidatesTimeout);
1504
jbauchac8869e2015-07-03 01:36:14 -07001505 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001508 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001510 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001511 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 observer_.ice_connection_state_,
1513 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001514
1515 // Now we block ping requests and wait until the ICE connection transitions
1516 // to the Failed state. This will take at least 30 seconds because it must
1517 // wait for the Port to timeout.
1518 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001519
1520 loopback_network_manager.ApplyFirewallRules(fss_.get());
1521 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001522 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001523 observer_.ice_connection_state_,
1524 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 }
1526
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001527 void TestLoopbackCall() {
1528 LoopbackNetworkConfiguration config;
1529 TestLoopbackCall(config);
1530 }
1531
stefanc1aeaf02015-10-15 07:26:07 -07001532 void TestPacketOptions() {
stefanc1aeaf02015-10-15 07:26:07 -07001533 LoopbackNetworkConfiguration config;
1534 LoopbackNetworkManager loopback_network_manager(this, config);
1535
1536 SetupLoopbackCall();
1537
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001538 // Wait for channel to be ready for sending.
1539 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001540 uint8_t test_packet[15] = {0};
1541 rtc::PacketOptions options;
1542 options.packet_id = 10;
1543 media_engine_->GetVideoChannel(0)
1544 ->SendRtp(test_packet, sizeof(test_packet), options);
1545
1546 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001547 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1548 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001549 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1550 }
1551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1553 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001554 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1555 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001556
1557 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001558 std::vector<cricket::AudioCodec> codecs =
1559 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 codecs.push_back(kCNCodec1);
1561 codecs.push_back(kCNCodec2);
1562 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001563 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 }
1565
1566 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1567 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001568 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001570 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001571 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1573 if (audio_content_desc->codecs()[i].name == "CN")
1574 return false;
1575 }
1576 return true;
1577 }
1578
deadbeefab9b2d12015-10-14 11:33:11 -07001579 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001580 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001581 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001582 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1583 data_channel_ = DataChannel::Create(
1584 session_.get(), session_->data_channel_type(), "datachannel", dci);
1585 }
1586
1587 void SetLocalDescriptionWithDataChannel() {
1588 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001589 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 SetLocalDescriptionWithoutError(offer);
1591 }
1592
wu@webrtc.org91053e72013-08-10 07:18:04 +00001593 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001594 RTCCertificateGenerationMethod cert_gen_method,
1595 CreateSessionDescriptionRequest::Type type) {
1596 InitWithDtls(cert_gen_method);
1597 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1598 }
1599
1600 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1601 CreateSessionDescriptionRequest::Type type) {
1602 InitWithDtlsIdentityGenFail();
1603 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1604 }
1605
1606 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001607 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001608 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001609 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001610 if (type == CreateSessionDescriptionRequest::kAnswer) {
1611 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001612 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07001613 std::unique_ptr<JsepSessionDescription> offer(
1614 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001615 ASSERT_TRUE(offer.get() != NULL);
1616 SetRemoteDescriptionWithoutError(offer.release());
1617 }
1618
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001619 PeerConnectionInterface::RTCOfferAnswerOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001620 cricket::MediaSessionOptions offer_session_options;
1621 cricket::MediaSessionOptions answer_session_options;
1622 GetOptionsForOffer(options, &offer_session_options);
1623 GetOptionsForAnswer(&answer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001624 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001625 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001626 observers[kNumber];
1627 for (int i = 0; i < kNumber; ++i) {
1628 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1629 if (type == CreateSessionDescriptionRequest::kOffer) {
zhihuang1c378ed2017-08-17 14:10:50 -07001630 session_->CreateOffer(observers[i], options, offer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001631 } else {
zhihuang1c378ed2017-08-17 14:10:50 -07001632 session_->CreateAnswer(observers[i], answer_session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001633 }
1634 }
1635
1636 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1637 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1638 WebRtcSessionCreateSDPObserverForTest::kFailed;
1639
1640 for (int i = 0; i < kNumber; ++i) {
1641 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1642 if (success) {
1643 EXPECT_TRUE(observers[i]->description() != NULL);
1644 } else {
1645 EXPECT_TRUE(observers[i]->description() == NULL);
1646 }
1647 }
1648 }
1649
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001650 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001651 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001652 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001653 turn_server.credentials = credentials;
1654 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001655 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001656 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001657 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001658 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001659 }
1660
skvlad11a9cbf2016-10-07 11:53:05 -07001661 webrtc::RtcEventLogNullImpl event_log_;
nisse7eaa4ea2017-05-08 05:25:41 -07001662 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1663 std::unique_ptr<rtc::FirewallSocketServer> fss_;
1664 rtc::AutoSocketServerThread thread_;
deadbeef112b2e92017-02-10 20:13:37 -08001665 // |media_engine_| and |data_engine_| are actually owned by
1666 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 cricket::FakeMediaEngine* media_engine_;
1668 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001669 // Actually owned by session_.
1670 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001671 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001672 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001673 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1674 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001675 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001676 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001677 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001678 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001679 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001680 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001681 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001682 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 MockIceObserver observer_;
1684 cricket::FakeVideoMediaChannel* video_channel_;
1685 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001686 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001687 // The following flags affect options created for CreateOffer/CreateAnswer.
1688 bool send_stream_1_ = false;
1689 bool send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -07001690 bool local_send_audio_ = false;
1691 bool local_send_video_ = false;
1692 bool local_recv_audio_ = true;
1693 bool local_recv_video_ = true;
1694 bool remote_send_audio_ = false;
1695 bool remote_send_video_ = false;
1696 bool remote_recv_audio_ = true;
1697 bool remote_recv_video_ = true;
1698 std::vector<cricket::MediaDescriptionOptions> offered_media_sections_;
deadbeefab9b2d12015-10-14 11:33:11 -07001699 rtc::scoped_refptr<DataChannel> data_channel_;
1700 // Last values received from data channel creation signal.
1701 std::string last_data_channel_label_;
1702 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001703 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704};
1705
Henrik Boström87713d02015-08-25 09:53:21 +02001706TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1707 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 // SDES is disabled when DTLS is on.
1709 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710}
1711
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001712TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001713 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001714 // SDES is required if DTLS is off.
1715 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001716}
1717
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1719 TestSessionCandidatesWithBundleRtcpMux(false, false);
1720}
1721
1722// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1723// with rtcp-mux and/or bundle.
1724TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1725 TestSessionCandidatesWithBundleRtcpMux(false, true);
1726}
1727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1729 TestSessionCandidatesWithBundleRtcpMux(true, true);
1730}
1731
1732TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001733 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1734 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001735 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001736 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 InitiateCall();
1738 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1739 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1740 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1741}
1742
deadbeeff5f03e82016-06-06 11:16:06 -07001743TEST_F(WebRtcSessionTest, TestStunError) {
1744 rtc::ScopedFakeClock clock;
1745
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001746 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1747 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001748 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001749 rtc::FP_UDP,
1750 rtc::FD_ANY,
1751 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001752 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001753 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001755 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001756 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1757 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1759 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001760 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1761 // warning.
1762 session_->Close();
1763 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764}
1765
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001766TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001767 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001768 SessionDescriptionInterface* offer = NULL;
1769 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1770 std::string unknown_action;
1771 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1772 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1773}
1774
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775// Test creating offers and receive answers and make sure the
1776// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001778 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001779 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001780 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 const std::string session_id_orig = offer->session_id();
1782 const std::string session_version_orig = offer->session_version();
1783 SetLocalDescriptionWithoutError(offer);
1784
deadbeefab9b2d12015-10-14 11:33:11 -07001785 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 SessionDescriptionInterface* answer =
1787 CreateRemoteAnswer(session_->local_description());
1788 SetRemoteDescriptionWithoutError(answer);
1789
1790 video_channel_ = media_engine_->GetVideoChannel(0);
1791 voice_channel_ = media_engine_->GetVoiceChannel(0);
1792
1793 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1794 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1795
1796 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1797 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1798
1799 ASSERT_EQ(1u, video_channel_->send_streams().size());
1800 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1801 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1802 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1803
1804 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001805 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001806 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807
1808 // Verify the session id is the same and the session version is
1809 // increased.
1810 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001811 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1812 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813
1814 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001815 EXPECT_EQ(0u, video_channel_->send_streams().size());
1816 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817
deadbeefab9b2d12015-10-14 11:33:11 -07001818 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 answer = CreateRemoteAnswer(session_->local_description());
1820 SetRemoteDescriptionWithoutError(answer);
1821
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 // Make sure the receive streams have not changed.
1823 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1824 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1825 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1826 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1827}
1828
1829// Test receiving offers and creating answers and make sure the
1830// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001831TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001832 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001833 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001834 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001835 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 SetRemoteDescriptionWithoutError(offer);
1837
deadbeefab9b2d12015-10-14 11:33:11 -07001838 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001839 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001840 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 SetLocalDescriptionWithoutError(answer);
1842
1843 const std::string session_id_orig = answer->session_id();
1844 const std::string session_version_orig = answer->session_version();
1845
1846 video_channel_ = media_engine_->GetVideoChannel(0);
1847 voice_channel_ = media_engine_->GetVoiceChannel(0);
1848
htaa2a49d92016-03-04 02:51:39 -08001849 ASSERT_TRUE(video_channel_);
1850 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1852 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1853
1854 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1855 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1856
1857 ASSERT_EQ(1u, video_channel_->send_streams().size());
1858 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1859 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1860 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1861
deadbeefab9b2d12015-10-14 11:33:11 -07001862 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001863 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 SetRemoteDescriptionWithoutError(offer);
1865
1866 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001867 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001868 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869
1870 // Verify the session id is the same and the session version is
1871 // increased.
1872 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001873 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1874 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 SetLocalDescriptionWithoutError(answer);
1876
1877 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1878 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1879 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1880 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1881 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1882 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1883
1884 // Make sure we have no send streams.
1885 EXPECT_EQ(0u, video_channel_->send_streams().size());
1886 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1887}
1888
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001889TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001890 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001891 media_engine_->set_fail_create_channel(true);
1892
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001893 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001894 ASSERT_TRUE(offer != NULL);
1895 // SetRemoteDescription and SetLocalDescription will take the ownership of
1896 // the offer.
1897 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001898 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001899 ASSERT_TRUE(offer != NULL);
1900 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1901}
1902
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903//
1904// Tests for creating/setting SDP under different SDES/DTLS polices:
1905//
1906// --DTLS off and SDES on
1907// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1908// set local/remote offer/answer with crypto --> success
1909// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1910// failure
1911// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1912// failure
1913// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1914// failure
1915//
1916// --DTLS on and SDES off
1917// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1918// set local/remote offer/answer with DTLS fingerprint --> success
1919// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1920// fingerprint --> failure
1921// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1922// --> failure
1923// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1924// --> failure
1925//
1926// --Encryption disabled: DTLS off and SDES off
1927// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1928// answer without SDES or DTLS --> success
1929// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1930// answer without SDES or DTLS --> success
1931//
1932
1933// Test that we return a failure when applying a remote/local offer that doesn't
1934// have cryptos enabled when DTLS is off.
1935TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001936 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001938 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 JsepSessionDescription* offer = CreateRemoteOffer(
1940 options, cricket::SEC_DISABLED);
1941 ASSERT_TRUE(offer != NULL);
1942 VerifyNoCryptoParams(offer->description(), false);
1943 // SetRemoteDescription and SetLocalDescription will take the ownership of
1944 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1947 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949}
1950
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001951// Test that we return a failure when applying a local answer that doesn't have
1952// cryptos enabled when DTLS is off.
1953TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001954 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 SessionDescriptionInterface* offer = NULL;
1956 SessionDescriptionInterface* answer = NULL;
1957 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1958 // SetRemoteDescription and SetLocalDescription will take the ownership of
1959 // the offer.
1960 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962}
1963
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964// Test we will return fail when apply an remote answer that doesn't have
1965// crypto enabled when DTLS is off.
1966TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001967 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 SessionDescriptionInterface* offer = NULL;
1969 SessionDescriptionInterface* answer = NULL;
1970 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1971 // SetRemoteDescription and SetLocalDescription will take the ownership of
1972 // the offer.
1973 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001974 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975}
1976
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001977// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1978// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001979TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001980 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001981 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 SetFactoryDtlsSrtp();
1983 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001984 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001985 JsepSessionDescription* offer =
1986 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 ASSERT_TRUE(offer != NULL);
1988 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001989 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990
1991 // SetRemoteDescription will take the ownership of the offer.
1992 SetRemoteDescriptionWithoutError(offer);
1993
1994 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001995 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 ASSERT_TRUE(answer != NULL);
1997 VerifyFingerprintStatus(answer->description(), true);
1998 // Check that we don't have an a=crypto line in the answer.
1999 VerifyNoCryptoParams(answer->description(), true);
2000
2001 // Now set the local description, which should work, even without a=crypto.
2002 SetLocalDescriptionWithoutError(answer);
2003}
2004
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002005// Test that we set a local offer with a DTLS fingerprint when DTLS is on
2006// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02002007TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07002008 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02002009 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002010 SetFactoryDtlsSrtp();
2011
2012 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002013 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002014 ASSERT_TRUE(offer != NULL);
2015 VerifyFingerprintStatus(offer->description(), true);
2016 // Check that we don't have an a=crypto line in the offer.
2017 VerifyNoCryptoParams(offer->description(), true);
2018
2019 // Now set the local description, which should work, even without a=crypto.
2020 SetLocalDescriptionWithoutError(offer);
2021
2022 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002023 GetOptionsForAnswer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002024 JsepSessionDescription* answer =
2025 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2026 ASSERT_TRUE(answer != NULL);
2027 VerifyFingerprintStatus(answer->description(), true);
2028 VerifyNoCryptoParams(answer->description(), true);
2029
2030 // SetRemoteDescription will take the ownership of the answer.
2031 SetRemoteDescriptionWithoutError(answer);
2032}
2033
2034// Test that if we support DTLS and the other side didn't offer a fingerprint,
2035// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02002036TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002037 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002039 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002040 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 JsepSessionDescription* offer = CreateRemoteOffer(
2042 options, cricket::SEC_REQUIRED);
2043 ASSERT_TRUE(offer != NULL);
2044 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002045 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002047 // SetRemoteDescription will take the ownership of the offer.
2048 SetRemoteDescriptionOfferExpectError(
2049 kSdpWithoutDtlsFingerprint, offer);
2050
2051 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
2052 // SetLocalDescription will take the ownership of the offer.
2053 SetLocalDescriptionOfferExpectError(
2054 kSdpWithoutDtlsFingerprint, offer);
2055}
2056
2057// Test that we return a failure when applying a local answer that doesn't have
2058// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02002059TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002060 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002061 SessionDescriptionInterface* offer = NULL;
2062 SessionDescriptionInterface* answer = NULL;
2063 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
2064
2065 // SetRemoteDescription and SetLocalDescription will take the ownership of
2066 // the offer and answer.
2067 SetRemoteDescriptionWithoutError(offer);
2068 SetLocalDescriptionAnswerExpectError(
2069 kSdpWithoutDtlsFingerprint, answer);
2070}
2071
2072// Test that we return a failure when applying a remote answer that doesn't have
2073// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02002074TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02002075 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 SessionDescriptionInterface* offer = CreateOffer();
zhihuang1c378ed2017-08-17 14:10:50 -07002077 cricket::MediaSessionOptions offer_options;
2078 GetOptionsForRemoteOffer(&offer_options);
2079
kwibergd1fe2812016-04-27 06:47:29 -07002080 std::unique_ptr<SessionDescriptionInterface> temp_offer(
zhihuang1c378ed2017-08-17 14:10:50 -07002081 CreateRemoteOffer(offer_options, cricket::SEC_ENABLED));
2082
2083 cricket::MediaSessionOptions answer_options;
2084 GetOptionsForAnswer(&answer_options);
2085 JsepSessionDescription* answer = CreateRemoteAnswer(
2086 temp_offer.get(), answer_options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002087
2088 // SetRemoteDescription and SetLocalDescription will take the ownership of
2089 // the offer and answer.
2090 SetLocalDescriptionWithoutError(offer);
2091 SetRemoteDescriptionAnswerExpectError(
2092 kSdpWithoutDtlsFingerprint, answer);
2093}
2094
2095// Test that we create a local offer without SDES or DTLS and accept a remote
2096// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002097TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07002098 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002099 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002100 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002101
2102 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002104 ASSERT_TRUE(offer != NULL);
2105 VerifyFingerprintStatus(offer->description(), false);
2106 // Check that we don't have an a=crypto line in the offer.
2107 VerifyNoCryptoParams(offer->description(), false);
2108
2109 // Now set the local description, which should work, even without a=crypto.
2110 SetLocalDescriptionWithoutError(offer);
2111
2112 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002113 GetOptionsForAnswer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002114 JsepSessionDescription* answer =
2115 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2116 ASSERT_TRUE(answer != NULL);
2117 VerifyFingerprintStatus(answer->description(), false);
2118 VerifyNoCryptoParams(answer->description(), false);
2119
2120 // SetRemoteDescription will take the ownership of the answer.
2121 SetRemoteDescriptionWithoutError(answer);
2122}
2123
2124// Test that we create a local answer without SDES or DTLS and accept a remote
2125// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002126TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002127 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002128 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002129
2130 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002131 GetOptionsForRemoteOffer(&options);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002132 JsepSessionDescription* offer =
2133 CreateRemoteOffer(options, cricket::SEC_DISABLED);
2134 ASSERT_TRUE(offer != NULL);
2135 VerifyFingerprintStatus(offer->description(), false);
2136 VerifyNoCryptoParams(offer->description(), false);
2137
2138 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 SetRemoteDescriptionWithoutError(offer);
2140
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002141 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08002142 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 ASSERT_TRUE(answer != NULL);
2144 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002145 // Check that we don't have an a=crypto line in the answer.
2146 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002148 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 SetLocalDescriptionWithoutError(answer);
2150}
2151
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002152// Test that we can create and set an answer correctly when different
2153// SSL roles have been negotiated for different transports.
2154// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
2155TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
2156 SendAudioVideoStream1();
2157 InitWithDtls(GetParam());
2158 SetFactoryDtlsSrtp();
2159
2160 SessionDescriptionInterface* offer = CreateOffer();
2161 SetLocalDescriptionWithoutError(offer);
2162
2163 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002164 GetOptionsForAnswer(&options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002165
2166 // First, negotiate different SSL roles.
2167 SessionDescriptionInterface* answer =
2168 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2169 TransportInfo* audio_transport_info =
2170 answer->description()->GetTransportInfoByName("audio");
2171 audio_transport_info->description.connection_role =
2172 cricket::CONNECTIONROLE_ACTIVE;
2173 TransportInfo* video_transport_info =
2174 answer->description()->GetTransportInfoByName("video");
2175 video_transport_info->description.connection_role =
2176 cricket::CONNECTIONROLE_PASSIVE;
2177 SetRemoteDescriptionWithoutError(answer);
2178
2179 // Now create an offer in the reverse direction, and ensure the initial
2180 // offerer responds with an answer with correct SSL roles.
2181 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2182 kSessionVersion,
2183 session_->remote_description());
2184 SetRemoteDescriptionWithoutError(offer);
2185
zhihuang1c378ed2017-08-17 14:10:50 -07002186 cricket::MediaSessionOptions answer_options;
2187 answer_options.bundle_enabled = true;
2188 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002189 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2190 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2191 audio_transport_info->description.connection_role);
2192 video_transport_info = answer->description()->GetTransportInfoByName("video");
2193 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2194 video_transport_info->description.connection_role);
2195 SetLocalDescriptionWithoutError(answer);
2196
2197 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2198 // audio is transferred over to video in the answer that completes the BUNDLE
2199 // negotiation.
2200 options.bundle_enabled = true;
2201 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2202 kSessionVersion,
2203 session_->remote_description());
2204 SetRemoteDescriptionWithoutError(offer);
zhihuang1c378ed2017-08-17 14:10:50 -07002205 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002206 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2207 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2208 audio_transport_info->description.connection_role);
2209 video_transport_info = answer->description()->GetTransportInfoByName("video");
2210 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2211 video_transport_info->description.connection_role);
2212 SetLocalDescriptionWithoutError(answer);
2213}
2214
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002216 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002217 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002219 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 SetLocalDescriptionWithoutError(offer);
2221
2222 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002223 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 SetLocalDescriptionWithoutError(offer2);
2225}
2226
2227TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002228 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002229 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002231 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 SetRemoteDescriptionWithoutError(offer);
2233
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002234 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 SetRemoteDescriptionWithoutError(offer2);
2236}
2237
2238TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002239 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002240 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002241 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002243 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002244 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2245 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246}
2247
2248TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002249 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002250 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002251 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002253 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002254 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002255 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256}
2257
2258TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002259 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002260 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002262 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263
htaa2a49d92016-03-04 02:51:39 -08002264 JsepSessionDescription* pranswer =
2265 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002267 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268
deadbeefab9b2d12015-10-14 11:33:11 -07002269 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002270 JsepSessionDescription* pranswer2 =
2271 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2273
deadbeefd59daf82015-10-14 15:02:44 -07002274 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275
deadbeefab9b2d12015-10-14 11:33:11 -07002276 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002277 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002278 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279}
2280
2281TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002282 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002283 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002284 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002285 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286
2287 JsepSessionDescription* pranswer =
2288 CreateRemoteAnswer(session_->local_description());
2289 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2290
2291 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002292 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293
deadbeefab9b2d12015-10-14 11:33:11 -07002294 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 JsepSessionDescription* pranswer2 =
2296 CreateRemoteAnswer(session_->local_description());
2297 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2298
2299 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002300 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301
deadbeefab9b2d12015-10-14 11:33:11 -07002302 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 SessionDescriptionInterface* answer =
2304 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002305 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306}
2307
2308TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002309 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002310 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002311 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002312
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 SessionDescriptionInterface* answer =
2314 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002315 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2316 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317}
2318
2319TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002320 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002321 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002322 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 SessionDescriptionInterface* answer =
2325 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002326 SetRemoteDescriptionAnswerExpectError(
2327 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328}
2329
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002330// Tests that the remote candidates are added and removed successfully.
2331TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002332 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002333 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002335 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
zhihuang38989e52017-03-21 11:04:53 -07002336 "", "", "local", 0, "");
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002337 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2339
deadbeefd59daf82015-10-14 15:02:44 -07002340 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2342
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002343 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002345
2346 // Fail since we have not set a remote description.
2347 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348
2349 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2350 session_->local_description());
2351 SetRemoteDescriptionWithoutError(answer);
2352
deadbeefd59daf82015-10-14 15:02:44 -07002353 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2354 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002355 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002356 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2357 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 // Verifying the candidates are copied properly from internal vector.
2360 const SessionDescriptionInterface* remote_desc =
2361 session_->remote_description();
2362 ASSERT_TRUE(remote_desc != NULL);
2363 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2364 const IceCandidateCollection* candidates =
2365 remote_desc->candidates(kMediaContentIndex0);
2366 ASSERT_EQ(2u, candidates->count());
2367 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2368 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2369 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2370 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2371
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002372 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2373 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 candidate.set_component(2);
2375 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2376 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002377 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378
2379 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2380 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002381
2382 // Remove candidate1 and candidate2
2383 std::vector<cricket::Candidate> remote_candidates;
2384 remote_candidates.push_back(ice_candidate1.candidate());
2385 remote_candidates.push_back(ice_candidate2.candidate());
2386 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2387 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388}
2389
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002390// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391// that it is retained if the remote session description is changed.
2392TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002393 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 cricket::Candidate candidate1;
2395 candidate1.set_component(1);
2396 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2397 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002398 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 CreateAndSetRemoteOfferAndLocalAnswer();
2400
2401 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2402 const SessionDescriptionInterface* remote_desc =
2403 session_->remote_description();
2404 ASSERT_TRUE(remote_desc != NULL);
2405 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2406 const IceCandidateCollection* candidates =
2407 remote_desc->candidates(kMediaContentIndex0);
2408 ASSERT_EQ(1u, candidates->count());
2409 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2410
2411 // Update the RemoteSessionDescription with a new session description and
2412 // a candidate and check that the new remote session description contains both
2413 // candidates.
2414 SessionDescriptionInterface* offer = CreateRemoteOffer();
2415 cricket::Candidate candidate2;
2416 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2417 candidate2);
2418 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2419 SetRemoteDescriptionWithoutError(offer);
2420
2421 remote_desc = session_->remote_description();
2422 ASSERT_TRUE(remote_desc != NULL);
2423 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2424 candidates = remote_desc->candidates(kMediaContentIndex0);
2425 ASSERT_EQ(2u, candidates->count());
2426 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2427 // Username and password have be updated with the TransportInfo of the
2428 // SessionDescription, won't be equal to the original one.
2429 candidate2.set_username(candidates->at(0)->candidate().username());
2430 candidate2.set_password(candidates->at(0)->candidate().password());
2431 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2432 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2433 // No need to verify the username and password.
2434 candidate1.set_username(candidates->at(1)->candidate().username());
2435 candidate1.set_password(candidates->at(1)->candidate().password());
2436 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2437
2438 // Test that the candidate is ignored if we can add the same candidate again.
2439 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2440}
2441
2442// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002443// that they are retained if the local session description is changed. And if
2444// continual gathering is enabled, they are removed from the local session
2445// description when the network is down.
2446TEST_F(WebRtcSessionTest,
2447 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002448 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002449 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002450 // Enable Continual Gathering.
2451 cricket::IceConfig config;
2452 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2453 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002454 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 CreateAndSetRemoteOfferAndLocalAnswer();
2456
2457 const SessionDescriptionInterface* local_desc = session_->local_description();
2458 const IceCandidateCollection* candidates =
2459 local_desc->candidates(kMediaContentIndex0);
2460 ASSERT_TRUE(candidates != NULL);
2461 EXPECT_EQ(0u, candidates->count());
2462
deadbeefb60a8192016-08-24 15:15:00 -07002463 // Since we're using continual gathering, we won't get "gathering done".
2464 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465
2466 local_desc = session_->local_description();
2467 candidates = local_desc->candidates(kMediaContentIndex0);
2468 ASSERT_TRUE(candidates != NULL);
2469 EXPECT_LT(0u, candidates->count());
2470 candidates = local_desc->candidates(1);
2471 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002472 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473
2474 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002475 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 CreateAndSetRemoteOfferAndLocalAnswer();
2477
2478 local_desc = session_->local_description();
2479 candidates = local_desc->candidates(kMediaContentIndex0);
2480 ASSERT_TRUE(candidates != NULL);
2481 EXPECT_LT(0u, candidates->count());
2482 candidates = local_desc->candidates(1);
2483 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002484 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002485
2486 candidates = local_desc->candidates(kMediaContentIndex0);
2487 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002488 // Bring down the network interface to trigger candidate removals.
2489 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2490 // Verify that all local candidates are removed.
2491 EXPECT_EQ(0, observer_.num_candidates_removed_);
2492 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2493 kIceCandidatesTimeout);
2494 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2495}
2496
2497// Tests that if continual gathering is disabled, local candidates won't be
2498// removed when the interface is turned down.
2499TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2500 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2501 Init();
2502 SendAudioVideoStream1();
2503 CreateAndSetRemoteOfferAndLocalAnswer();
2504
2505 const SessionDescriptionInterface* local_desc = session_->local_description();
2506 const IceCandidateCollection* candidates =
2507 local_desc->candidates(kMediaContentIndex0);
2508 ASSERT_TRUE(candidates != NULL);
2509 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2510
2511 size_t num_local_candidates = candidates->count();
2512 EXPECT_LT(0u, num_local_candidates);
2513 // By default, Continual Gathering is disabled.
2514 // Bring down the network interface.
2515 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2516 // Verify that the local candidates are not removed.
2517 rtc::Thread::Current()->ProcessMessages(1000);
2518 EXPECT_EQ(0, observer_.num_candidates_removed_);
2519 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520}
2521
2522// Test that we can set a remote session description with remote candidates.
2523TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002524 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525
2526 cricket::Candidate candidate1;
2527 candidate1.set_component(1);
2528 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2529 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002530 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002531 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532
2533 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2534 SetRemoteDescriptionWithoutError(offer);
2535
2536 const SessionDescriptionInterface* remote_desc =
2537 session_->remote_description();
2538 ASSERT_TRUE(remote_desc != NULL);
2539 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2540 const IceCandidateCollection* candidates =
2541 remote_desc->candidates(kMediaContentIndex0);
2542 ASSERT_EQ(1u, candidates->count());
2543 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2544
htaa2a49d92016-03-04 02:51:39 -08002545 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 SetLocalDescriptionWithoutError(answer);
2547}
2548
2549// Test that offers and answers contains ice candidates when Ice candidates have
2550// been gathered.
2551TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002552 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002553 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002554 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 // Ice is started but candidates are not provided until SetLocalDescription
2556 // is called.
2557 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2558 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2559 CreateAndSetRemoteOfferAndLocalAnswer();
2560 // Wait until at least one local candidate has been collected.
2561 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2562 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563
kwibergd1fe2812016-04-27 06:47:29 -07002564 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002565
zhihuang1c378ed2017-08-17 14:10:50 -07002566 ASSERT_TRUE(local_offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2568 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569
2570 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2571 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002572 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2574 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 SetLocalDescriptionWithoutError(answer);
2576}
2577
2578// Verifies TransportProxy and media channels are created with content names
2579// present in the SessionDescription.
2580TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002581 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002582 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002583 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584
2585 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002586 // "video". Goal is to modify these content names and verify transport
2587 // channels
2588 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 // present in SDP.
2590 std::string sdp;
2591 EXPECT_TRUE(offer->ToString(&sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592
2593 SessionDescriptionInterface* modified_offer =
2594 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2595
2596 SetRemoteDescriptionWithoutError(modified_offer);
2597
zhihuang1c378ed2017-08-17 14:10:50 -07002598 cricket::MediaSessionOptions answer_options;
2599 answer_options.bundle_enabled = false;
2600 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 SetLocalDescriptionWithoutError(answer);
2602
deadbeef5bd5ca32017-02-10 11:31:50 -08002603 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002604 session_->voice_rtp_transport_channel();
2605 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002606 EXPECT_EQ(voice_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07002607 "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002608 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002609 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002610 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002611 EXPECT_EQ(video_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07002612 "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2614 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2615}
2616
2617// Test that an offer contains the correct media content descriptions based on
2618// the send streams when no constraints have been set.
2619TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002620 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002621 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002622
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 ASSERT_TRUE(offer != NULL);
2624 const cricket::ContentInfo* content =
2625 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002626 ASSERT_TRUE(content != NULL);
2627 EXPECT_EQ(
2628 cricket::MD_RECVONLY,
2629 static_cast<const cricket::AudioContentDescription*>(content->description)
2630 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002632 ASSERT_TRUE(content != NULL);
2633 EXPECT_EQ(
2634 cricket::MD_RECVONLY,
2635 static_cast<const cricket::VideoContentDescription*>(content->description)
2636 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637}
2638
2639// Test that an offer contains the correct media content descriptions based on
2640// the send streams when no constraints have been set.
2641TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002642 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002644 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002645 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002646
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002647 const cricket::ContentInfo* content =
2648 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002649 ASSERT_TRUE(content != NULL);
2650 EXPECT_EQ(
2651 cricket::MD_SENDRECV,
2652 static_cast<const cricket::AudioContentDescription*>(content->description)
2653 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002655 ASSERT_TRUE(content != NULL);
2656 EXPECT_EQ(
2657 cricket::MD_RECVONLY,
2658 static_cast<const cricket::VideoContentDescription*>(content->description)
2659 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660
2661 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002662 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002663 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 content = cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002665 ASSERT_TRUE(content != NULL);
2666 EXPECT_EQ(
2667 cricket::MD_SENDRECV,
2668 static_cast<const cricket::AudioContentDescription*>(content->description)
2669 ->direction());
2670
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07002672 ASSERT_TRUE(content != NULL);
2673 EXPECT_EQ(
2674 cricket::MD_SENDRECV,
2675 static_cast<const cricket::VideoContentDescription*>(content->description)
2676 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677}
2678
2679// Test that an offer contains no media content descriptions if
2680// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2681TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002682 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002683 PeerConnectionInterface::RTCOfferAnswerOptions options;
2684 options.offer_to_receive_audio = 0;
2685 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686
kwibergd1fe2812016-04-27 06:47:29 -07002687 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002688
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 ASSERT_TRUE(offer != NULL);
2690 const cricket::ContentInfo* content =
2691 cricket::GetFirstAudioContent(offer->description());
2692 EXPECT_TRUE(content == NULL);
2693 content = cricket::GetFirstVideoContent(offer->description());
2694 EXPECT_TRUE(content == NULL);
2695}
2696
2697// Test that an offer contains only audio media content descriptions if
2698// kOfferToReceiveAudio constraints are set to true.
2699TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002700 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002701 PeerConnectionInterface::RTCOfferAnswerOptions options;
2702 options.offer_to_receive_audio =
2703 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
zhihuang1c378ed2017-08-17 14:10:50 -07002704 options.offer_to_receive_video = 0;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002705
kwibergd1fe2812016-04-27 06:47:29 -07002706 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707
2708 const cricket::ContentInfo* content =
2709 cricket::GetFirstAudioContent(offer->description());
2710 EXPECT_TRUE(content != NULL);
2711 content = cricket::GetFirstVideoContent(offer->description());
2712 EXPECT_TRUE(content == NULL);
2713}
2714
2715// Test that an offer contains audio and video media content descriptions if
2716// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2717TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002718 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002720 PeerConnectionInterface::RTCOfferAnswerOptions options;
2721 options.offer_to_receive_audio =
2722 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2723 options.offer_to_receive_video =
2724 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2725
kwibergd1fe2812016-04-27 06:47:29 -07002726 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 const cricket::ContentInfo* content =
2729 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002730 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002731
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 content = cricket::GetFirstVideoContent(offer->description());
2733 EXPECT_TRUE(content != NULL);
2734
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002735 // Sets constraints to false and verifies that audio/video contents are
2736 // removed.
2737 options.offer_to_receive_audio = 0;
2738 options.offer_to_receive_video = 0;
zhihuang1c378ed2017-08-17 14:10:50 -07002739 // Remove the media sections added in previous offer.
2740 offered_media_sections_.clear();
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002741 offer.reset(CreateOffer(options));
2742
2743 content = cricket::GetFirstAudioContent(offer->description());
2744 EXPECT_TRUE(content == NULL);
2745 content = cricket::GetFirstVideoContent(offer->description());
2746 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747}
2748
2749// Test that an answer can not be created if the last remote description is not
2750// an offer.
2751TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002752 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002753 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 SetLocalDescriptionWithoutError(offer);
2755 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2756 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002757 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002758}
2759
2760// Test that an answer contains the correct media content descriptions when no
2761// constraints have been set.
2762TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002763 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002764 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002765 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002767 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 const cricket::ContentInfo* content =
2769 cricket::GetFirstAudioContent(answer->description());
2770 ASSERT_TRUE(content != NULL);
2771 EXPECT_FALSE(content->rejected);
2772
2773 content = cricket::GetFirstVideoContent(answer->description());
2774 ASSERT_TRUE(content != NULL);
2775 EXPECT_FALSE(content->rejected);
2776}
2777
2778// Test that an answer contains the correct media content descriptions when no
2779// constraints have been set and the offer only contain audio.
2780TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 // Create a remote offer with audio only.
2783 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002784 GetOptionsForAudioOnlyRemoteOffer(&options);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002785
kwibergd1fe2812016-04-27 06:47:29 -07002786 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2788 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2789
2790 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002791 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 const cricket::ContentInfo* content =
2793 cricket::GetFirstAudioContent(answer->description());
2794 ASSERT_TRUE(content != NULL);
2795 EXPECT_FALSE(content->rejected);
2796
2797 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2798}
2799
2800// Test that an answer contains the correct media content descriptions when no
2801// constraints have been set.
2802TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002803 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002805 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002806 SetRemoteDescriptionWithoutError(offer.release());
2807 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002808 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002809 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 const cricket::ContentInfo* content =
2811 cricket::GetFirstAudioContent(answer->description());
2812 ASSERT_TRUE(content != NULL);
2813 EXPECT_FALSE(content->rejected);
2814
2815 content = cricket::GetFirstVideoContent(answer->description());
2816 ASSERT_TRUE(content != NULL);
2817 EXPECT_FALSE(content->rejected);
2818}
2819
2820// Test that an answer contains the correct media content descriptions when
2821// constraints have been set but no stream is sent.
2822TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002823 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002825 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 SetRemoteDescriptionWithoutError(offer.release());
2827
htaa2a49d92016-03-04 02:51:39 -08002828 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07002829 remote_send_audio_ = false;
2830 remote_send_video_ = false;
2831 local_recv_audio_ = false;
2832 local_recv_video_ = false;
kwibergd1fe2812016-04-27 06:47:29 -07002833 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002834 CreateAnswer(session_options));
2835
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836 const cricket::ContentInfo* content =
2837 cricket::GetFirstAudioContent(answer->description());
2838 ASSERT_TRUE(content != NULL);
2839 EXPECT_TRUE(content->rejected);
2840
2841 content = cricket::GetFirstVideoContent(answer->description());
2842 ASSERT_TRUE(content != NULL);
2843 EXPECT_TRUE(content->rejected);
2844}
2845
2846// Test that an answer contains the correct media content descriptions when
2847// constraints have been set and streams are sent.
2848TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002849 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002851 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 SetRemoteDescriptionWithoutError(offer.release());
2853
htaa2a49d92016-03-04 02:51:39 -08002854 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002856 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002857 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858
2859 // TODO(perkj): Should the direction be set to SEND_ONLY?
2860 const cricket::ContentInfo* content =
2861 cricket::GetFirstAudioContent(answer->description());
2862 ASSERT_TRUE(content != NULL);
2863 EXPECT_FALSE(content->rejected);
2864
2865 // TODO(perkj): Should the direction be set to SEND_ONLY?
2866 content = cricket::GetFirstVideoContent(answer->description());
2867 ASSERT_TRUE(content != NULL);
2868 EXPECT_FALSE(content->rejected);
2869}
2870
2871TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2872 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002873 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002874 PeerConnectionInterface::RTCOfferAnswerOptions options;
2875 options.offer_to_receive_audio =
2876 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2877 options.voice_activity_detection = false;
2878
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881 const cricket::ContentInfo* content =
2882 cricket::GetFirstAudioContent(offer->description());
2883 EXPECT_TRUE(content != NULL);
2884 EXPECT_TRUE(VerifyNoCNCodecs(content));
2885}
2886
2887TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2888 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002889 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002891 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 SetRemoteDescriptionWithoutError(offer.release());
2893
htaa2a49d92016-03-04 02:51:39 -08002894 cricket::MediaSessionOptions options;
2895 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002896 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 const cricket::ContentInfo* content =
2898 cricket::GetFirstAudioContent(answer->description());
2899 ASSERT_TRUE(content != NULL);
2900 EXPECT_TRUE(VerifyNoCNCodecs(content));
2901}
2902
2903// This test verifies the call setup when remote answer with audio only and
2904// later updates with video.
2905TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002906 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2908 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2909
deadbeefab9b2d12015-10-14 11:33:11 -07002910 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002911 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912
2913 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002914 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2915 cricket::MD_RECVONLY, kActive, &options);
2916 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2917 cricket::MD_INACTIVE, kStopped, &options);
2918 local_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2920
2921 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2922 // and answer;
2923 SetLocalDescriptionWithoutError(offer);
2924 SetRemoteDescriptionWithoutError(answer);
2925
2926 video_channel_ = media_engine_->GetVideoChannel(0);
2927 voice_channel_ = media_engine_->GetVoiceChannel(0);
2928
zhihuang1c378ed2017-08-17 14:10:50 -07002929 ASSERT_TRUE(video_channel_ == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930
2931 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2932 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2933 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2934
2935 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002936 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07002937 local_recv_video_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 CreateAndSetRemoteOfferAndLocalAnswer();
2939
2940 video_channel_ = media_engine_->GetVideoChannel(0);
2941 voice_channel_ = media_engine_->GetVoiceChannel(0);
2942
zhihuang1c378ed2017-08-17 14:10:50 -07002943 ASSERT_TRUE(video_channel_ != nullptr);
2944 ASSERT_TRUE(voice_channel_ != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002945
2946 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2947 ASSERT_EQ(1u, video_channel_->send_streams().size());
2948 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2949 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2950 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2951 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2952 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2953 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2954
2955 // Change session back to audio only.
zhihuang1c378ed2017-08-17 14:10:50 -07002956 // The remote side doesn't send and recv video.
deadbeefab9b2d12015-10-14 11:33:11 -07002957 SendAudioOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07002958 remote_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 CreateAndSetRemoteOfferAndLocalAnswer();
2960
zhihuang1c378ed2017-08-17 14:10:50 -07002961 video_channel_ = media_engine_->GetVideoChannel(0);
2962 voice_channel_ = media_engine_->GetVoiceChannel(0);
2963
2964 // The audio is expected to be rejected.
2965 EXPECT_TRUE(video_channel_ == nullptr);
2966
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2968 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2969 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2970 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2971}
2972
2973// This test verifies the call setup when remote answer with video only and
2974// later updates with audio.
2975TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002976 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002977 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2978 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002979 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002980 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981
2982 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002983 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
2984 cricket::MD_INACTIVE, kStopped, &options);
2985 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2986 cricket::MD_RECVONLY, kActive, &options);
2987 local_recv_audio_ = false;
2988 SessionDescriptionInterface* answer =
2989 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990
2991 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2992 // and answer.
2993 SetLocalDescriptionWithoutError(offer);
2994 SetRemoteDescriptionWithoutError(answer);
2995
2996 video_channel_ = media_engine_->GetVideoChannel(0);
2997 voice_channel_ = media_engine_->GetVoiceChannel(0);
2998
2999 ASSERT_TRUE(voice_channel_ == NULL);
3000 ASSERT_TRUE(video_channel_ != NULL);
3001
3002 EXPECT_EQ(0u, video_channel_->recv_streams().size());
3003 ASSERT_EQ(1u, video_channel_->send_streams().size());
3004 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
3005
3006 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07003007 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07003008 local_recv_audio_ = true;
3009 SessionDescriptionInterface* offer2 = CreateRemoteOffer();
3010 SetRemoteDescriptionWithoutError(offer2);
3011 cricket::MediaSessionOptions answer_options;
3012 // Disable the bundling here. If the media is bundled on audio
3013 // transport, then we can't reject the audio because switching the bundled
3014 // transport is not currently supported.
3015 // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704)
3016 answer_options.bundle_enabled = false;
3017 SessionDescriptionInterface* answer2 = CreateAnswer(answer_options);
3018 SetLocalDescriptionWithoutError(answer2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019
3020 voice_channel_ = media_engine_->GetVoiceChannel(0);
olka3c747662017-08-17 06:50:32 -07003021
zhihuang1c378ed2017-08-17 14:10:50 -07003022 ASSERT_TRUE(voice_channel_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
3024 ASSERT_EQ(1u, voice_channel_->send_streams().size());
3025 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
3026 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
3027
3028 // Change session back to video only.
zhihuang1c378ed2017-08-17 14:10:50 -07003029 // The remote side doesn't send and recv audio.
deadbeefab9b2d12015-10-14 11:33:11 -07003030 SendVideoOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07003031 remote_recv_audio_ = false;
3032 SessionDescriptionInterface* offer3 = CreateRemoteOffer();
3033 SetRemoteDescriptionWithoutError(offer3);
3034 SessionDescriptionInterface* answer3 = CreateAnswer(answer_options);
3035 SetLocalDescriptionWithoutError(answer3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003036
3037 video_channel_ = media_engine_->GetVideoChannel(0);
3038 voice_channel_ = media_engine_->GetVoiceChannel(0);
3039
zhihuang1c378ed2017-08-17 14:10:50 -07003040 // The video is expected to be rejected.
3041 EXPECT_TRUE(voice_channel_ == nullptr);
3042
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043 ASSERT_EQ(1u, video_channel_->recv_streams().size());
3044 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
3045 ASSERT_EQ(1u, video_channel_->send_streams().size());
3046 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
3047}
3048
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003050 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003051 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003052 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053 VerifyCryptoParams(offer->description());
3054 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07003055 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056 VerifyCryptoParams(answer->description());
3057}
3058
jbauchcb560652016-08-04 05:20:32 -07003059TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
3060 InitWithGcm();
3061 SendAudioVideoStream1();
3062 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
3063 VerifyCryptoParams(offer->description(), true);
3064 SetRemoteDescriptionWithoutError(offer.release());
3065 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
3066 VerifyCryptoParams(answer->description(), true);
3067}
3068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003070 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003072 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003073 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074 VerifyNoCryptoParams(offer->description(), false);
3075}
3076
3077TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003078 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079 VerifyAnswerFromNonCryptoOffer();
3080}
3081
3082TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003083 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084 VerifyAnswerFromCryptoOffer();
3085}
3086
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003087// This test verifies that setLocalDescription fails if
3088// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
3089TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003090 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003091 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003092 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003093
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003094 std::string sdp;
3095 RemoveIceUfragPwdLines(offer.get(), &sdp);
3096 SessionDescriptionInterface* modified_offer =
3097 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003098 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003099}
3100
3101// This test verifies that setRemoteDescription fails if
3102// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
3103TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003104 Init();
kwibergd1fe2812016-04-27 06:47:29 -07003105 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003106 std::string sdp;
3107 RemoveIceUfragPwdLines(offer.get(), &sdp);
3108 SessionDescriptionInterface* modified_offer =
3109 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003110 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003111}
3112
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003113// This test verifies that setLocalDescription fails if local offer has
3114// too short ice ufrag and pwd strings.
3115TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003116 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003117 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003118 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003119 // Modifying ice ufrag and pwd in local offer with strings smaller than the
3120 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08003121 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003122 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08003123 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003124
3125 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08003126 offer.reset(CreateOffer());
3127 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
3128 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003129}
3130
3131// This test verifies that setRemoteDescription fails if remote offer has
3132// too short ice ufrag and pwd strings.
3133TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003134 Init();
kwibergd1fe2812016-04-27 06:47:29 -07003135 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003136 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
3137 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08003138 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003139 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08003140 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003141
deadbeef0ed85b22016-02-23 17:24:52 -08003142 offer.reset(CreateRemoteOffer());
3143 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
3144 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00003145}
3146
Honghai Zhang04e91462015-12-11 14:26:22 -08003147// Test that if the remote offer indicates the peer requested ICE restart (via
3148// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3149TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07003150 Init();
honghaiz503726c2015-07-31 12:37:38 -07003151
3152 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07003153 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08003154 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003155 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3156 0, "", "", "relay", 0, "");
3157 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3158 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003159 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3160 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003161 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3162
3163 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003164 offer.reset(CreateRemoteOffer());
3165 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003166 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3167 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3168 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003169 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
3170 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003171 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3172
3173 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003174 offer.reset(CreateRemoteOffer());
3175 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003176 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3177 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3178 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003179 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
3180 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003181 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3182
3183 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003184 offer.reset(CreateRemoteOffer());
3185 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3186 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003187 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3188}
3189
Honghai Zhang04e91462015-12-11 14:26:22 -08003190// Test that if the remote answer indicates the peer requested ICE restart (via
3191// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3192TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
3193 Init();
3194 SessionDescriptionInterface* offer = CreateOffer();
3195 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08003196
3197 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07003198 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08003199 answer->set_type(JsepSessionDescription::kPrAnswer);
3200 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003201 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3202 0, "", "", "relay", 0, "");
3203 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3204 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003205 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
3206 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003207 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3208
3209 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003210 answer.reset(CreateRemoteAnswer(offer));
3211 answer->set_type(JsepSessionDescription::kPrAnswer);
3212 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003213 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3214 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3215 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003216 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3217 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003218 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3219
3220 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003221 answer.reset(CreateRemoteAnswer(offer));
3222 answer->set_type(JsepSessionDescription::kPrAnswer);
3223 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003224 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3225 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3226 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003227 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3228 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003229 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3230
3231 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003232 answer.reset(CreateRemoteAnswer(offer));
3233 answer->set_type(JsepSessionDescription::kPrAnswer);
3234 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3235 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003236 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3237}
3238
Donald Curtisd4f769d2015-05-28 09:48:21 -07003239// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003240// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003241TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3242 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3243
3244 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003245 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003246
zhihuang1c378ed2017-08-17 14:10:50 -07003247 cricket::MediaSessionOptions offer_options;
3248 GetOptionsForRemoteOffer(&offer_options);
3249 offer_options.bundle_enabled = true;
Donald Curtisd4f769d2015-05-28 09:48:21 -07003250
zhihuang1c378ed2017-08-17 14:10:50 -07003251 SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003252 SetRemoteDescriptionWithoutError(offer);
3253
zhihuang1c378ed2017-08-17 14:10:50 -07003254 cricket::MediaSessionOptions answer_options;
3255 answer_options.bundle_enabled = true;
3256 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003257 SetLocalDescriptionWithoutError(answer);
3258
deadbeefcbecd352015-09-23 11:50:27 -07003259 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3260 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003261
deadbeefcbecd352015-09-23 11:50:27 -07003262 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003263 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003264
3265 // Checks if one of the transport channels contains a connection using a given
3266 // port.
eladalon1cc5fc32017-08-23 04:15:18 -07003267 auto connection_with_remote_port = [this](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003268 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3269 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003270 for (auto& chan_stat : kv.second.channel_stats) {
3271 for (auto& conn_info : chan_stat.connection_infos) {
3272 if (conn_info.remote_candidate.address().port() == port) {
3273 return true;
3274 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003275 }
3276 }
3277 }
3278 return false;
3279 };
3280
3281 EXPECT_FALSE(connection_with_remote_port(5000));
3282 EXPECT_FALSE(connection_with_remote_port(5001));
3283 EXPECT_FALSE(connection_with_remote_port(6000));
3284
3285 // The way the *_WAIT checks work is they only wait if the condition fails,
3286 // which does not help in the case where state is not changing. This is
3287 // problematic in this test since we want to verify that adding a video
3288 // candidate does _not_ change state. So we interleave candidates and assume
3289 // that messages are executed in the order they were posted.
3290
3291 // First audio candidate.
3292 cricket::Candidate candidate0;
3293 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3294 candidate0.set_component(1);
3295 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003296 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003297 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3298 candidate0);
3299 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3300
3301 // Video candidate.
3302 cricket::Candidate candidate1;
3303 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3304 candidate1.set_component(1);
3305 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003306 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003307 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3308 candidate1);
3309 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3310
3311 // Second audio candidate.
3312 cricket::Candidate candidate2;
3313 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3314 candidate2.set_component(1);
3315 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003316 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003317 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3318 candidate2);
3319 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3320
3321 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3322 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3323
3324 // No need here for a _WAIT check since we are checking that state hasn't
3325 // changed: if this is false we would be doing waits for nothing and if this
3326 // is true then there will be no messages processed anyways.
3327 EXPECT_FALSE(connection_with_remote_port(6000));
3328}
3329
deadbeefcbecd352015-09-23 11:50:27 -07003330// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003331TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3332 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003333 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003334
3335 PeerConnectionInterface::RTCOfferAnswerOptions options;
3336 options.use_rtp_mux = true;
3337
3338 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003340
deadbeefcbecd352015-09-23 11:50:27 -07003341 EXPECT_NE(session_->voice_rtp_transport_channel(),
3342 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003343
deadbeefab9b2d12015-10-14 11:33:11 -07003344 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003345 SessionDescriptionInterface* answer =
3346 CreateRemoteAnswer(session_->local_description());
3347 SetRemoteDescriptionWithoutError(answer);
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3350 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003351}
3352
deadbeefcbecd352015-09-23 11:50:27 -07003353// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003354TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3355 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003356 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003357
Donald Curtis0e209b02015-03-24 09:29:54 -07003358 PeerConnectionInterface::RTCOfferAnswerOptions options;
3359 options.use_rtp_mux = true;
3360
3361 SessionDescriptionInterface* offer = CreateOffer(options);
3362 SetLocalDescriptionWithoutError(offer);
3363
deadbeefcbecd352015-09-23 11:50:27 -07003364 EXPECT_NE(session_->voice_rtp_transport_channel(),
3365 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003366
deadbeefab9b2d12015-10-14 11:33:11 -07003367 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003368
3369 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003370 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003371 CreateRemoteAnswer(session_->local_description()));
3372 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3373 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3374 JsepSessionDescription* modified_answer =
3375 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3376 modified_answer->Initialize(answer_copy, "1", "1");
3377 SetRemoteDescriptionWithoutError(modified_answer); //
3378
deadbeefcbecd352015-09-23 11:50:27 -07003379 EXPECT_NE(session_->voice_rtp_transport_channel(),
3380 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003381}
3382
3383// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3384TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3385 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003386 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003387
3388 PeerConnectionInterface::RTCOfferAnswerOptions options;
3389 options.use_rtp_mux = true;
3390
3391 SessionDescriptionInterface* offer = CreateOffer(options);
3392 SetLocalDescriptionWithoutError(offer);
3393
deadbeefcbecd352015-09-23 11:50:27 -07003394 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3395 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003396
deadbeefab9b2d12015-10-14 11:33:11 -07003397 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003398 SessionDescriptionInterface* answer =
3399 CreateRemoteAnswer(session_->local_description());
3400 SetRemoteDescriptionWithoutError(answer);
3401
deadbeefcbecd352015-09-23 11:50:27 -07003402 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3403 session_->video_rtp_transport_channel());
3404}
3405
3406// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3407// audio content in the answer.
3408TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3409 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003410 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003411
3412 PeerConnectionInterface::RTCOfferAnswerOptions options;
3413 options.use_rtp_mux = true;
3414
3415 SessionDescriptionInterface* offer = CreateOffer(options);
3416 SetLocalDescriptionWithoutError(offer);
3417
3418 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3419 session_->video_rtp_transport_channel());
3420
zhihuang1c378ed2017-08-17 14:10:50 -07003421 SendVideoOnlyStream2();
3422 local_send_audio_ = false;
3423 remote_recv_audio_ = false;
deadbeefcbecd352015-09-23 11:50:27 -07003424 cricket::MediaSessionOptions recv_options;
zhihuang1c378ed2017-08-17 14:10:50 -07003425 GetOptionsForRemoteAnswer(&recv_options);
deadbeefcbecd352015-09-23 11:50:27 -07003426 SessionDescriptionInterface* answer =
3427 CreateRemoteAnswer(session_->local_description(), recv_options);
3428 SetRemoteDescriptionWithoutError(answer);
3429
deadbeefd59daf82015-10-14 15:02:44 -07003430 EXPECT_TRUE(nullptr == session_->voice_channel());
3431 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003432
deadbeefd59daf82015-10-14 15:02:44 -07003433 session_->Close();
3434 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3435 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3436 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3437 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003438}
3439
3440// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3441TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3442 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003443 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003444
Donald Curtis0e209b02015-03-24 09:29:54 -07003445 PeerConnectionInterface::RTCOfferAnswerOptions options;
3446 options.use_rtp_mux = true;
3447
3448 SessionDescriptionInterface* offer = CreateOffer(options);
3449 SetLocalDescriptionWithoutError(offer);
3450
deadbeefcbecd352015-09-23 11:50:27 -07003451 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3452 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003453
deadbeefab9b2d12015-10-14 11:33:11 -07003454 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003455
3456 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003457 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 CreateRemoteAnswer(session_->local_description()));
3459 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3460 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3461 JsepSessionDescription* modified_answer =
3462 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3463 modified_answer->Initialize(answer_copy, "1", "1");
3464 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465
deadbeefcbecd352015-09-23 11:50:27 -07003466 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3467 session_->video_rtp_transport_channel());
3468}
3469
3470// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3471TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3472 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003473 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003474
3475 SessionDescriptionInterface* offer = CreateRemoteOffer();
3476 SetRemoteDescriptionWithoutError(offer);
3477
3478 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3479 session_->video_rtp_transport_channel());
3480
deadbeefab9b2d12015-10-14 11:33:11 -07003481 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003482 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003483 SetLocalDescriptionWithoutError(answer);
3484
3485 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3486 session_->video_rtp_transport_channel());
3487}
3488
3489// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3490TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3491 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003492 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003493
3494 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003495 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003496 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3497 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3498 JsepSessionDescription* modified_offer =
3499 new JsepSessionDescription(JsepSessionDescription::kOffer);
3500 modified_offer->Initialize(offer_copy, "1", "1");
3501
3502 // Expect an error when applying the remote description
3503 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3504 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003505}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506
Peter Thatcher4eddf182015-04-30 10:55:59 -07003507// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003508TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3509 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003510 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511
zhihuang1c378ed2017-08-17 14:10:50 -07003512 PeerConnectionInterface::RTCOfferAnswerOptions rtc_options;
3513 rtc_options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514
zhihuang1c378ed2017-08-17 14:10:50 -07003515 SessionDescriptionInterface* offer = CreateOffer(rtc_options);
Donald Curtis0e209b02015-03-24 09:29:54 -07003516 SetLocalDescriptionWithoutError(offer);
3517
deadbeefcbecd352015-09-23 11:50:27 -07003518 EXPECT_NE(session_->voice_rtp_transport_channel(),
3519 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003520
deadbeefab9b2d12015-10-14 11:33:11 -07003521 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003522 SessionDescriptionInterface* answer =
3523 CreateRemoteAnswer(session_->local_description());
3524 SetRemoteDescriptionWithoutError(answer);
3525
3526 // This should lead to an audio-only call but isn't implemented
3527 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003528 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3529 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003530}
3531
deadbeefcbecd352015-09-23 11:50:27 -07003532// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003533TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3534 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003535 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003536 PeerConnectionInterface::RTCOfferAnswerOptions options;
3537 options.use_rtp_mux = true;
3538
3539 SessionDescriptionInterface* offer = CreateOffer(options);
3540 SetLocalDescriptionWithoutError(offer);
3541
deadbeefcbecd352015-09-23 11:50:27 -07003542 EXPECT_NE(session_->voice_rtp_transport_channel(),
3543 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003544
deadbeefab9b2d12015-10-14 11:33:11 -07003545 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003546
3547 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003548 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003549 CreateRemoteAnswer(session_->local_description()));
3550 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3551 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3552 JsepSessionDescription* modified_answer =
3553 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3554 modified_answer->Initialize(answer_copy, "1", "1");
3555 SetRemoteDescriptionWithoutError(modified_answer); //
3556
deadbeefcbecd352015-09-23 11:50:27 -07003557 EXPECT_NE(session_->voice_rtp_transport_channel(),
3558 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559}
3560
Peter Thatcher4eddf182015-04-30 10:55:59 -07003561// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3562TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3563 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003564 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003565
3566 PeerConnectionInterface::RTCOfferAnswerOptions options;
3567 options.use_rtp_mux = true;
3568
3569 SessionDescriptionInterface* offer = CreateOffer(options);
3570 SetRemoteDescriptionWithoutError(offer);
3571
deadbeefcbecd352015-09-23 11:50:27 -07003572 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3573 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003574}
3575
skvlad6c87a672016-05-17 17:49:52 -07003576// Adding a new channel to a BUNDLE which is already connected should directly
3577// assign the bundle transport to the channel, without first setting a
3578// disconnected non-bundle transport and then replacing it. The application
3579// should not receive any changes in the ICE state.
3580TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3581 LoopbackNetworkConfiguration config;
3582 LoopbackNetworkManager loopback_network_manager(this, config);
3583 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3584 // connected. Disabling either of these two means that we need to wait for the
3585 // answer to find out if more transports are needed.
3586 configuration_.bundle_policy =
3587 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003588 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07003589 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003590
3591 // Negotiate an audio channel with MAX_BUNDLE enabled.
3592 SendAudioOnlyStream2();
3593 SessionDescriptionInterface* offer = CreateOffer();
3594 SetLocalDescriptionWithoutError(offer);
3595 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3596 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3597 std::string sdp;
3598 offer->ToString(&sdp);
3599 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3600 JsepSessionDescription::kAnswer, sdp, nullptr);
3601 ASSERT_TRUE(answer != NULL);
3602 SetRemoteDescriptionWithoutError(answer);
3603
3604 // Wait for the ICE state to stabilize.
3605 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3606 observer_.ice_connection_state_, kIceCandidatesTimeout);
3607 observer_.ice_connection_state_history_.clear();
3608
3609 // Now add a video channel which should be using the same bundle transport.
3610 SendAudioVideoStream2();
3611 offer = CreateOffer();
3612 offer->ToString(&sdp);
3613 SetLocalDescriptionWithoutError(offer);
3614 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3615 sdp, nullptr);
3616 ASSERT_TRUE(answer != NULL);
3617 SetRemoteDescriptionWithoutError(answer);
3618
3619 // Wait for ICE state to stabilize
3620 rtc::Thread::Current()->ProcessMessages(0);
3621 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3622 observer_.ice_connection_state_, kIceCandidatesTimeout);
3623
3624 // No ICE state changes are expected to happen.
3625 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3626}
3627
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003628TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3629 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003630 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003631
3632 PeerConnectionInterface::RTCOfferAnswerOptions options;
3633 SessionDescriptionInterface* offer = CreateOffer(options);
3634 SetLocalDescriptionWithoutError(offer);
3635
deadbeefcbecd352015-09-23 11:50:27 -07003636 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3637 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003638
deadbeefab9b2d12015-10-14 11:33:11 -07003639 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003640 SessionDescriptionInterface* answer =
3641 CreateRemoteAnswer(session_->local_description());
3642 SetRemoteDescriptionWithoutError(answer);
3643
deadbeefcbecd352015-09-23 11:50:27 -07003644 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3645 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003646}
3647
3648TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3649 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003650 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003651
3652 PeerConnectionInterface::RTCOfferAnswerOptions options;
3653 SessionDescriptionInterface* offer = CreateOffer(options);
3654 SetLocalDescriptionWithoutError(offer);
3655
deadbeefcbecd352015-09-23 11:50:27 -07003656 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3657 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003658
deadbeefab9b2d12015-10-14 11:33:11 -07003659 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003660 SessionDescriptionInterface* answer =
3661 CreateRemoteAnswer(session_->local_description());
3662 SetRemoteDescriptionWithoutError(answer);
3663
deadbeefcbecd352015-09-23 11:50:27 -07003664 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3665 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003666}
3667
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003668// This test verifies that SetLocalDescription and SetRemoteDescription fails
3669// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3670TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003671 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003672 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003673
3674 PeerConnectionInterface::RTCOfferAnswerOptions options;
3675 options.use_rtp_mux = true;
3676
3677 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003678 std::string offer_str;
3679 offer->ToString(&offer_str);
3680 // Disable rtcp-mux
3681 const std::string rtcp_mux = "rtcp-mux";
3682 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003683 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003684 xrtcp_mux.c_str(), xrtcp_mux.length(),
3685 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003686 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003687 new JsepSessionDescription(JsepSessionDescription::kOffer);
3688 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003689 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003690 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003691 new JsepSessionDescription(JsepSessionDescription::kOffer);
3692 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003693 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003694 // Trying unmodified SDP.
3695 SetLocalDescriptionWithoutError(offer);
3696}
3697
jbauchcb560652016-08-04 05:20:32 -07003698TEST_F(WebRtcSessionTest, SetSetupGcm) {
3699 InitWithGcm();
3700 SendAudioVideoStream1();
3701 CreateAndSetRemoteOfferAndLocalAnswer();
3702}
3703
deadbeefd59daf82015-10-14 15:02:44 -07003704// This test verifies the |initial_offerer| flag when session initiates the
3705// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003706TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003707 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003708 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003709 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003710 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3711 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003712 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003713 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003714 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003715}
3716
deadbeefd59daf82015-10-14 15:02:44 -07003717// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003718TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003719 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003720 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003721 SessionDescriptionInterface* offer = CreateRemoteOffer();
3722 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003723 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003724
deadbeefd59daf82015-10-14 15:02:44 -07003725 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003727 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003728}
3729
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003730// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3731TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003732 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003733 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003734 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003735 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003736 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003737 CreateRemoteAnswer(session_->local_description()));
3738
3739 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3740 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003741 JsepSessionDescription* modified_answer =
3742 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
3744 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3745 answer->session_id(),
3746 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003747 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003748
wu@webrtc.org4e393072014-04-07 17:04:35 +00003749 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750 std::string sdp;
3751 EXPECT_TRUE(answer->ToString(&sdp));
3752 const std::string kAudioMid = "a=mid:audio";
3753 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003754 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003755 kAudioMidReplaceStr.c_str(),
3756 kAudioMidReplaceStr.length(),
3757 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003758 SessionDescriptionInterface* modified_answer1 =
3759 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003760 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003761
wu@webrtc.org4e393072014-04-07 17:04:35 +00003762 // Different media types.
3763 EXPECT_TRUE(answer->ToString(&sdp));
3764 const std::string kAudioMline = "m=audio";
3765 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003766 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003767 kAudioMlineReplaceStr.c_str(),
3768 kAudioMlineReplaceStr.length(),
3769 &sdp);
3770 SessionDescriptionInterface* modified_answer2 =
3771 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3772 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3773
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003774 SetRemoteDescriptionWithoutError(answer.release());
3775}
3776
3777// Verifying remote offer and local answer have matching m-lines as per
3778// RFC 3264.
3779TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003780 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003781 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003782 SessionDescriptionInterface* offer = CreateRemoteOffer();
3783 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003784 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003785
3786 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3787 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003788 JsepSessionDescription* modified_answer =
3789 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003790
3791 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3792 answer->session_id(),
3793 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003794 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003795 SetLocalDescriptionWithoutError(answer);
3796}
3797
3798// This test verifies that WebRtcSession does not start candidate allocation
3799// before SetLocalDescription is called.
3800TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003801 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003802 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003803 SessionDescriptionInterface* offer = CreateRemoteOffer();
3804 cricket::Candidate candidate;
3805 candidate.set_component(1);
3806 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3807 candidate);
3808 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3809 cricket::Candidate candidate1;
3810 candidate1.set_component(1);
3811 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3812 candidate1);
3813 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3814 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003815 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3816 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817
3818 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003819 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003820 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3821 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3822
htaa2a49d92016-03-04 02:51:39 -08003823 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003824 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3826}
3827
3828// This test verifies that crypto parameter is updated in local session
3829// description as per security policy set in MediaSessionDescriptionFactory.
3830TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003831 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003832 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003833 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003834
3835 // Making sure SetLocalDescription correctly sets crypto value in
3836 // SessionDescription object after de-serialization of sdp string. The value
3837 // will be set as per MediaSessionDescriptionFactory.
3838 std::string offer_str;
3839 offer->ToString(&offer_str);
3840 SessionDescriptionInterface* jsep_offer_str =
3841 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3842 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003843 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3844 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003845}
3846
3847// This test verifies the crypto parameter when security is disabled.
3848TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003849 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003850 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003851 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003852 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003853
3854 // Making sure SetLocalDescription correctly sets crypto value in
3855 // SessionDescription object after de-serialization of sdp string. The value
3856 // will be set as per MediaSessionDescriptionFactory.
3857 std::string offer_str;
3858 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003859 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003860 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3861 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003862 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3863 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003864}
3865
3866// This test verifies that an answer contains new ufrag and password if an offer
3867// with new ufrag and password is received.
3868TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003869 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003871 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07003872 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003873 SetRemoteDescriptionWithoutError(offer.release());
3874
deadbeefab9b2d12015-10-14 11:33:11 -07003875 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003876 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003877 SetLocalDescriptionWithoutError(answer.release());
3878
3879 // Receive an offer with new ufrag and password.
zhihuang1c378ed2017-08-17 14:10:50 -07003880 for (size_t i = 0; i < options.media_description_options.size(); ++i) {
3881 options.media_description_options[i].transport_options.ice_restart = true;
deadbeef0ed85b22016-02-23 17:24:52 -08003882 }
zhihuang1c378ed2017-08-17 14:10:50 -07003883
kwibergd1fe2812016-04-27 06:47:29 -07003884 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003885 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003886 SetRemoteDescriptionWithoutError(updated_offer1.release());
3887
kwibergd1fe2812016-04-27 06:47:29 -07003888 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003889
deadbeef0ed85b22016-02-23 17:24:52 -08003890 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3891 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003892
deadbeef0ed85b22016-02-23 17:24:52 -08003893 // Even a second answer (created before the description is set) should have
3894 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003895 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003896
3897 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3898 session_->local_description()->description()));
3899
3900 SetLocalDescriptionWithoutError(updated_answer2.release());
3901}
3902
3903// This test verifies that an answer contains new ufrag and password if an offer
3904// that changes either the ufrag or password (but not both) is received.
3905// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3906// a=ice-pwd attributes compared to the previous SDP from the peer, it
3907// indicates that ICE is restarting for this media stream."
3908TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3909 Init();
3910 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003911 GetOptionsForRemoteOffer(&options);
deadbeef0ed85b22016-02-23 17:24:52 -08003912 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003913 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003914 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3915 SetRemoteDescriptionWithoutError(offer.release());
3916
3917 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003918 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003919 SetLocalDescriptionWithoutError(answer.release());
3920
3921 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003922 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003923 CreateRemoteOffer(options, session_->remote_description()));
3924 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3925 "original_password12345");
3926 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3927
kwibergd1fe2812016-04-27 06:47:29 -07003928 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003929 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3930 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003931 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003932
3933 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003934 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003935 CreateRemoteOffer(options, session_->remote_description()));
3936 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3937 "modified_password12345");
3938 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3939
kwibergd1fe2812016-04-27 06:47:29 -07003940 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003941 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3942 session_->local_description()->description()));
3943 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003944}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003945
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946// This test verifies that an answer contains old ufrag and password if an offer
3947// with old ufrag and password is received.
3948TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003949 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003950 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003951 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07003952 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003953 SetRemoteDescriptionWithoutError(offer.release());
3954
deadbeefab9b2d12015-10-14 11:33:11 -07003955 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003956 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003957 SetLocalDescriptionWithoutError(answer.release());
3958
3959 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003960 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003961 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003962 SetRemoteDescriptionWithoutError(updated_offer2.release());
3963
kwibergd1fe2812016-04-27 06:47:29 -07003964 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003965
deadbeef0ed85b22016-02-23 17:24:52 -08003966 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3967 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003968
3969 SetLocalDescriptionWithoutError(updated_answer2.release());
3970}
3971
deadbeef0ed85b22016-02-23 17:24:52 -08003972// This test verifies that if an offer does an ICE restart on some, but not all
3973// media sections, the answer will change the ufrag/password in the correct
3974// media sections.
3975TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3976 Init();
3977 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07003978 GetOptionsForRemoteOffer(&options);
deadbeef0ed85b22016-02-23 17:24:52 -08003979 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003980 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003981
3982 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3983 "aaaaaaaaaaaaaaaaaaaaaa");
3984 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3985 "bbbbbbbbbbbbbbbbbbbbbb");
3986 SetRemoteDescriptionWithoutError(offer.release());
3987
3988 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003989 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003990 SetLocalDescriptionWithoutError(answer.release());
3991
3992 // Receive an offer with new ufrag and password, but only for the video media
3993 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003994 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003995 CreateRemoteOffer(options, session_->remote_description()));
3996 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3997 "cccccccccccccccccccccc");
3998 SetRemoteDescriptionWithoutError(updated_offer.release());
3999
kwibergd1fe2812016-04-27 06:47:29 -07004000 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08004001
4002 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
4003 session_->local_description()->description(),
4004 cricket::MEDIA_TYPE_AUDIO));
4005
4006 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
4007 session_->local_description()->description(),
4008 cricket::MEDIA_TYPE_VIDEO));
4009
4010 SetLocalDescriptionWithoutError(updated_answer.release());
4011}
4012
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004013TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004014 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004015 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004016 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004017 const std::string session_id_orig = offer->session_id();
4018 const std::string session_version_orig = offer->session_version();
4019 SetLocalDescriptionWithoutError(offer);
4020
4021 video_channel_ = media_engine_->GetVideoChannel(0);
4022 video_channel_->set_fail_set_send_codecs(true);
4023
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00004024 SessionDescriptionInterface* answer =
4025 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004026 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07004027
4028 // Test that after a content error, setting any description will
4029 // result in an error.
4030 video_channel_->set_fail_set_send_codecs(false);
4031 answer = CreateRemoteAnswer(session_->local_description());
4032 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
4033 offer = CreateRemoteOffer();
4034 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004035}
4036
4037// Runs the loopback call test with BUNDLE and STUN disabled.
4038TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
4039 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004040 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004041 cricket::PORTALLOCATOR_DISABLE_STUN |
4042 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004043 TestLoopbackCall();
4044}
4045
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004046TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004047 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00004048 cricket::PORTALLOCATOR_DISABLE_STUN |
4049 cricket::PORTALLOCATOR_ENABLE_IPV6 |
4050 cricket::PORTALLOCATOR_DISABLE_RELAY);
4051
4052 // best connection is IPv6 since it has higher network preference.
4053 LoopbackNetworkConfiguration config;
4054 config.test_ipv6_network_ = true;
4055 config.best_connection_after_initial_ice_converged_ =
4056 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
4057
4058 TestLoopbackCall(config);
4059}
4060
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00004061// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00004062TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07004063 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
4064 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00004065 TestLoopbackCall();
4066}
4067
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004068TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08004069 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004070 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004071 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08004072 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08004073 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004074}
4075
Henrik Boström87713d02015-08-25 09:53:21 +02004076TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08004077 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00004078 options_.disable_sctp_data_channels = false;
4079
Henrik Boström87713d02015-08-25 09:53:21 +02004080 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004081
4082 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004083 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
4084}
4085
4086// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
4087// before and after BUNDLE is negotiated.
4088TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08004089 SetFactoryDtlsSrtp();
4090 InitWithDtls(GetParam());
4091
4092 // Initially these fields should be empty.
4093 EXPECT_FALSE(session_->sctp_content_name());
4094 EXPECT_FALSE(session_->sctp_transport_name());
4095
4096 // Create offer with audio/video/data.
4097 // Default bundle policy is "balanced", so data should be using its own
4098 // transport.
4099 SendAudioVideoStream1();
4100 CreateDataChannel();
4101 InitiateCall();
4102 ASSERT_TRUE(session_->sctp_content_name());
4103 ASSERT_TRUE(session_->sctp_transport_name());
4104 EXPECT_EQ("data", *session_->sctp_content_name());
4105 EXPECT_EQ("data", *session_->sctp_transport_name());
4106
4107 // Create answer that finishes BUNDLE negotiation, which means everything
4108 // should be bundled on the first transport (audio).
4109 cricket::MediaSessionOptions answer_options;
deadbeef953c2ce2017-01-09 14:53:41 -08004110 answer_options.bundle_enabled = true;
4111 answer_options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07004112 GetOptionsForAnswer(&answer_options);
deadbeef953c2ce2017-01-09 14:53:41 -08004113 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
4114 session_->local_description(), answer_options, cricket::SEC_DISABLED));
4115 ASSERT_TRUE(session_->sctp_content_name());
4116 ASSERT_TRUE(session_->sctp_transport_name());
4117 EXPECT_EQ("data", *session_->sctp_content_name());
4118 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004119}
4120
Henrik Boström87713d02015-08-25 09:53:21 +02004121TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02004122 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004123
kwibergd1fe2812016-04-27 06:47:29 -07004124 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004125 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004126 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
4127}
4128
Henrik Boström87713d02015-08-25 09:53:21 +02004129TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004130 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02004131 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004132
4133 // Create remote offer with SCTP.
4134 cricket::MediaSessionOptions options;
4135 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07004136 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004137 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004138 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004139 SetRemoteDescriptionWithoutError(offer);
4140
4141 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07004142 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004143 EXPECT_TRUE(answer != NULL);
4144 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
4145 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004146}
4147
deadbeef953c2ce2017-01-09 14:53:41 -08004148// Test that if DTLS is disabled, we don't end up with an SctpTransport
4149// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004150TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004151 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004152 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004153
4154 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004155 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4156 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004157}
4158
deadbeef953c2ce2017-01-09 14:53:41 -08004159// Test that if DTLS is enabled, we end up with an SctpTransport created
4160// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004161TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02004162 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004163
4164 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004165 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4166 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004167}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004168
deadbeef953c2ce2017-01-09 14:53:41 -08004169// Test that if SCTP is disabled, we don't end up with an SctpTransport
4170// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004171TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00004172 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004173 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004174
4175 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004176 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4177 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004178}
4179
Henrik Boström87713d02015-08-25 09:53:21 +02004180TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004181 const int new_send_port = 9998;
4182 const int new_recv_port = 7775;
4183
Henrik Boström87713d02015-08-25 09:53:21 +02004184 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004185 SetFactoryDtlsSrtp();
4186
4187 // By default, don't actually add the codecs to desc_factory_; they don't
4188 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4189 // let the session description get parsed. That'll get the proper codecs
4190 // into the stream.
4191 cricket::MediaSessionOptions options;
4192 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4193 "stream1", new_send_port, options);
4194
4195 // SetRemoteDescription will take the ownership of the offer.
4196 SetRemoteDescriptionWithoutError(offer);
4197
htaa2a49d92016-03-04 02:51:39 -08004198 SessionDescriptionInterface* answer =
4199 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004200 ASSERT_TRUE(answer != NULL);
4201
4202 // Now set the local description, which'll take ownership of the answer.
4203 SetLocalDescriptionWithoutError(answer);
4204
4205 // TEST PLAN: Set the port number to something new, set it in the SDP,
4206 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08004207 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07004208 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004209 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
4210 EXPECT_EQ(
4211 new_recv_port,
4212 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
4213 EXPECT_EQ(
4214 new_send_port,
4215 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004216}
4217
deadbeef953c2ce2017-01-09 14:53:41 -08004218// Verifies that when a session's SctpTransport receives an OPEN message,
4219// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004220// config.
4221TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004222 InitWithDtls(GetParam());
4223
4224 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004225 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4226 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004227
deadbeef953c2ce2017-01-09 14:53:41 -08004228 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004229 webrtc::DataChannelInit config;
4230 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004231 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004232 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4233 cricket::ReceiveDataParams params;
4234 params.ssrc = config.id;
4235 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004236 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4237 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004238
deadbeef953c2ce2017-01-09 14:53:41 -08004239 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004240 EXPECT_EQ(config.id, last_data_channel_config_.id);
4241 EXPECT_FALSE(last_data_channel_config_.negotiated);
4242 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4243 last_data_channel_config_.open_handshake_role);
4244}
4245
4246TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004247 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004248 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004249
htaa2a49d92016-03-04 02:51:39 -08004250 configuration_.certificates.push_back(certificate);
4251 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004252 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4253
4254 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4255}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004256
Henrik Boström87713d02015-08-25 09:53:21 +02004257// Verifies that CreateOffer succeeds when CreateOffer is called before async
4258// identity generation is finished (even if a certificate is provided this is
4259// an async op).
4260TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004261 InitWithDtls(GetParam());
4262
Henrik Boströmd8281982015-08-27 10:12:24 +02004263 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004264 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004265 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004266
wu@webrtc.org91053e72013-08-10 07:18:04 +00004267 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004268 VerifyNoCryptoParams(offer->description(), true);
4269 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004270}
4271
4272// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004273// identity generation is finished (even if a certificate is provided this is
4274// an async op).
4275TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004276 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004277 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004278
4279 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004280 GetOptionsForRemoteOffer(&options);
kwibergd1fe2812016-04-27 06:47:29 -07004281 std::unique_ptr<JsepSessionDescription> offer(
4282 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004283 ASSERT_TRUE(offer.get() != NULL);
4284 SetRemoteDescriptionWithoutError(offer.release());
4285
kwibergd1fe2812016-04-27 06:47:29 -07004286 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004287 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004288 VerifyNoCryptoParams(answer->description(), true);
4289 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004290}
4291
4292// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004293// identity generation is finished (even if a certificate is provided this is
4294// an async op).
4295TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004296 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004297
Henrik Boströmd8281982015-08-27 10:12:24 +02004298 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004299
kwibergd1fe2812016-04-27 06:47:29 -07004300 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004301 EXPECT_TRUE(offer != NULL);
4302}
4303
4304// Verifies that CreateOffer fails when CreateOffer is called after async
4305// identity generation fails.
4306TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004307 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004308
Henrik Boströmd8281982015-08-27 10:12:24 +02004309 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004310
kwibergd1fe2812016-04-27 06:47:29 -07004311 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004312 EXPECT_TRUE(offer == NULL);
4313}
4314
4315// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4316// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004317TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004318 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004319 VerifyMultipleAsyncCreateDescription(GetParam(),
4320 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004321}
4322
4323// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4324// before async identity generation fails.
4325TEST_F(WebRtcSessionTest,
4326 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004327 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4328 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004329}
4330
4331// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4332// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004333TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004334 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004335 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004336 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004337}
4338
4339// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4340// before async identity generation fails.
4341TEST_F(WebRtcSessionTest,
4342 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004343 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4344 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004345}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004346
4347// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4348// offer has no SDES crypto but only DTLS fingerprint.
4349TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4350 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004351 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004352 // Create a remote offer with secured transport disabled.
4353 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004354 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004355 JsepSessionDescription* offer(CreateRemoteOffer(
4356 options, cricket::SEC_DISABLED));
4357 // Adds a DTLS fingerprint to the remote offer.
4358 cricket::SessionDescription* sdp = offer->description();
4359 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4360 ASSERT_TRUE(audio != NULL);
4361 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4362 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004363 rtc::SSLFingerprint::CreateFromRfc4572(
4364 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004365 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004366 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004367}
4368
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004369TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004370 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004371 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004372 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004373 SessionDescriptionInterface* offer = CreateOffer();
4374
4375 SetLocalDescriptionWithoutError(offer);
4376
4377 voice_channel_ = media_engine_->GetVoiceChannel(0);
4378
4379 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004380 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004381 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004382}
4383
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004384// Tests that we can renegotiate new media content with ICE candidates in the
4385// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004386TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004387 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004388 SetFactoryDtlsSrtp();
4389
deadbeefab9b2d12015-10-14 11:33:11 -07004390 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004391 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004392 SetLocalDescriptionWithoutError(offer);
4393
4394 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4395 SetRemoteDescriptionWithoutError(answer);
4396
4397 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004398 GetOptionsForRemoteOffer(&options);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004399 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4400
4401 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004402 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004403 candidate1.set_component(1);
4404 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4405 candidate1);
4406 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4407 SetRemoteDescriptionWithoutError(offer);
4408
htaa2a49d92016-03-04 02:51:39 -08004409 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004410 SetLocalDescriptionWithoutError(answer);
4411}
4412
4413// Tests that we can renegotiate new media content with ICE candidates separated
4414// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004415TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004416 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004417 SetFactoryDtlsSrtp();
4418
deadbeefab9b2d12015-10-14 11:33:11 -07004419 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004420 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004421 SetLocalDescriptionWithoutError(offer);
4422
4423 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4424 SetRemoteDescriptionWithoutError(answer);
4425
4426 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004427 GetOptionsForRemoteOffer(&options);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004428 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4429 SetRemoteDescriptionWithoutError(offer);
4430
4431 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004432 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004433 candidate1.set_component(1);
4434 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4435 candidate1);
4436 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4437
htaa2a49d92016-03-04 02:51:39 -08004438 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004439 SetLocalDescriptionWithoutError(answer);
4440}
honghaiz7f777492016-02-02 21:54:01 -08004441
zhihuang9763d562016-08-05 11:14:50 -07004442#ifdef HAVE_QUIC
4443TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4444 configuration_.enable_quic = true;
4445 InitWithDtls(GetParam());
4446 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4447 SessionDescriptionInterface* offer = CreateOffer();
4448 ASSERT_TRUE(offer);
4449 ASSERT_TRUE(offer->description());
4450 SetLocalDescriptionWithoutError(offer);
4451 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07004452 GetOptionsForAnswer(&options);
zhihuang9763d562016-08-05 11:14:50 -07004453 SessionDescriptionInterface* answer =
4454 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4455 ASSERT_TRUE(answer);
4456 ASSERT_TRUE(answer->description());
4457 SetRemoteDescriptionWithoutError(answer);
4458}
4459#endif // HAVE_QUIC
4460
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004461// Tests that RTX codec is removed from the answer when it isn't supported
4462// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004463TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004464 Init();
zhihuang1c378ed2017-08-17 14:10:50 -07004465 // Send video only to match the |kSdpWithRtx|.
4466 SendVideoOnlyStream2();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004467 std::string offer_sdp(kSdpWithRtx);
4468
4469 SessionDescriptionInterface* offer =
4470 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4471 EXPECT_TRUE(offer->ToString(&offer_sdp));
4472
4473 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004474 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004475 SetRemoteDescriptionWithoutError(offer);
4476
zhihuang1c378ed2017-08-17 14:10:50 -07004477 // |offered_media_sections_| is used when creating answer.
4478 offered_media_sections_.push_back(cricket::MediaDescriptionOptions(
4479 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
4480 cricket::RtpTransceiverDirection(true, true), false));
4481 // Don't create media section for audio in the answer.
htaa2a49d92016-03-04 02:51:39 -08004482 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004483 // Answer SDP does not contain the RTX codec.
4484 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004485 SetLocalDescriptionWithoutError(answer);
4486}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004487
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004488// This verifies that the voice channel after bundle has both options from video
4489// and voice channels.
4490TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4491 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004492 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004493
4494 PeerConnectionInterface::RTCOfferAnswerOptions options;
4495 options.use_rtp_mux = true;
4496
4497 SessionDescriptionInterface* offer = CreateOffer(options);
4498 SetLocalDescriptionWithoutError(offer);
4499
4500 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4501 rtc::Socket::Option::OPT_SNDBUF, 4000);
4502
4503 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4504 rtc::Socket::Option::OPT_RCVBUF, 8000);
4505
4506 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004507 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004508 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4509 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004510 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004511 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4512
deadbeefcbecd352015-09-23 11:50:27 -07004513 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004514 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4515 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004516 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004517 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4518
deadbeefcbecd352015-09-23 11:50:27 -07004519 EXPECT_NE(session_->voice_rtp_transport_channel(),
4520 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004521
deadbeefab9b2d12015-10-14 11:33:11 -07004522 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004523 SessionDescriptionInterface* answer =
4524 CreateRemoteAnswer(session_->local_description());
4525 SetRemoteDescriptionWithoutError(answer);
4526
deadbeefcbecd352015-09-23 11:50:27 -07004527 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004528 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4529 EXPECT_EQ(4000, option_val);
4530
deadbeefcbecd352015-09-23 11:50:27 -07004531 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004532 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4533 EXPECT_EQ(8000, option_val);
4534}
4535
tommi0f620f42015-07-09 03:25:02 -07004536// Test creating a session, request multiple offers, destroy the session
4537// and make sure we got success/failure callbacks for all of the requests.
4538// Background: crbug.com/507307
4539TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4540 Init();
4541
4542 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4543 PeerConnectionInterface::RTCOfferAnswerOptions options;
4544 options.offer_to_receive_audio =
4545 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004546 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07004547 GetOptionsForOffer(options, &session_options);
tommi0f620f42015-07-09 03:25:02 -07004548 for (auto& o : observers) {
4549 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004550 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004551 }
4552
4553 session_.reset();
4554
tommi0f620f42015-07-09 03:25:02 -07004555 for (auto& o : observers) {
4556 // We expect to have received a notification now even if the session was
4557 // terminated. The offer creation may or may not have succeeded, but we
4558 // must have received a notification which, so the only invalid state
4559 // is kInit.
4560 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4561 }
4562}
4563
stefanc1aeaf02015-10-15 07:26:07 -07004564TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4565 TestPacketOptions();
4566}
4567
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004568// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4569// currently fails because upon disconnection and reconnection OnIceComplete is
4570// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004571
deadbeefcbecd352015-09-23 11:50:27 -07004572INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4573 WebRtcSessionTest,
4574 testing::Values(ALREADY_GENERATED,
4575 DTLS_IDENTITY_STORE));