blob: b80949ce10d7415a72b46847aceeb34962baba21 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/fakemetricsobserver.h"
16#include "webrtc/api/jsepicecandidate.h"
17#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080018#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000019#include "webrtc/base/fakenetwork.h"
20#include "webrtc/base/firewallsocketserver.h"
21#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/network.h"
24#include "webrtc/base/physicalsocketserver.h"
25#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020026#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/sslstreamadapter.h"
28#include "webrtc/base/stringutils.h"
29#include "webrtc/base/thread.h"
30#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070031#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/fakemediaengine.h"
33#include "webrtc/media/base/fakevideorenderer.h"
34#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010035#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080036#include "webrtc/media/sctp/sctptransportinternal.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080037#include "webrtc/p2p/base/packettransportinternal.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/p2p/base/stunserver.h"
39#include "webrtc/p2p/base/teststunserver.h"
40#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080042#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010043#include "webrtc/pc/channelmanager.h"
ossu7bb87ee2017-01-23 04:56:25 -080044#include "webrtc/pc/fakemediacontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010045#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080046#include "webrtc/pc/peerconnection.h"
47#include "webrtc/pc/sctputils.h"
48#include "webrtc/pc/test/fakertccertificategenerator.h"
49#include "webrtc/pc/videotrack.h"
50#include "webrtc/pc/webrtcsession.h"
51#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000058using webrtc::CreateSessionDescriptionObserver;
59using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070060using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070061using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using webrtc::JsepIceCandidate;
65using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000066using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::PeerConnectionInterface;
68using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070069using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000071using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000072using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000073using webrtc::kCreateChannelFailed;
74using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000076using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000077using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000078using webrtc::kSdpWithoutDtlsFingerprint;
79using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000082using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000084typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
85
wu@webrtc.org364f2042013-11-20 21:49:41 +000086static const int kClientAddrPort = 0;
87static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000088static const char kClientIPv6AddrHost1[] =
89 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const char kClientAddrHost2[] = "22.22.22.22";
91static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000092static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
93static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000094static const char kTurnUsername[] = "test";
95static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97static const char kSessionVersion[] = "1";
98
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099// Media index of candidates belonging to the first media content.
100static const int kMediaContentIndex0 = 0;
101static const char kMediaContentName0[] = "audio";
102
103// Media index of candidates belonging to the second media content.
104static const int kMediaContentIndex1 = 1;
105static const char kMediaContentName1[] = "video";
106
deadbeef953c2ce2017-01-09 14:53:41 -0800107static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const int kIceCandidatesTimeout = 10000;
109
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000110static const char kFakeDtlsFingerprint[] =
111 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
112 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
113
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000114static const char kTooLongIceUfragPwd[] =
115 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
116 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
117 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
119
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000120static const char kSdpWithRtx[] =
121 "v=0\r\n"
122 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
123 "s=-\r\n"
124 "t=0 0\r\n"
125 "a=msid-semantic: WMS stream1\r\n"
126 "m=video 9 RTP/SAVPF 0 96\r\n"
127 "c=IN IP4 0.0.0.0\r\n"
128 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
129 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
130 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
131 "a=mid:video\r\n"
132 "a=sendrecv\r\n"
133 "a=rtcp-mux\r\n"
134 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
135 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
136 "a=rtpmap:0 fake_video_codec/90000\r\n"
137 "a=rtpmap:96 rtx/90000\r\n"
138 "a=fmtp:96 apt=0\r\n";
139
deadbeefab9b2d12015-10-14 11:33:11 -0700140static const char kStream1[] = "stream1";
141static const char kVideoTrack1[] = "video1";
142static const char kAudioTrack1[] = "audio1";
143
144static const char kStream2[] = "stream2";
145static const char kVideoTrack2[] = "video2";
146static const char kAudioTrack2[] = "audio2";
147
Henrik Boström87713d02015-08-25 09:53:21 +0200148enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150class MockIceObserver : public webrtc::IceObserver {
151 public:
152 MockIceObserver()
153 : oncandidatesready_(false),
154 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
155 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
156 }
157
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200158 virtual ~MockIceObserver() = default;
159
zstein6dfd53a2017-03-06 13:49:03 -0800160 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800161 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700163 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800175 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000176 switch (candidate->sdp_mline_index()) {
177 case kMediaContentIndex0:
178 mline_0_candidates_.push_back(candidate->candidate());
179 break;
180 case kMediaContentIndex1:
181 mline_1_candidates_.push_back(candidate->candidate());
182 break;
183 default:
nissec80e7412017-01-11 05:56:46 -0800184 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 }
191
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700194 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700195 num_candidates_removed_ += candidates.size();
196 }
197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700203 std::vector<PeerConnectionInterface::IceConnectionState>
204 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700205 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206};
207
deadbeef953c2ce2017-01-09 14:53:41 -0800208// Used for tests in this file to verify that WebRtcSession responds to signals
209// from the SctpTransport correctly, and calls Start with the correct
210// local/remote ports.
211class FakeSctpTransport : public cricket::SctpTransportInternal {
212 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800213 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800214 bool Start(int local_port, int remote_port) override {
215 local_port_ = local_port;
216 remote_port_ = remote_port;
217 return true;
218 }
219 bool OpenStream(int sid) override { return true; }
220 bool ResetStream(int sid) override { return true; }
221 bool SendData(const cricket::SendDataParams& params,
222 const rtc::CopyOnWriteBuffer& payload,
223 cricket::SendDataResult* result = nullptr) override {
224 return true;
225 }
226 bool ReadyToSendData() override { return true; }
227 void set_debug_name_for_testing(const char* debug_name) override {}
228
229 int local_port() const { return local_port_; }
230 int remote_port() const { return remote_port_; }
231
232 private:
233 int local_port_ = -1;
234 int remote_port_ = -1;
235};
236
237class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
238 public:
239 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800240 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800241 last_fake_sctp_transport_ = new FakeSctpTransport();
242 return std::unique_ptr<cricket::SctpTransportInternal>(
243 last_fake_sctp_transport_);
244 }
245
246 FakeSctpTransport* last_fake_sctp_transport() {
247 return last_fake_sctp_transport_;
248 }
249
250 private:
251 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
252};
253
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254class WebRtcSessionForTest : public webrtc::WebRtcSession {
255 public:
zhihuang29ff8442016-07-27 11:07:25 -0700256 WebRtcSessionForTest(
257 webrtc::MediaControllerInterface* media_controller,
258 rtc::Thread* network_thread,
259 rtc::Thread* worker_thread,
260 rtc::Thread* signaling_thread,
261 cricket::PortAllocator* port_allocator,
262 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800263 std::unique_ptr<cricket::TransportController> transport_controller,
264 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
stefanc1aeaf02015-10-15 07:26:07 -0700265 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700266 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700267 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700268 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700269 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800270 std::move(transport_controller),
271 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 RegisterIceObserver(ice_observer);
273 }
274 virtual ~WebRtcSessionForTest() {}
275
deadbeefcbecd352015-09-23 11:50:27 -0700276 // Note that these methods are only safe to use if the signaling thread
277 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800278 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700279 return rtp_transport_channel(voice_channel());
280 }
281
deadbeef5bd5ca32017-02-10 11:31:50 -0800282 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700283 return rtcp_transport_channel(voice_channel());
284 }
285
deadbeef5bd5ca32017-02-10 11:31:50 -0800286 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700287 return rtp_transport_channel(video_channel());
288 }
289
deadbeef5bd5ca32017-02-10 11:31:50 -0800290 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700291 return rtcp_transport_channel(video_channel());
292 }
293
deadbeefcbecd352015-09-23 11:50:27 -0700294 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800295 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800296 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700297 if (!ch) {
298 return nullptr;
299 }
zhihuangb2cdd932017-01-19 16:54:25 -0800300 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700301 }
302
deadbeef5bd5ca32017-02-10 11:31:50 -0800303 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800304 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700305 if (!ch) {
306 return nullptr;
307 }
zhihuangb2cdd932017-01-19 16:54:25 -0800308 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700309 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310};
311
wu@webrtc.org91053e72013-08-10 07:18:04 +0000312class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000313 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000315 enum State {
316 kInit,
317 kFailed,
318 kSucceeded,
319 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000320 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000321
322 // CreateSessionDescriptionObserver implementation.
323 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000324 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000325 state_ = kSucceeded;
326 }
327 virtual void OnFailure(const std::string& error) {
328 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
330
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000331 SessionDescriptionInterface* description() { return description_.get(); }
332
333 SessionDescriptionInterface* ReleaseDescription() {
334 return description_.release();
335 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336
wu@webrtc.org91053e72013-08-10 07:18:04 +0000337 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
wu@webrtc.org91053e72013-08-10 07:18:04 +0000339 protected:
340 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
342 private:
kwibergd1fe2812016-04-27 06:47:29 -0700343 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000344 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345};
346
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800347class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000348 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800349 FakeAudioSource() : sink_(NULL) {}
350 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000351 if (sink_)
352 sink_->OnClose();
353 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000354
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000355 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800357 const cricket::AudioSource::Sink* sink() const { return sink_; }
358
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000359 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800360 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000361};
362
Henrik Boström87713d02015-08-25 09:53:21 +0200363class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700364 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
365 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 protected:
367 // TODO Investigate why ChannelManager crashes, if it's created
368 // after stun_server.
369 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700370 : media_engine_(new cricket::FakeMediaEngine()),
371 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800372 channel_manager_(new cricket::ChannelManager(
373 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
374 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
375 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700376 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700377 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800378 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
379 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700380 channel_manager_.get(),
381 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700382 tdesc_factory_(new cricket::TransportDescriptionFactory()),
383 desc_factory_(
384 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
385 tdesc_factory_.get())),
386 pss_(new rtc::PhysicalSocketServer),
387 vss_(new rtc::VirtualSocketServer(pss_.get())),
388 fss_(new rtc::FirewallSocketServer(vss_.get())),
389 ss_scope_(fss_.get()),
390 stun_socket_addr_(
391 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
392 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
393 stun_socket_addr_)),
394 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
395 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000396 cricket::ServerAddresses stun_servers;
397 stun_servers.insert(stun_socket_addr_);
398 allocator_.reset(new cricket::BasicPortAllocator(
399 &network_manager_,
400 stun_servers,
401 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000402 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700403 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 EXPECT_TRUE(channel_manager_->Init());
405 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000406 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 }
408
409 void AddInterface(const SocketAddress& addr) {
410 network_manager_.AddInterface(addr);
411 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700412 void RemoveInterface(const SocketAddress& addr) {
413 network_manager_.RemoveInterface(addr);
414 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415
Henrik Boströmd79599d2016-06-01 13:58:50 +0200416 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
417 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
418 // options. When DTLS is enabled a certificate will be used if provided,
419 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000420 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800421 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
422 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800424 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700426 media_controller_.get(), 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>(
429 new cricket::TransportController(rtc::Thread::Current(),
430 rtc::Thread::Current(),
deadbeef953c2ce2017-01-09 14:53:41 -0800431 allocator_.get())),
432 std::unique_ptr<FakeSctpTransportFactory>(
433 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700434 session_->SignalDataChannelOpenMessage.connect(
435 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436
zhihuang4dfb8ce2016-11-23 10:30:12 -0800437 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
439 observer_.ice_connection_state_);
440 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
441 observer_.ice_gathering_state_);
442
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200443 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800444 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700445 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 }
447
deadbeefab9b2d12015-10-14 11:33:11 -0700448 void OnDataChannelOpenMessage(const std::string& label,
449 const InternalDataChannelInit& config) {
450 last_data_channel_label_ = label;
451 last_data_channel_config_ = config;
452 }
453
zhihuang4dfb8ce2016-11-23 10:30:12 -0800454 void Init() {
455 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
456 }
457
458 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
459 Init(nullptr, rtcp_mux_policy);
460 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000462 void InitWithBundlePolicy(
463 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800464 configuration_.bundle_policy = bundle_policy;
465 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700466 }
467
468 void InitWithRtcpMuxPolicy(
469 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
470 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800471 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000472 }
473
Henrik Boström87713d02015-08-25 09:53:21 +0200474 // Successfully init with DTLS; with a certificate generated and supplied or
475 // with a store that generates it for us.
476 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200477 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200478 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800479 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200480 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200481 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200482 cert_generator.reset(new FakeRTCCertificateGenerator());
483 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200484 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700485 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200486 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800487 Init(std::move(cert_generator),
488 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200489 }
490
491 // Init with DTLS with a store that will fail to generate a certificate.
492 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200493 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
494 new FakeRTCCertificateGenerator());
495 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800496 Init(std::move(cert_generator),
497 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000498 }
499
jbauchcb560652016-08-04 05:20:32 -0700500 void InitWithGcm() {
501 rtc::CryptoOptions crypto_options;
502 crypto_options.enable_gcm_crypto_suites = true;
503 channel_manager_->SetCryptoOptions(crypto_options);
504 with_gcm_ = true;
505 Init();
506 }
507
deadbeefab9b2d12015-10-14 11:33:11 -0700508 void SendAudioVideoStream1() {
509 send_stream_1_ = true;
510 send_stream_2_ = false;
511 send_audio_ = true;
512 send_video_ = true;
513 }
514
515 void SendAudioVideoStream2() {
516 send_stream_1_ = false;
517 send_stream_2_ = true;
518 send_audio_ = true;
519 send_video_ = true;
520 }
521
522 void SendAudioVideoStream1And2() {
523 send_stream_1_ = true;
524 send_stream_2_ = true;
525 send_audio_ = true;
526 send_video_ = true;
527 }
528
529 void SendNothing() {
530 send_stream_1_ = false;
531 send_stream_2_ = false;
532 send_audio_ = false;
533 send_video_ = false;
534 }
535
536 void SendAudioOnlyStream2() {
537 send_stream_1_ = false;
538 send_stream_2_ = true;
539 send_audio_ = true;
540 send_video_ = false;
541 }
542
543 void SendVideoOnlyStream2() {
544 send_stream_1_ = false;
545 send_stream_2_ = true;
546 send_audio_ = false;
547 send_video_ = true;
548 }
549
550 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
551 if (send_stream_1_ && send_audio_) {
552 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
553 kStream1);
554 }
555 if (send_stream_1_ && send_video_) {
556 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
557 kStream1);
558 }
559 if (send_stream_2_ && send_audio_) {
560 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
561 kStream2);
562 }
563 if (send_stream_2_ && send_video_) {
564 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
565 kStream2);
566 }
567 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
568 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
569 data_channel_->label(),
570 data_channel_->label());
571 }
572 }
573
574 void GetOptionsForOffer(
575 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
576 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800577 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700578
deadbeefc80741f2015-10-22 13:14:45 -0700579 AddStreamsToOptions(session_options);
580 if (rtc_options.offer_to_receive_audio ==
581 RTCOfferAnswerOptions::kUndefined) {
582 session_options->recv_audio =
583 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
584 }
585 if (rtc_options.offer_to_receive_video ==
586 RTCOfferAnswerOptions::kUndefined) {
587 session_options->recv_video =
588 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
589 }
590 session_options->bundle_enabled =
591 session_options->bundle_enabled &&
592 (session_options->has_audio() || session_options->has_video() ||
593 session_options->has_data());
594
deadbeefab9b2d12015-10-14 11:33:11 -0700595 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
596 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700597 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
598 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700599 }
jbauchcb560652016-08-04 05:20:32 -0700600
601 if (with_gcm_) {
602 session_options->crypto_options.enable_gcm_crypto_suites = true;
603 }
deadbeefab9b2d12015-10-14 11:33:11 -0700604 }
605
htaa2a49d92016-03-04 02:51:39 -0800606 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
607 // ParseConstraintsForAnswer is used to set some defaults.
608 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700609
deadbeefc80741f2015-10-22 13:14:45 -0700610 AddStreamsToOptions(session_options);
611 session_options->bundle_enabled =
612 session_options->bundle_enabled &&
613 (session_options->has_audio() || session_options->has_video() ||
614 session_options->has_data());
615
zhihuang9763d562016-08-05 11:14:50 -0700616 if (session_->data_channel_type() != cricket::DCT_RTP) {
617 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700618 }
jbauchcb560652016-08-04 05:20:32 -0700619
620 if (with_gcm_) {
621 session_options->crypto_options.enable_gcm_crypto_suites = true;
622 }
deadbeefab9b2d12015-10-14 11:33:11 -0700623 }
624
625 // Creates a local offer and applies it. Starts ICE.
626 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 // to decide which streams to create.
628 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000629 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 SetLocalDescriptionWithoutError(offer);
631 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
632 observer_.ice_gathering_state_,
633 kIceCandidatesTimeout);
634 }
635
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000636 SessionDescriptionInterface* CreateOffer() {
637 PeerConnectionInterface::RTCOfferAnswerOptions options;
638 options.offer_to_receive_audio =
639 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
640
641 return CreateOffer(options);
642 }
643
wu@webrtc.org91053e72013-08-10 07:18:04 +0000644 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800645 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000646 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000647 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700648 cricket::MediaSessionOptions session_options;
649 GetOptionsForOffer(options, &session_options);
650 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000651 EXPECT_TRUE_WAIT(
652 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000653 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000654 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000655 }
656
657 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800658 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000659 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000660 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800661 cricket::MediaSessionOptions session_options = options;
662 GetOptionsForAnswer(&session_options);
663 // Overwrite recv_audio and recv_video with passed-in values.
664 session_options.recv_video = options.recv_video;
665 session_options.recv_audio = options.recv_audio;
666 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000667 EXPECT_TRUE_WAIT(
668 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000669 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000670 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000671 }
672
htaa2a49d92016-03-04 02:51:39 -0800673 SessionDescriptionInterface* CreateAnswer() {
674 cricket::MediaSessionOptions options;
675 options.recv_video = true;
676 options.recv_audio = true;
677 return CreateAnswer(options);
678 }
679
wu@webrtc.org364f2042013-11-20 21:49:41 +0000680 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 return (session_->voice_channel() != NULL &&
682 session_->video_channel() != NULL);
683 }
684
jbauchcb560652016-08-04 05:20:32 -0700685 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
686 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 ASSERT_TRUE(session_.get() != NULL);
688 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
689 ASSERT_TRUE(content != NULL);
690 const cricket::AudioContentDescription* audio_content =
691 static_cast<const cricket::AudioContentDescription*>(
692 content->description);
693 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700694 if (!gcm_enabled) {
695 ASSERT_EQ(1U, audio_content->cryptos().size());
696 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
697 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
698 audio_content->cryptos()[0].cipher_suite);
699 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
700 audio_content->protocol());
701 } else {
702 // The offer contains 3 possible crypto suites, the answer 1.
703 EXPECT_LE(1U, audio_content->cryptos().size());
704 EXPECT_NE(2U, audio_content->cryptos().size());
705 EXPECT_GE(3U, audio_content->cryptos().size());
706 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
707 ASSERT_EQ("AEAD_AES_256_GCM",
708 audio_content->cryptos()[0].cipher_suite);
709 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
710 audio_content->protocol());
711 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
713 content = cricket::GetFirstVideoContent(sdp);
714 ASSERT_TRUE(content != NULL);
715 const cricket::VideoContentDescription* video_content =
716 static_cast<const cricket::VideoContentDescription*>(
717 content->description);
718 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700719 if (!gcm_enabled) {
720 ASSERT_EQ(1U, video_content->cryptos().size());
721 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
722 video_content->cryptos()[0].cipher_suite);
723 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
724 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
725 video_content->protocol());
726 } else {
727 // The offer contains 3 possible crypto suites, the answer 1.
728 EXPECT_LE(1U, video_content->cryptos().size());
729 EXPECT_NE(2U, video_content->cryptos().size());
730 EXPECT_GE(3U, video_content->cryptos().size());
731 ASSERT_EQ("AEAD_AES_256_GCM",
732 video_content->cryptos()[0].cipher_suite);
733 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
734 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
735 video_content->protocol());
736 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 }
738
739 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
740 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
741 ASSERT_TRUE(content != NULL);
742 const cricket::AudioContentDescription* audio_content =
743 static_cast<const cricket::AudioContentDescription*>(
744 content->description);
745 ASSERT_TRUE(audio_content != NULL);
746 ASSERT_EQ(0U, audio_content->cryptos().size());
747
748 content = cricket::GetFirstVideoContent(sdp);
749 ASSERT_TRUE(content != NULL);
750 const cricket::VideoContentDescription* video_content =
751 static_cast<const cricket::VideoContentDescription*>(
752 content->description);
753 ASSERT_TRUE(video_content != NULL);
754 ASSERT_EQ(0U, video_content->cryptos().size());
755
756 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700757 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700759 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 video_content->protocol());
761 } else {
762 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
763 audio_content->protocol());
764 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
765 video_content->protocol());
766 }
767 }
768
769 // Set the internal fake description factories to do DTLS-SRTP.
770 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000771 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000773 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200774 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800775 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700776 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800777 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
779 }
780
781 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
782 bool expected) {
783 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
784 ASSERT_TRUE(audio != NULL);
785 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 const TransportInfo* video = sdp->GetTransportInfoByName("video");
787 ASSERT_TRUE(video != NULL);
788 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 }
790
791 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000792 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000794 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000795 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000797 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000799 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
800 offer);
htaa2a49d92016-03-04 02:51:39 -0800801 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 // Answer should be NULL as no crypto params in offer.
803 ASSERT_TRUE(answer == NULL);
804 }
805
806 void VerifyAnswerFromCryptoOffer() {
807 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000808 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700810 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
812 ASSERT_TRUE(offer.get() != NULL);
813 VerifyCryptoParams(offer->description());
814 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700815 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 ASSERT_TRUE(answer.get() != NULL);
817 VerifyCryptoParams(answer->description());
818 }
819
deadbeef0ed85b22016-02-23 17:24:52 -0800820 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
821 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800823 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 }
825
826 const cricket::ContentInfos& contents = desc1->contents();
827 cricket::ContentInfos::const_iterator it = contents.begin();
828
829 for (; it != contents.end(); ++it) {
830 const cricket::TransportDescription* transport_desc1 =
831 desc1->GetTransportDescriptionByName(it->name);
832 const cricket::TransportDescription* transport_desc2 =
833 desc2->GetTransportDescriptionByName(it->name);
834 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800835 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 }
837 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
838 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800839 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 }
841 }
deadbeef0ed85b22016-02-23 17:24:52 -0800842 return true;
843 }
844
845 // Compares ufrag/password only for the specified |media_type|.
846 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
847 const cricket::SessionDescription* desc2,
848 cricket::MediaType media_type) {
849 if (desc1->contents().size() != desc2->contents().size()) {
850 return false;
851 }
852
853 const cricket::ContentInfo* cinfo =
854 cricket::GetFirstMediaContent(desc1->contents(), media_type);
855 const cricket::TransportDescription* transport_desc1 =
856 desc1->GetTransportDescriptionByName(cinfo->name);
857 const cricket::TransportDescription* transport_desc2 =
858 desc2->GetTransportDescriptionByName(cinfo->name);
859 if (!transport_desc1 || !transport_desc2) {
860 return false;
861 }
862 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
863 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
864 return false;
865 }
866 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000868
869 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
870 std::string *sdp) {
871 const cricket::SessionDescription* desc = current_desc->description();
872 EXPECT_TRUE(current_desc->ToString(sdp));
873
874 const cricket::ContentInfos& contents = desc->contents();
875 cricket::ContentInfos::const_iterator it = contents.begin();
876 // Replace ufrag and pwd lines with empty strings.
877 for (; it != contents.end(); ++it) {
878 const cricket::TransportDescription* transport_desc =
879 desc->GetTransportDescriptionByName(it->name);
880 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
881 + "\r\n";
882 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
883 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000884 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000885 "", 0,
886 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000887 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000888 "", 0,
889 sdp);
890 }
891 }
892
deadbeef0ed85b22016-02-23 17:24:52 -0800893 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
894 const std::string& ufrag,
895 const std::string& pwd) {
896 cricket::SessionDescription* desc = current_desc->description();
897 for (TransportInfo& transport_info : desc->transport_infos()) {
898 cricket::TransportDescription& transport_desc =
899 transport_info.description;
900 transport_desc.ice_ufrag = ufrag;
901 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000902 }
903 }
904
deadbeef0ed85b22016-02-23 17:24:52 -0800905 // Sets ufrag/pwd for specified |media_type|.
906 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
907 cricket::MediaType media_type,
908 const std::string& ufrag,
909 const std::string& pwd) {
910 cricket::SessionDescription* desc = current_desc->description();
911 const cricket::ContentInfo* cinfo =
912 cricket::GetFirstMediaContent(desc->contents(), media_type);
913 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
914 cricket::TransportDescription* transport_desc =
915 &transport_info->description;
916 transport_desc->ice_ufrag = ufrag;
917 transport_desc->ice_pwd = pwd;
918 }
919
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 // Creates a remote offer and and applies it as a remote description,
921 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700922 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 // to decide which local and remote streams to create.
924 void CreateAndSetRemoteOfferAndLocalAnswer() {
925 SessionDescriptionInterface* offer = CreateRemoteOffer();
926 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800927 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 SetLocalDescriptionWithoutError(answer);
929 }
930 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
931 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700932 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
934 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700935 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 SetLocalDescriptionWithoutError(desc);
937 EXPECT_EQ(expected_state, session_->state());
938 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000939 void SetLocalDescriptionExpectError(const std::string& action,
940 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 SessionDescriptionInterface* desc) {
942 std::string error;
943 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000944 std::string sdp_type = "local ";
945 sdp_type.append(action);
946 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_NE(std::string::npos, error.find(expected_error));
948 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000949 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
950 SessionDescriptionInterface* desc) {
951 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
952 expected_error, desc);
953 }
954 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
955 SessionDescriptionInterface* desc) {
956 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
957 expected_error, desc);
958 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
960 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
961 }
962 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700963 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 SetRemoteDescriptionWithoutError(desc);
965 EXPECT_EQ(expected_state, session_->state());
966 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 void SetRemoteDescriptionExpectError(const std::string& action,
968 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 SessionDescriptionInterface* desc) {
970 std::string error;
971 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000972 std::string sdp_type = "remote ";
973 sdp_type.append(action);
974 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 EXPECT_NE(std::string::npos, error.find(expected_error));
976 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000977 void SetRemoteDescriptionOfferExpectError(
978 const std::string& expected_error, SessionDescriptionInterface* desc) {
979 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
980 expected_error, desc);
981 }
982 void SetRemoteDescriptionPranswerExpectError(
983 const std::string& expected_error, SessionDescriptionInterface* desc) {
984 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
985 expected_error, desc);
986 }
987 void SetRemoteDescriptionAnswerExpectError(
988 const std::string& expected_error, SessionDescriptionInterface* desc) {
989 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
990 expected_error, desc);
991 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
994 SessionDescriptionInterface** nocrypto_answer) {
995 // Create a SDP without Crypto.
996 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000997 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 options.bundle_enabled = true;
999 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1000 ASSERT_TRUE(*offer != NULL);
1001 VerifyCryptoParams((*offer)->description());
1002
1003 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1004 cricket::SEC_DISABLED);
1005 EXPECT_TRUE(*nocrypto_answer != NULL);
1006 }
1007
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001008 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1009 SessionDescriptionInterface** nodtls_answer) {
1010 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001011 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001012 options.bundle_enabled = true;
1013
kwibergd1fe2812016-04-27 06:47:29 -07001014 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001015 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1016
1017 *nodtls_answer =
1018 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1019 EXPECT_TRUE(*nodtls_answer != NULL);
1020 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1021 VerifyCryptoParams((*nodtls_answer)->description());
1022
1023 SetFactoryDtlsSrtp();
1024 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1025 ASSERT_TRUE(*offer != NULL);
1026 VerifyFingerprintStatus((*offer)->description(), true);
1027 VerifyCryptoParams((*offer)->description());
1028 }
1029
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 JsepSessionDescription* CreateRemoteOfferWithVersion(
1031 cricket::MediaSessionOptions options,
1032 cricket::SecurePolicy secure_policy,
1033 const std::string& session_version,
1034 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001035 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 const cricket::SessionDescription* cricket_desc = NULL;
1037 if (current_desc) {
1038 cricket_desc = current_desc->description();
1039 session_id = current_desc->session_id();
1040 }
1041
1042 desc_factory_->set_secure(secure_policy);
1043 JsepSessionDescription* offer(
1044 new JsepSessionDescription(JsepSessionDescription::kOffer));
1045 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1046 session_id, session_version)) {
1047 delete offer;
1048 offer = NULL;
1049 }
1050 return offer;
1051 }
1052 JsepSessionDescription* CreateRemoteOffer(
1053 cricket::MediaSessionOptions options) {
1054 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1055 kSessionVersion, NULL);
1056 }
1057 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001058 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1059 return CreateRemoteOfferWithVersion(
1060 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 }
1062 JsepSessionDescription* CreateRemoteOffer(
1063 cricket::MediaSessionOptions options,
1064 const SessionDescriptionInterface* current_desc) {
1065 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1066 kSessionVersion, current_desc);
1067 }
1068
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001069 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1070 const char* sctp_stream_name, int new_port,
1071 cricket::MediaSessionOptions options) {
1072 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001073 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1074 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001075 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1076 }
1077
1078 // Takes ownership of offer_basis (and deletes it).
1079 JsepSessionDescription* ChangeSDPSctpPort(
1080 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1081 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1082 // SessionDescription from the mutated string.
1083 const char* default_port_str = "5000";
1084 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001085 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001086 std::string offer_str;
1087 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001088 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001089 new_port_str, strlen(new_port_str),
1090 &offer_str);
1091 JsepSessionDescription* offer = new JsepSessionDescription(
1092 offer_basis->type());
1093 delete offer_basis;
1094 offer->Initialize(offer_str, NULL);
1095 return offer;
1096 }
1097
deadbeefab9b2d12015-10-14 11:33:11 -07001098 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 // before this function to decide which streams to create.
1100 JsepSessionDescription* CreateRemoteOffer() {
1101 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001102 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 return CreateRemoteOffer(options, session_->remote_description());
1104 }
1105
1106 JsepSessionDescription* CreateRemoteAnswer(
1107 const SessionDescriptionInterface* offer,
1108 cricket::MediaSessionOptions options,
1109 cricket::SecurePolicy policy) {
1110 desc_factory_->set_secure(policy);
1111 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001112 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 JsepSessionDescription* answer(
1114 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1115 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1116 options, NULL),
1117 session_id, kSessionVersion)) {
1118 delete answer;
1119 answer = NULL;
1120 }
1121 return answer;
1122 }
1123
1124 JsepSessionDescription* CreateRemoteAnswer(
1125 const SessionDescriptionInterface* offer,
1126 cricket::MediaSessionOptions options) {
1127 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1128 }
1129
deadbeefab9b2d12015-10-14 11:33:11 -07001130 // Creates an answer session description.
1131 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 // to decide which streams to create.
1133 JsepSessionDescription* CreateRemoteAnswer(
1134 const SessionDescriptionInterface* offer) {
1135 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001136 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1138 }
1139
1140 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001141 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001142 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001143 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001144
1145 PeerConnectionInterface::RTCOfferAnswerOptions options;
1146 options.use_rtp_mux = bundle;
1147
1148 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1150 // and answer.
1151 SetLocalDescriptionWithoutError(offer);
1152
kwibergd1fe2812016-04-27 06:47:29 -07001153 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001154 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 std::string sdp;
1156 EXPECT_TRUE(answer->ToString(&sdp));
1157
1158 size_t expected_candidate_num = 2;
1159 if (!rtcp_mux) {
1160 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1161 // for rtp and rtcp.
1162 expected_candidate_num = 4;
1163 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 const std::string kRtcpMux = "a=rtcp-mux";
1165 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001166 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 kXRtcpMux.c_str(), kXRtcpMux.length(),
1168 &sdp);
1169 }
1170
1171 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1172 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173
1174 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001175 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1177 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001178 if (bundle) {
1179 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1180 } else {
1181 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 }
1183 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184
zhihuang3a334652016-05-05 18:37:49 -07001185 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1186 const std::string& codec_name) {
1187 for (const auto& content : desc->description()->contents()) {
1188 if (static_cast<cricket::MediaContentDescription*>(content.description)
1189 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1190 const auto* mdesc =
1191 static_cast<cricket::VideoContentDescription*>(content.description);
1192 for (const auto& codec : mdesc->codecs()) {
1193 if (codec.name == codec_name) {
1194 return true;
1195 }
1196 }
1197 }
1198 }
1199 return false;
1200 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001201 // Helper class to configure loopback network and verify Best
1202 // Connection using right IP protocol for TestLoopbackCall
1203 // method. LoopbackNetworkManager applies firewall rules to block
1204 // all ping traffic once ICE completed, and remove them to observe
1205 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1206 // verifies the best connection is using the right IP protocol after
1207 // initial ICE convergences.
1208
1209 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001210 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001211 LoopbackNetworkConfiguration()
1212 : test_ipv6_network_(false),
1213 test_extra_ipv4_network_(false),
1214 best_connection_after_initial_ice_converged_(1, 0) {}
1215
1216 // Used to track the expected best connection count in each IP protocol.
1217 struct ExpectedBestConnection {
1218 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1219 : ipv4_count_(ipv4_count),
1220 ipv6_count_(ipv6_count) {}
1221
1222 int ipv4_count_;
1223 int ipv6_count_;
1224 };
1225
1226 bool test_ipv6_network_;
1227 bool test_extra_ipv4_network_;
1228 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1229
1230 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001231 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001232 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1233 }
1234
1235 private:
jbauchac8869e2015-07-03 01:36:14 -07001236 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001237 const ExpectedBestConnection& expected) const {
1238 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001239 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1240 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001241 expected.ipv4_count_);
1242 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001243 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1244 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001245 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001246 // This is used in the loopback call so there is only single host to host
1247 // candidate pair.
1248 EXPECT_EQ(metrics_observer->GetEnumCounter(
1249 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1250 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001251 0);
1252 EXPECT_EQ(metrics_observer->GetEnumCounter(
1253 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1254 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001255 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001256 }
1257 };
1258
1259 class LoopbackNetworkManager {
1260 public:
1261 LoopbackNetworkManager(WebRtcSessionTest* session,
1262 const LoopbackNetworkConfiguration& config)
1263 : config_(config) {
1264 session->AddInterface(
1265 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1266 if (config_.test_extra_ipv4_network_) {
1267 session->AddInterface(
1268 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1269 }
1270 if (config_.test_ipv6_network_) {
1271 session->AddInterface(
1272 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1273 }
1274 }
1275
1276 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1277 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1278 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1279 if (config_.test_extra_ipv4_network_) {
1280 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1281 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1282 }
1283 if (config_.test_ipv6_network_) {
1284 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1285 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1286 }
1287 }
1288
1289 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1290
1291 private:
1292 LoopbackNetworkConfiguration config_;
1293 };
1294
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 // The method sets up a call from the session to itself, in a loopback
1296 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001297 // disconnection, and then a permanent disconnection.
1298 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1300 // While running the call, this method also checks if the session goes through
1301 // the correct sequence of ICE states when a connection is established,
1302 // broken, and re-established.
1303 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001304 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1305 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001307
stefanc1aeaf02015-10-15 07:26:07 -07001308 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001309 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001310 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001311 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312
1313 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1314 observer_.ice_gathering_state_);
1315 SetLocalDescriptionWithoutError(offer);
1316 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1317 observer_.ice_connection_state_);
1318 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001319 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1321 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001322 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323
1324 std::string sdp;
1325 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001326 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1327 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 ASSERT_TRUE(desc != NULL);
1329 SetRemoteDescriptionWithoutError(desc);
1330
1331 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001332 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001333
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001334 // The ice connection state is "Connected" too briefly to catch in a test.
1335 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001336 observer_.ice_connection_state_, kIceCandidatesTimeout);
1337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338
stefanc1aeaf02015-10-15 07:26:07 -07001339 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1340 LoopbackNetworkManager loopback_network_manager(this, config);
1341 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001342 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 // Adding firewall rule to block ping requests, which should cause
1344 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001345
1346 loopback_network_manager.ApplyFirewallRules(fss_.get());
1347
1348 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1350 observer_.ice_connection_state_,
1351 kIceCandidatesTimeout);
1352
jbauchac8869e2015-07-03 01:36:14 -07001353 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001354
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001356 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001358 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001359 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 observer_.ice_connection_state_,
1361 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001362
1363 // Now we block ping requests and wait until the ICE connection transitions
1364 // to the Failed state. This will take at least 30 seconds because it must
1365 // wait for the Port to timeout.
1366 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001367
1368 loopback_network_manager.ApplyFirewallRules(fss_.get());
1369 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001370 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001371 observer_.ice_connection_state_,
1372 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 }
1374
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001375 void TestLoopbackCall() {
1376 LoopbackNetworkConfiguration config;
1377 TestLoopbackCall(config);
1378 }
1379
stefanc1aeaf02015-10-15 07:26:07 -07001380 void TestPacketOptions() {
1381 media_controller_.reset(
1382 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1383 LoopbackNetworkConfiguration config;
1384 LoopbackNetworkManager loopback_network_manager(this, config);
1385
1386 SetupLoopbackCall();
1387
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001388 // Wait for channel to be ready for sending.
1389 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001390 uint8_t test_packet[15] = {0};
1391 rtc::PacketOptions options;
1392 options.packet_id = 10;
1393 media_engine_->GetVideoChannel(0)
1394 ->SendRtp(test_packet, sizeof(test_packet), options);
1395
1396 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001397 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1398 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001399 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1400 }
1401
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1403 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001404 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1405 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001406
1407 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001408 std::vector<cricket::AudioCodec> codecs =
1409 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 codecs.push_back(kCNCodec1);
1411 codecs.push_back(kCNCodec2);
1412 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001413 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 }
1415
1416 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1417 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001418 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001420 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001421 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1423 if (audio_content_desc->codecs()[i].name == "CN")
1424 return false;
1425 }
1426 return true;
1427 }
1428
deadbeefab9b2d12015-10-14 11:33:11 -07001429 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001430 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001431 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001432 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1433 data_channel_ = DataChannel::Create(
1434 session_.get(), session_->data_channel_type(), "datachannel", dci);
1435 }
1436
1437 void SetLocalDescriptionWithDataChannel() {
1438 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001439 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 SetLocalDescriptionWithoutError(offer);
1441 }
1442
wu@webrtc.org91053e72013-08-10 07:18:04 +00001443 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001444 RTCCertificateGenerationMethod cert_gen_method,
1445 CreateSessionDescriptionRequest::Type type) {
1446 InitWithDtls(cert_gen_method);
1447 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1448 }
1449
1450 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1451 CreateSessionDescriptionRequest::Type type) {
1452 InitWithDtlsIdentityGenFail();
1453 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1454 }
1455
1456 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001457 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001458 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001459 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001460 if (type == CreateSessionDescriptionRequest::kAnswer) {
1461 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001462 std::unique_ptr<JsepSessionDescription> offer(
1463 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001464 ASSERT_TRUE(offer.get() != NULL);
1465 SetRemoteDescriptionWithoutError(offer.release());
1466 }
1467
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001468 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001469 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001470 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001471 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001472 observers[kNumber];
1473 for (int i = 0; i < kNumber; ++i) {
1474 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1475 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001476 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001477 } else {
htaa2a49d92016-03-04 02:51:39 -08001478 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001479 }
1480 }
1481
1482 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1483 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1484 WebRtcSessionCreateSDPObserverForTest::kFailed;
1485
1486 for (int i = 0; i < kNumber; ++i) {
1487 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1488 if (success) {
1489 EXPECT_TRUE(observers[i]->description() != NULL);
1490 } else {
1491 EXPECT_TRUE(observers[i]->description() == NULL);
1492 }
1493 }
1494 }
1495
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001496 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001497 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001498 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001499 turn_server.credentials = credentials;
1500 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001501 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001502 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001503 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001504 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001505 }
1506
skvlad11a9cbf2016-10-07 11:53:05 -07001507 webrtc::RtcEventLogNullImpl event_log_;
deadbeef112b2e92017-02-10 20:13:37 -08001508 // |media_engine_| and |data_engine_| are actually owned by
1509 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 cricket::FakeMediaEngine* media_engine_;
1511 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001512 // Actually owned by session_.
1513 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001514 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001515 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001516 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1517 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1518 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1519 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1520 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1521 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001522 rtc::SocketServerScope ss_scope_;
1523 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001524 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001525 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001526 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001527 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001528 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001529 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001530 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 MockIceObserver observer_;
1532 cricket::FakeVideoMediaChannel* video_channel_;
1533 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001534 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001535 // The following flags affect options created for CreateOffer/CreateAnswer.
1536 bool send_stream_1_ = false;
1537 bool send_stream_2_ = false;
1538 bool send_audio_ = false;
1539 bool send_video_ = false;
1540 rtc::scoped_refptr<DataChannel> data_channel_;
1541 // Last values received from data channel creation signal.
1542 std::string last_data_channel_label_;
1543 InternalDataChannelInit last_data_channel_config_;
jbauchcb560652016-08-04 05:20:32 -07001544 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545};
1546
Henrik Boström87713d02015-08-25 09:53:21 +02001547TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1548 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001549 // SDES is disabled when DTLS is on.
1550 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551}
1552
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001554 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001555 // SDES is required if DTLS is off.
1556 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001557}
1558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1560 TestSessionCandidatesWithBundleRtcpMux(false, false);
1561}
1562
1563// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1564// with rtcp-mux and/or bundle.
1565TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1566 TestSessionCandidatesWithBundleRtcpMux(false, true);
1567}
1568
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1570 TestSessionCandidatesWithBundleRtcpMux(true, true);
1571}
1572
1573TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001574 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1575 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001576 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001577 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 InitiateCall();
1579 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1580 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1581 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1582}
1583
deadbeeff5f03e82016-06-06 11:16:06 -07001584TEST_F(WebRtcSessionTest, TestStunError) {
1585 rtc::ScopedFakeClock clock;
1586
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001587 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1588 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001589 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001590 rtc::FP_UDP,
1591 rtc::FD_ANY,
1592 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001593 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001594 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001596 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001597 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1598 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1600 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001601 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1602 // warning.
1603 session_->Close();
1604 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605}
1606
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001607TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001608 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001609 SessionDescriptionInterface* offer = NULL;
1610 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1611 std::string unknown_action;
1612 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1613 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1614}
1615
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616// Test creating offers and receive answers and make sure the
1617// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001618TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001619 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001620 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001621 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 const std::string session_id_orig = offer->session_id();
1623 const std::string session_version_orig = offer->session_version();
1624 SetLocalDescriptionWithoutError(offer);
1625
deadbeefab9b2d12015-10-14 11:33:11 -07001626 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 SessionDescriptionInterface* answer =
1628 CreateRemoteAnswer(session_->local_description());
1629 SetRemoteDescriptionWithoutError(answer);
1630
1631 video_channel_ = media_engine_->GetVideoChannel(0);
1632 voice_channel_ = media_engine_->GetVoiceChannel(0);
1633
1634 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1635 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1636
1637 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1638 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1639
1640 ASSERT_EQ(1u, video_channel_->send_streams().size());
1641 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1642 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1643 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1644
1645 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001646 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001647 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648
1649 // Verify the session id is the same and the session version is
1650 // increased.
1651 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001652 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1653 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654
1655 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001656 EXPECT_EQ(0u, video_channel_->send_streams().size());
1657 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658
deadbeefab9b2d12015-10-14 11:33:11 -07001659 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 answer = CreateRemoteAnswer(session_->local_description());
1661 SetRemoteDescriptionWithoutError(answer);
1662
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001663 // Make sure the receive streams have not changed.
1664 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1665 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1666 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1667 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1668}
1669
1670// Test receiving offers and creating answers and make sure the
1671// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001672TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001673 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001674 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001675 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001676 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 SetRemoteDescriptionWithoutError(offer);
1678
deadbeefab9b2d12015-10-14 11:33:11 -07001679 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001680 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001681 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 SetLocalDescriptionWithoutError(answer);
1683
1684 const std::string session_id_orig = answer->session_id();
1685 const std::string session_version_orig = answer->session_version();
1686
1687 video_channel_ = media_engine_->GetVideoChannel(0);
1688 voice_channel_ = media_engine_->GetVoiceChannel(0);
1689
htaa2a49d92016-03-04 02:51:39 -08001690 ASSERT_TRUE(video_channel_);
1691 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1693 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1694
1695 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1696 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1697
1698 ASSERT_EQ(1u, video_channel_->send_streams().size());
1699 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1700 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1701 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1702
deadbeefab9b2d12015-10-14 11:33:11 -07001703 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001704 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 SetRemoteDescriptionWithoutError(offer);
1706
1707 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001708 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001709 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710
1711 // Verify the session id is the same and the session version is
1712 // increased.
1713 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001714 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1715 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 SetLocalDescriptionWithoutError(answer);
1717
1718 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1719 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1720 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1721 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1722 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1723 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1724
1725 // Make sure we have no send streams.
1726 EXPECT_EQ(0u, video_channel_->send_streams().size());
1727 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1728}
1729
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001730TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001731 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001732 media_engine_->set_fail_create_channel(true);
1733
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001734 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001735 ASSERT_TRUE(offer != NULL);
1736 // SetRemoteDescription and SetLocalDescription will take the ownership of
1737 // the offer.
1738 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001739 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001740 ASSERT_TRUE(offer != NULL);
1741 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1742}
1743
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744//
1745// Tests for creating/setting SDP under different SDES/DTLS polices:
1746//
1747// --DTLS off and SDES on
1748// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1749// set local/remote offer/answer with crypto --> success
1750// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1751// failure
1752// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1753// failure
1754// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1755// failure
1756//
1757// --DTLS on and SDES off
1758// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1759// set local/remote offer/answer with DTLS fingerprint --> success
1760// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1761// fingerprint --> failure
1762// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1763// --> failure
1764// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1765// --> failure
1766//
1767// --Encryption disabled: DTLS off and SDES off
1768// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1769// answer without SDES or DTLS --> success
1770// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1771// answer without SDES or DTLS --> success
1772//
1773
1774// Test that we return a failure when applying a remote/local offer that doesn't
1775// have cryptos enabled when DTLS is off.
1776TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001777 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001779 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 JsepSessionDescription* offer = CreateRemoteOffer(
1781 options, cricket::SEC_DISABLED);
1782 ASSERT_TRUE(offer != NULL);
1783 VerifyNoCryptoParams(offer->description(), false);
1784 // SetRemoteDescription and SetLocalDescription will take the ownership of
1785 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1788 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790}
1791
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001792// Test that we return a failure when applying a local answer that doesn't have
1793// cryptos enabled when DTLS is off.
1794TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001795 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 SessionDescriptionInterface* offer = NULL;
1797 SessionDescriptionInterface* answer = NULL;
1798 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1799 // SetRemoteDescription and SetLocalDescription will take the ownership of
1800 // the offer.
1801 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803}
1804
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001805// Test we will return fail when apply an remote answer that doesn't have
1806// crypto enabled when DTLS is off.
1807TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001808 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 SessionDescriptionInterface* offer = NULL;
1810 SessionDescriptionInterface* answer = NULL;
1811 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1812 // SetRemoteDescription and SetLocalDescription will take the ownership of
1813 // the offer.
1814 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001815 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816}
1817
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1819// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001820TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001821 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001822 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 SetFactoryDtlsSrtp();
1824 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001825 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001826 JsepSessionDescription* offer =
1827 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 ASSERT_TRUE(offer != NULL);
1829 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001830 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831
1832 // SetRemoteDescription will take the ownership of the offer.
1833 SetRemoteDescriptionWithoutError(offer);
1834
1835 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001836 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 ASSERT_TRUE(answer != NULL);
1838 VerifyFingerprintStatus(answer->description(), true);
1839 // Check that we don't have an a=crypto line in the answer.
1840 VerifyNoCryptoParams(answer->description(), true);
1841
1842 // Now set the local description, which should work, even without a=crypto.
1843 SetLocalDescriptionWithoutError(answer);
1844}
1845
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001846// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1847// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001848TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001849 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001850 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001851 SetFactoryDtlsSrtp();
1852
1853 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001854 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001855 ASSERT_TRUE(offer != NULL);
1856 VerifyFingerprintStatus(offer->description(), true);
1857 // Check that we don't have an a=crypto line in the offer.
1858 VerifyNoCryptoParams(offer->description(), true);
1859
1860 // Now set the local description, which should work, even without a=crypto.
1861 SetLocalDescriptionWithoutError(offer);
1862
1863 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001864 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 JsepSessionDescription* answer =
1866 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1867 ASSERT_TRUE(answer != NULL);
1868 VerifyFingerprintStatus(answer->description(), true);
1869 VerifyNoCryptoParams(answer->description(), true);
1870
1871 // SetRemoteDescription will take the ownership of the answer.
1872 SetRemoteDescriptionWithoutError(answer);
1873}
1874
1875// Test that if we support DTLS and the other side didn't offer a fingerprint,
1876// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001877TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001878 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001880 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001881 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 JsepSessionDescription* offer = CreateRemoteOffer(
1883 options, cricket::SEC_REQUIRED);
1884 ASSERT_TRUE(offer != NULL);
1885 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001886 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001888 // SetRemoteDescription will take the ownership of the offer.
1889 SetRemoteDescriptionOfferExpectError(
1890 kSdpWithoutDtlsFingerprint, offer);
1891
1892 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1893 // SetLocalDescription will take the ownership of the offer.
1894 SetLocalDescriptionOfferExpectError(
1895 kSdpWithoutDtlsFingerprint, offer);
1896}
1897
1898// Test that we return a failure when applying a local answer that doesn't have
1899// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001900TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001901 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001902 SessionDescriptionInterface* offer = NULL;
1903 SessionDescriptionInterface* answer = NULL;
1904 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1905
1906 // SetRemoteDescription and SetLocalDescription will take the ownership of
1907 // the offer and answer.
1908 SetRemoteDescriptionWithoutError(offer);
1909 SetLocalDescriptionAnswerExpectError(
1910 kSdpWithoutDtlsFingerprint, answer);
1911}
1912
1913// Test that we return a failure when applying a remote answer that doesn't have
1914// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001915TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001916 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001917 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001919 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001920 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001921 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001923 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924
1925 // SetRemoteDescription and SetLocalDescription will take the ownership of
1926 // the offer and answer.
1927 SetLocalDescriptionWithoutError(offer);
1928 SetRemoteDescriptionAnswerExpectError(
1929 kSdpWithoutDtlsFingerprint, answer);
1930}
1931
1932// Test that we create a local offer without SDES or DTLS and accept a remote
1933// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001934TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001935 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001937 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938
1939 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001940 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001941 ASSERT_TRUE(offer != NULL);
1942 VerifyFingerprintStatus(offer->description(), false);
1943 // Check that we don't have an a=crypto line in the offer.
1944 VerifyNoCryptoParams(offer->description(), false);
1945
1946 // Now set the local description, which should work, even without a=crypto.
1947 SetLocalDescriptionWithoutError(offer);
1948
1949 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001950 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001951 JsepSessionDescription* answer =
1952 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1953 ASSERT_TRUE(answer != NULL);
1954 VerifyFingerprintStatus(answer->description(), false);
1955 VerifyNoCryptoParams(answer->description(), false);
1956
1957 // SetRemoteDescription will take the ownership of the answer.
1958 SetRemoteDescriptionWithoutError(answer);
1959}
1960
1961// Test that we create a local answer without SDES or DTLS and accept a remote
1962// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001963TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001965 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966
1967 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001968 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001969 JsepSessionDescription* offer =
1970 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1971 ASSERT_TRUE(offer != NULL);
1972 VerifyFingerprintStatus(offer->description(), false);
1973 VerifyNoCryptoParams(offer->description(), false);
1974
1975 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 SetRemoteDescriptionWithoutError(offer);
1977
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001978 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001979 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 ASSERT_TRUE(answer != NULL);
1981 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001982 // Check that we don't have an a=crypto line in the answer.
1983 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001985 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetLocalDescriptionWithoutError(answer);
1987}
1988
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001989// Test that we can create and set an answer correctly when different
1990// SSL roles have been negotiated for different transports.
1991// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1992TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1993 SendAudioVideoStream1();
1994 InitWithDtls(GetParam());
1995 SetFactoryDtlsSrtp();
1996
1997 SessionDescriptionInterface* offer = CreateOffer();
1998 SetLocalDescriptionWithoutError(offer);
1999
2000 cricket::MediaSessionOptions options;
2001 options.recv_video = true;
2002
2003 // First, negotiate different SSL roles.
2004 SessionDescriptionInterface* answer =
2005 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2006 TransportInfo* audio_transport_info =
2007 answer->description()->GetTransportInfoByName("audio");
2008 audio_transport_info->description.connection_role =
2009 cricket::CONNECTIONROLE_ACTIVE;
2010 TransportInfo* video_transport_info =
2011 answer->description()->GetTransportInfoByName("video");
2012 video_transport_info->description.connection_role =
2013 cricket::CONNECTIONROLE_PASSIVE;
2014 SetRemoteDescriptionWithoutError(answer);
2015
2016 // Now create an offer in the reverse direction, and ensure the initial
2017 // offerer responds with an answer with correct SSL roles.
2018 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2019 kSessionVersion,
2020 session_->remote_description());
2021 SetRemoteDescriptionWithoutError(offer);
2022
htaa2a49d92016-03-04 02:51:39 -08002023 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002024 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2025 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2026 audio_transport_info->description.connection_role);
2027 video_transport_info = answer->description()->GetTransportInfoByName("video");
2028 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2029 video_transport_info->description.connection_role);
2030 SetLocalDescriptionWithoutError(answer);
2031
2032 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2033 // audio is transferred over to video in the answer that completes the BUNDLE
2034 // negotiation.
2035 options.bundle_enabled = true;
2036 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2037 kSessionVersion,
2038 session_->remote_description());
2039 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002040 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002041 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2042 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2043 audio_transport_info->description.connection_role);
2044 video_transport_info = answer->description()->GetTransportInfoByName("video");
2045 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2046 video_transport_info->description.connection_role);
2047 SetLocalDescriptionWithoutError(answer);
2048}
2049
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002051 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002052 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002054 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 SetLocalDescriptionWithoutError(offer);
2056
2057 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 SetLocalDescriptionWithoutError(offer2);
2060}
2061
2062TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SetRemoteDescriptionWithoutError(offer);
2068
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002069 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SetRemoteDescriptionWithoutError(offer2);
2071}
2072
2073TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002074 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002079 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2080 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081}
2082
2083TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002084 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002085 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002086 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002088 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002089 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002090 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091}
2092
2093TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002094 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002095 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002097 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098
htaa2a49d92016-03-04 02:51:39 -08002099 JsepSessionDescription* pranswer =
2100 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002102 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
deadbeefab9b2d12015-10-14 11:33:11 -07002104 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002105 JsepSessionDescription* pranswer2 =
2106 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2108
deadbeefd59daf82015-10-14 15:02:44 -07002109 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002112 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002113 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114}
2115
2116TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002117 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002118 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002119 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002120 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121
2122 JsepSessionDescription* pranswer =
2123 CreateRemoteAnswer(session_->local_description());
2124 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2125
2126 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002127 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
deadbeefab9b2d12015-10-14 11:33:11 -07002129 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 JsepSessionDescription* pranswer2 =
2131 CreateRemoteAnswer(session_->local_description());
2132 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2133
2134 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002135 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136
deadbeefab9b2d12015-10-14 11:33:11 -07002137 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 SessionDescriptionInterface* answer =
2139 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002140 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141}
2142
2143TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002144 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002145 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002146 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 SessionDescriptionInterface* answer =
2149 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002150 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2151 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152}
2153
2154TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002156 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002157 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 SessionDescriptionInterface* answer =
2160 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002161 SetRemoteDescriptionAnswerExpectError(
2162 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163}
2164
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002165// Tests that the remote candidates are added and removed successfully.
2166TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002167 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002168 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002170 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2171 "", "", "host", 0, "");
2172 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2174
deadbeefd59daf82015-10-14 15:02:44 -07002175 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2177
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002178 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002180
2181 // Fail since we have not set a remote description.
2182 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
2184 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2185 session_->local_description());
2186 SetRemoteDescriptionWithoutError(answer);
2187
deadbeefd59daf82015-10-14 15:02:44 -07002188 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2189 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002190 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002191 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2192 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 // Verifying the candidates are copied properly from internal vector.
2195 const SessionDescriptionInterface* remote_desc =
2196 session_->remote_description();
2197 ASSERT_TRUE(remote_desc != NULL);
2198 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2199 const IceCandidateCollection* candidates =
2200 remote_desc->candidates(kMediaContentIndex0);
2201 ASSERT_EQ(2u, candidates->count());
2202 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2203 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2204 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2205 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2206
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002207 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2208 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 candidate.set_component(2);
2210 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2211 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002212 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213
2214 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2215 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002216
2217 // Remove candidate1 and candidate2
2218 std::vector<cricket::Candidate> remote_candidates;
2219 remote_candidates.push_back(ice_candidate1.candidate());
2220 remote_candidates.push_back(ice_candidate2.candidate());
2221 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2222 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223}
2224
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002225// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226// that it is retained if the remote session description is changed.
2227TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002228 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 cricket::Candidate candidate1;
2230 candidate1.set_component(1);
2231 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2232 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002233 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 CreateAndSetRemoteOfferAndLocalAnswer();
2235
2236 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2237 const SessionDescriptionInterface* remote_desc =
2238 session_->remote_description();
2239 ASSERT_TRUE(remote_desc != NULL);
2240 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2241 const IceCandidateCollection* candidates =
2242 remote_desc->candidates(kMediaContentIndex0);
2243 ASSERT_EQ(1u, candidates->count());
2244 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2245
2246 // Update the RemoteSessionDescription with a new session description and
2247 // a candidate and check that the new remote session description contains both
2248 // candidates.
2249 SessionDescriptionInterface* offer = CreateRemoteOffer();
2250 cricket::Candidate candidate2;
2251 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2252 candidate2);
2253 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2254 SetRemoteDescriptionWithoutError(offer);
2255
2256 remote_desc = session_->remote_description();
2257 ASSERT_TRUE(remote_desc != NULL);
2258 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2259 candidates = remote_desc->candidates(kMediaContentIndex0);
2260 ASSERT_EQ(2u, candidates->count());
2261 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2262 // Username and password have be updated with the TransportInfo of the
2263 // SessionDescription, won't be equal to the original one.
2264 candidate2.set_username(candidates->at(0)->candidate().username());
2265 candidate2.set_password(candidates->at(0)->candidate().password());
2266 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2267 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2268 // No need to verify the username and password.
2269 candidate1.set_username(candidates->at(1)->candidate().username());
2270 candidate1.set_password(candidates->at(1)->candidate().password());
2271 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2272
2273 // Test that the candidate is ignored if we can add the same candidate again.
2274 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2275}
2276
2277// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002278// that they are retained if the local session description is changed. And if
2279// continual gathering is enabled, they are removed from the local session
2280// description when the network is down.
2281TEST_F(WebRtcSessionTest,
2282 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002283 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002284 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002285 // Enable Continual Gathering.
2286 cricket::IceConfig config;
2287 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2288 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002289 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 CreateAndSetRemoteOfferAndLocalAnswer();
2291
2292 const SessionDescriptionInterface* local_desc = session_->local_description();
2293 const IceCandidateCollection* candidates =
2294 local_desc->candidates(kMediaContentIndex0);
2295 ASSERT_TRUE(candidates != NULL);
2296 EXPECT_EQ(0u, candidates->count());
2297
deadbeefb60a8192016-08-24 15:15:00 -07002298 // Since we're using continual gathering, we won't get "gathering done".
2299 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300
2301 local_desc = session_->local_description();
2302 candidates = local_desc->candidates(kMediaContentIndex0);
2303 ASSERT_TRUE(candidates != NULL);
2304 EXPECT_LT(0u, candidates->count());
2305 candidates = local_desc->candidates(1);
2306 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002307 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308
2309 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002310 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 CreateAndSetRemoteOfferAndLocalAnswer();
2312
2313 local_desc = session_->local_description();
2314 candidates = local_desc->candidates(kMediaContentIndex0);
2315 ASSERT_TRUE(candidates != NULL);
2316 EXPECT_LT(0u, candidates->count());
2317 candidates = local_desc->candidates(1);
2318 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002319 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002320
2321 candidates = local_desc->candidates(kMediaContentIndex0);
2322 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002323 // Bring down the network interface to trigger candidate removals.
2324 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2325 // Verify that all local candidates are removed.
2326 EXPECT_EQ(0, observer_.num_candidates_removed_);
2327 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2328 kIceCandidatesTimeout);
2329 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2330}
2331
2332// Tests that if continual gathering is disabled, local candidates won't be
2333// removed when the interface is turned down.
2334TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2335 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2336 Init();
2337 SendAudioVideoStream1();
2338 CreateAndSetRemoteOfferAndLocalAnswer();
2339
2340 const SessionDescriptionInterface* local_desc = session_->local_description();
2341 const IceCandidateCollection* candidates =
2342 local_desc->candidates(kMediaContentIndex0);
2343 ASSERT_TRUE(candidates != NULL);
2344 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2345
2346 size_t num_local_candidates = candidates->count();
2347 EXPECT_LT(0u, num_local_candidates);
2348 // By default, Continual Gathering is disabled.
2349 // Bring down the network interface.
2350 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2351 // Verify that the local candidates are not removed.
2352 rtc::Thread::Current()->ProcessMessages(1000);
2353 EXPECT_EQ(0, observer_.num_candidates_removed_);
2354 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355}
2356
2357// Test that we can set a remote session description with remote candidates.
2358TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002359 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360
2361 cricket::Candidate candidate1;
2362 candidate1.set_component(1);
2363 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2364 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002365 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002366 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367
2368 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2369 SetRemoteDescriptionWithoutError(offer);
2370
2371 const SessionDescriptionInterface* remote_desc =
2372 session_->remote_description();
2373 ASSERT_TRUE(remote_desc != NULL);
2374 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2375 const IceCandidateCollection* candidates =
2376 remote_desc->candidates(kMediaContentIndex0);
2377 ASSERT_EQ(1u, candidates->count());
2378 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2379
htaa2a49d92016-03-04 02:51:39 -08002380 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 SetLocalDescriptionWithoutError(answer);
2382}
2383
2384// Test that offers and answers contains ice candidates when Ice candidates have
2385// been gathered.
2386TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002387 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002388 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002389 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 // Ice is started but candidates are not provided until SetLocalDescription
2391 // is called.
2392 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2393 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2394 CreateAndSetRemoteOfferAndLocalAnswer();
2395 // Wait until at least one local candidate has been collected.
2396 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2397 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
kwibergd1fe2812016-04-27 06:47:29 -07002399 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2402 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403
2404 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2405 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002406 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2408 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 SetLocalDescriptionWithoutError(answer);
2410}
2411
2412// Verifies TransportProxy and media channels are created with content names
2413// present in the SessionDescription.
2414TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002415 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002416 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002417 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418
2419 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002420 // "video". Goal is to modify these content names and verify transport
2421 // channels
2422 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 // present in SDP.
2424 std::string sdp;
2425 EXPECT_TRUE(offer->ToString(&sdp));
2426 const std::string kAudioMid = "a=mid:audio";
2427 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2428 const std::string kVideoMid = "a=mid:video";
2429 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2430
2431 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002432 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 kAudioMidReplaceStr.c_str(),
2434 kAudioMidReplaceStr.length(),
2435 &sdp);
2436 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002437 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 kVideoMidReplaceStr.c_str(),
2439 kVideoMidReplaceStr.length(),
2440 &sdp);
2441
2442 SessionDescriptionInterface* modified_offer =
2443 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2444
2445 SetRemoteDescriptionWithoutError(modified_offer);
2446
htaa2a49d92016-03-04 02:51:39 -08002447 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 SetLocalDescriptionWithoutError(answer);
2449
deadbeef5bd5ca32017-02-10 11:31:50 -08002450 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002451 session_->voice_rtp_transport_channel();
2452 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002453 EXPECT_EQ(voice_transport_channel->debug_name(),
2454 "audio_content_name " +
2455 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002456 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002457 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002458 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002459 EXPECT_EQ(video_transport_channel->debug_name(),
2460 "video_content_name " +
2461 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2463 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2464}
2465
2466// Test that an offer contains the correct media content descriptions based on
2467// the send streams when no constraints have been set.
2468TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002469 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002470 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 ASSERT_TRUE(offer != NULL);
2473 const cricket::ContentInfo* content =
2474 cricket::GetFirstAudioContent(offer->description());
2475 EXPECT_TRUE(content != NULL);
2476 content = cricket::GetFirstVideoContent(offer->description());
2477 EXPECT_TRUE(content == NULL);
2478}
2479
2480// Test that an offer contains the correct media content descriptions based on
2481// the send streams when no constraints have been set.
2482TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002483 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002485 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002486 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002487
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488 const cricket::ContentInfo* content =
2489 cricket::GetFirstAudioContent(offer->description());
2490 EXPECT_TRUE(content != NULL);
2491 content = cricket::GetFirstVideoContent(offer->description());
2492 EXPECT_TRUE(content == NULL);
2493
2494 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002495 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002496 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 content = cricket::GetFirstAudioContent(offer->description());
2498 EXPECT_TRUE(content != NULL);
2499 content = cricket::GetFirstVideoContent(offer->description());
2500 EXPECT_TRUE(content != NULL);
2501}
2502
2503// Test that an offer contains no media content descriptions if
2504// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2505TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002506 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002507 PeerConnectionInterface::RTCOfferAnswerOptions options;
2508 options.offer_to_receive_audio = 0;
2509 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510
kwibergd1fe2812016-04-27 06:47:29 -07002511 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002512
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 ASSERT_TRUE(offer != NULL);
2514 const cricket::ContentInfo* content =
2515 cricket::GetFirstAudioContent(offer->description());
2516 EXPECT_TRUE(content == NULL);
2517 content = cricket::GetFirstVideoContent(offer->description());
2518 EXPECT_TRUE(content == NULL);
2519}
2520
2521// Test that an offer contains only audio media content descriptions if
2522// kOfferToReceiveAudio constraints are set to true.
2523TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002524 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002525 PeerConnectionInterface::RTCOfferAnswerOptions options;
2526 options.offer_to_receive_audio =
2527 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2528
kwibergd1fe2812016-04-27 06:47:29 -07002529 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530
2531 const cricket::ContentInfo* content =
2532 cricket::GetFirstAudioContent(offer->description());
2533 EXPECT_TRUE(content != NULL);
2534 content = cricket::GetFirstVideoContent(offer->description());
2535 EXPECT_TRUE(content == NULL);
2536}
2537
2538// Test that an offer contains audio and video media content descriptions if
2539// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2540TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002541 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002543 PeerConnectionInterface::RTCOfferAnswerOptions options;
2544 options.offer_to_receive_audio =
2545 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2546 options.offer_to_receive_video =
2547 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2548
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002550
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 const cricket::ContentInfo* content =
2552 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002553 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 content = cricket::GetFirstVideoContent(offer->description());
2556 EXPECT_TRUE(content != NULL);
2557
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002558 // Sets constraints to false and verifies that audio/video contents are
2559 // removed.
2560 options.offer_to_receive_audio = 0;
2561 options.offer_to_receive_video = 0;
2562 offer.reset(CreateOffer(options));
2563
2564 content = cricket::GetFirstAudioContent(offer->description());
2565 EXPECT_TRUE(content == NULL);
2566 content = cricket::GetFirstVideoContent(offer->description());
2567 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568}
2569
2570// Test that an answer can not be created if the last remote description is not
2571// an offer.
2572TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002573 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002574 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 SetLocalDescriptionWithoutError(offer);
2576 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2577 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002578 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579}
2580
2581// Test that an answer contains the correct media content descriptions when no
2582// constraints have been set.
2583TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002586 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002588 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 const cricket::ContentInfo* content =
2590 cricket::GetFirstAudioContent(answer->description());
2591 ASSERT_TRUE(content != NULL);
2592 EXPECT_FALSE(content->rejected);
2593
2594 content = cricket::GetFirstVideoContent(answer->description());
2595 ASSERT_TRUE(content != NULL);
2596 EXPECT_FALSE(content->rejected);
2597}
2598
2599// Test that an answer contains the correct media content descriptions when no
2600// constraints have been set and the offer only contain audio.
2601TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002602 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603 // Create a remote offer with audio only.
2604 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002605
kwibergd1fe2812016-04-27 06:47:29 -07002606 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2608 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2609
2610 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002611 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 const cricket::ContentInfo* content =
2613 cricket::GetFirstAudioContent(answer->description());
2614 ASSERT_TRUE(content != NULL);
2615 EXPECT_FALSE(content->rejected);
2616
2617 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2618}
2619
2620// Test that an answer contains the correct media content descriptions when no
2621// constraints have been set.
2622TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002623 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002625 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 SetRemoteDescriptionWithoutError(offer.release());
2627 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002628 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002629 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 const cricket::ContentInfo* content =
2631 cricket::GetFirstAudioContent(answer->description());
2632 ASSERT_TRUE(content != NULL);
2633 EXPECT_FALSE(content->rejected);
2634
2635 content = cricket::GetFirstVideoContent(answer->description());
2636 ASSERT_TRUE(content != NULL);
2637 EXPECT_FALSE(content->rejected);
2638}
2639
2640// Test that an answer contains the correct media content descriptions when
2641// constraints have been set but no stream is sent.
2642TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002643 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002645 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 SetRemoteDescriptionWithoutError(offer.release());
2647
htaa2a49d92016-03-04 02:51:39 -08002648 cricket::MediaSessionOptions session_options;
2649 session_options.recv_audio = false;
2650 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002651 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002652 CreateAnswer(session_options));
2653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 const cricket::ContentInfo* content =
2655 cricket::GetFirstAudioContent(answer->description());
2656 ASSERT_TRUE(content != NULL);
2657 EXPECT_TRUE(content->rejected);
2658
2659 content = cricket::GetFirstVideoContent(answer->description());
2660 ASSERT_TRUE(content != NULL);
2661 EXPECT_TRUE(content->rejected);
2662}
2663
2664// Test that an answer contains the correct media content descriptions when
2665// constraints have been set and streams are sent.
2666TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002667 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002669 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 SetRemoteDescriptionWithoutError(offer.release());
2671
htaa2a49d92016-03-04 02:51:39 -08002672 cricket::MediaSessionOptions options;
2673 options.recv_audio = false;
2674 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002675
2676 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002677 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002678 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679
2680 // TODO(perkj): Should the direction be set to SEND_ONLY?
2681 const cricket::ContentInfo* content =
2682 cricket::GetFirstAudioContent(answer->description());
2683 ASSERT_TRUE(content != NULL);
2684 EXPECT_FALSE(content->rejected);
2685
2686 // TODO(perkj): Should the direction be set to SEND_ONLY?
2687 content = cricket::GetFirstVideoContent(answer->description());
2688 ASSERT_TRUE(content != NULL);
2689 EXPECT_FALSE(content->rejected);
2690}
2691
2692TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2693 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002694 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002695 PeerConnectionInterface::RTCOfferAnswerOptions options;
2696 options.offer_to_receive_audio =
2697 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2698 options.voice_activity_detection = false;
2699
kwibergd1fe2812016-04-27 06:47:29 -07002700 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002701
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 const cricket::ContentInfo* content =
2703 cricket::GetFirstAudioContent(offer->description());
2704 EXPECT_TRUE(content != NULL);
2705 EXPECT_TRUE(VerifyNoCNCodecs(content));
2706}
2707
2708TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2709 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002710 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002712 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 SetRemoteDescriptionWithoutError(offer.release());
2714
htaa2a49d92016-03-04 02:51:39 -08002715 cricket::MediaSessionOptions options;
2716 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002717 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 const cricket::ContentInfo* content =
2719 cricket::GetFirstAudioContent(answer->description());
2720 ASSERT_TRUE(content != NULL);
2721 EXPECT_TRUE(VerifyNoCNCodecs(content));
2722}
2723
2724// This test verifies the call setup when remote answer with audio only and
2725// later updates with video.
2726TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002727 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2729 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2730
deadbeefab9b2d12015-10-14 11:33:11 -07002731 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002732 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733
2734 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2736
2737 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2738 // and answer;
2739 SetLocalDescriptionWithoutError(offer);
2740 SetRemoteDescriptionWithoutError(answer);
2741
2742 video_channel_ = media_engine_->GetVideoChannel(0);
2743 voice_channel_ = media_engine_->GetVoiceChannel(0);
2744
2745 ASSERT_TRUE(video_channel_ == NULL);
2746
2747 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2748 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2749 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2750
2751 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002752 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753 CreateAndSetRemoteOfferAndLocalAnswer();
2754
2755 video_channel_ = media_engine_->GetVideoChannel(0);
2756 voice_channel_ = media_engine_->GetVoiceChannel(0);
2757
2758 ASSERT_TRUE(video_channel_ != NULL);
2759 ASSERT_TRUE(voice_channel_ != NULL);
2760
2761 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2762 ASSERT_EQ(1u, video_channel_->send_streams().size());
2763 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2764 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2765 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2766 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2767 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2768 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2769
2770 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002771 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 CreateAndSetRemoteOfferAndLocalAnswer();
2773
2774 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2775 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2776 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2777 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2778 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2779}
2780
2781// This test verifies the call setup when remote answer with video only and
2782// later updates with audio.
2783TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2786 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002787 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002788 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002789
2790 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002791 options.recv_audio = false;
2792 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2794 offer, options, cricket::SEC_ENABLED);
2795
2796 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2797 // and answer.
2798 SetLocalDescriptionWithoutError(offer);
2799 SetRemoteDescriptionWithoutError(answer);
2800
2801 video_channel_ = media_engine_->GetVideoChannel(0);
2802 voice_channel_ = media_engine_->GetVoiceChannel(0);
2803
2804 ASSERT_TRUE(voice_channel_ == NULL);
2805 ASSERT_TRUE(video_channel_ != NULL);
2806
2807 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2808 ASSERT_EQ(1u, video_channel_->send_streams().size());
2809 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2810
2811 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002812 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 CreateAndSetRemoteOfferAndLocalAnswer();
2814
2815 voice_channel_ = media_engine_->GetVoiceChannel(0);
2816 ASSERT_TRUE(voice_channel_ != NULL);
2817
2818 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2819 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2820 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2821 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2822
2823 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002824 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002825 CreateAndSetRemoteOfferAndLocalAnswer();
2826
2827 video_channel_ = media_engine_->GetVideoChannel(0);
2828 voice_channel_ = media_engine_->GetVoiceChannel(0);
2829
2830 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2831 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2832 ASSERT_EQ(1u, video_channel_->send_streams().size());
2833 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2834}
2835
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002837 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002838 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002839 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 VerifyCryptoParams(offer->description());
2841 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002842 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 VerifyCryptoParams(answer->description());
2844}
2845
jbauchcb560652016-08-04 05:20:32 -07002846TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2847 InitWithGcm();
2848 SendAudioVideoStream1();
2849 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2850 VerifyCryptoParams(offer->description(), true);
2851 SetRemoteDescriptionWithoutError(offer.release());
2852 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2853 VerifyCryptoParams(answer->description(), true);
2854}
2855
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002857 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002858 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002859 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002860 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861 VerifyNoCryptoParams(offer->description(), false);
2862}
2863
2864TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002865 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 VerifyAnswerFromNonCryptoOffer();
2867}
2868
2869TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002870 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871 VerifyAnswerFromCryptoOffer();
2872}
2873
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002874// This test verifies that setLocalDescription fails if
2875// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2876TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002877 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002878 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002880
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002881 std::string sdp;
2882 RemoveIceUfragPwdLines(offer.get(), &sdp);
2883 SessionDescriptionInterface* modified_offer =
2884 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002885 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002886}
2887
2888// This test verifies that setRemoteDescription fails if
2889// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2890TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002891 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002892 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002893 std::string sdp;
2894 RemoveIceUfragPwdLines(offer.get(), &sdp);
2895 SessionDescriptionInterface* modified_offer =
2896 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002897 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002898}
2899
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002900// This test verifies that setLocalDescription fails if local offer has
2901// too short ice ufrag and pwd strings.
2902TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002903 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002904 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002905 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002906 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2907 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002908 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002909 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002910 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002911
2912 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002913 offer.reset(CreateOffer());
2914 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2915 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002916}
2917
2918// This test verifies that setRemoteDescription fails if remote offer has
2919// too short ice ufrag and pwd strings.
2920TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002921 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002922 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002923 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2924 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002925 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002926 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002927 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002928
deadbeef0ed85b22016-02-23 17:24:52 -08002929 offer.reset(CreateRemoteOffer());
2930 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2931 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002932}
2933
Honghai Zhang04e91462015-12-11 14:26:22 -08002934// Test that if the remote offer indicates the peer requested ICE restart (via
2935// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2936TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002937 Init();
honghaiz503726c2015-07-31 12:37:38 -07002938
2939 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002940 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002941 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002942 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2943 0, "", "", "relay", 0, "");
2944 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2945 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002946 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2947 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002948 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2949
2950 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002951 offer.reset(CreateRemoteOffer());
2952 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002953 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2954 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2955 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002956 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2957 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002958 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2959
2960 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002961 offer.reset(CreateRemoteOffer());
2962 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002963 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2964 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2965 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002966 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2967 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002968 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2969
2970 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002971 offer.reset(CreateRemoteOffer());
2972 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2973 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002974 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2975}
2976
Honghai Zhang04e91462015-12-11 14:26:22 -08002977// Test that if the remote answer indicates the peer requested ICE restart (via
2978// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2979TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2980 Init();
2981 SessionDescriptionInterface* offer = CreateOffer();
2982 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002983
2984 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002985 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002986 answer->set_type(JsepSessionDescription::kPrAnswer);
2987 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002988 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2989 0, "", "", "relay", 0, "");
2990 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2991 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002992 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2993 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002994 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2995
2996 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002997 answer.reset(CreateRemoteAnswer(offer));
2998 answer->set_type(JsepSessionDescription::kPrAnswer);
2999 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003000 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3001 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3002 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003003 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3004 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003005 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3006
3007 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003008 answer.reset(CreateRemoteAnswer(offer));
3009 answer->set_type(JsepSessionDescription::kPrAnswer);
3010 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003011 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3012 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3013 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003014 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3015 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003016 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3017
3018 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003019 answer.reset(CreateRemoteAnswer(offer));
3020 answer->set_type(JsepSessionDescription::kPrAnswer);
3021 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3022 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003023 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3024}
3025
Donald Curtisd4f769d2015-05-28 09:48:21 -07003026// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003027// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003028TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3029 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3030
3031 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003032 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003033
3034 PeerConnectionInterface::RTCOfferAnswerOptions options;
3035 options.use_rtp_mux = true;
3036
3037 SessionDescriptionInterface* offer = CreateRemoteOffer();
3038 SetRemoteDescriptionWithoutError(offer);
3039
htaa2a49d92016-03-04 02:51:39 -08003040 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003041 SetLocalDescriptionWithoutError(answer);
3042
deadbeefcbecd352015-09-23 11:50:27 -07003043 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3044 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003045
deadbeefcbecd352015-09-23 11:50:27 -07003046 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003047 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003048
3049 // Checks if one of the transport channels contains a connection using a given
3050 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003051 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003052 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3053 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003054 for (auto& chan_stat : kv.second.channel_stats) {
3055 for (auto& conn_info : chan_stat.connection_infos) {
3056 if (conn_info.remote_candidate.address().port() == port) {
3057 return true;
3058 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003059 }
3060 }
3061 }
3062 return false;
3063 };
3064
3065 EXPECT_FALSE(connection_with_remote_port(5000));
3066 EXPECT_FALSE(connection_with_remote_port(5001));
3067 EXPECT_FALSE(connection_with_remote_port(6000));
3068
3069 // The way the *_WAIT checks work is they only wait if the condition fails,
3070 // which does not help in the case where state is not changing. This is
3071 // problematic in this test since we want to verify that adding a video
3072 // candidate does _not_ change state. So we interleave candidates and assume
3073 // that messages are executed in the order they were posted.
3074
3075 // First audio candidate.
3076 cricket::Candidate candidate0;
3077 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3078 candidate0.set_component(1);
3079 candidate0.set_protocol("udp");
3080 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3081 candidate0);
3082 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3083
3084 // Video candidate.
3085 cricket::Candidate candidate1;
3086 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3087 candidate1.set_component(1);
3088 candidate1.set_protocol("udp");
3089 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3090 candidate1);
3091 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3092
3093 // Second audio candidate.
3094 cricket::Candidate candidate2;
3095 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3096 candidate2.set_component(1);
3097 candidate2.set_protocol("udp");
3098 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3099 candidate2);
3100 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3101
3102 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3103 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3104
3105 // No need here for a _WAIT check since we are checking that state hasn't
3106 // changed: if this is false we would be doing waits for nothing and if this
3107 // is true then there will be no messages processed anyways.
3108 EXPECT_FALSE(connection_with_remote_port(6000));
3109}
3110
deadbeefcbecd352015-09-23 11:50:27 -07003111// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003112TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3113 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003114 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003115
3116 PeerConnectionInterface::RTCOfferAnswerOptions options;
3117 options.use_rtp_mux = true;
3118
3119 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003121
deadbeefcbecd352015-09-23 11:50:27 -07003122 EXPECT_NE(session_->voice_rtp_transport_channel(),
3123 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003124
deadbeefab9b2d12015-10-14 11:33:11 -07003125 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003126 SessionDescriptionInterface* answer =
3127 CreateRemoteAnswer(session_->local_description());
3128 SetRemoteDescriptionWithoutError(answer);
3129
deadbeefcbecd352015-09-23 11:50:27 -07003130 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3131 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003132}
3133
deadbeefcbecd352015-09-23 11:50:27 -07003134// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003135TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3136 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003137 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003138
Donald Curtis0e209b02015-03-24 09:29:54 -07003139 PeerConnectionInterface::RTCOfferAnswerOptions options;
3140 options.use_rtp_mux = true;
3141
3142 SessionDescriptionInterface* offer = CreateOffer(options);
3143 SetLocalDescriptionWithoutError(offer);
3144
deadbeefcbecd352015-09-23 11:50:27 -07003145 EXPECT_NE(session_->voice_rtp_transport_channel(),
3146 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003147
deadbeefab9b2d12015-10-14 11:33:11 -07003148 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003149
3150 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003151 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003152 CreateRemoteAnswer(session_->local_description()));
3153 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3154 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3155 JsepSessionDescription* modified_answer =
3156 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3157 modified_answer->Initialize(answer_copy, "1", "1");
3158 SetRemoteDescriptionWithoutError(modified_answer); //
3159
deadbeefcbecd352015-09-23 11:50:27 -07003160 EXPECT_NE(session_->voice_rtp_transport_channel(),
3161 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003162}
3163
3164// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3165TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3166 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003167 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003168
3169 PeerConnectionInterface::RTCOfferAnswerOptions options;
3170 options.use_rtp_mux = true;
3171
3172 SessionDescriptionInterface* offer = CreateOffer(options);
3173 SetLocalDescriptionWithoutError(offer);
3174
deadbeefcbecd352015-09-23 11:50:27 -07003175 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3176 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003177
deadbeefab9b2d12015-10-14 11:33:11 -07003178 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003179 SessionDescriptionInterface* answer =
3180 CreateRemoteAnswer(session_->local_description());
3181 SetRemoteDescriptionWithoutError(answer);
3182
deadbeefcbecd352015-09-23 11:50:27 -07003183 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3184 session_->video_rtp_transport_channel());
3185}
3186
3187// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3188// audio content in the answer.
3189TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3190 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003191 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003192
3193 PeerConnectionInterface::RTCOfferAnswerOptions options;
3194 options.use_rtp_mux = true;
3195
3196 SessionDescriptionInterface* offer = CreateOffer(options);
3197 SetLocalDescriptionWithoutError(offer);
3198
3199 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3200 session_->video_rtp_transport_channel());
3201
deadbeefab9b2d12015-10-14 11:33:11 -07003202 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003203 cricket::MediaSessionOptions recv_options;
3204 recv_options.recv_audio = false;
3205 recv_options.recv_video = true;
3206 SessionDescriptionInterface* answer =
3207 CreateRemoteAnswer(session_->local_description(), recv_options);
3208 SetRemoteDescriptionWithoutError(answer);
3209
deadbeefd59daf82015-10-14 15:02:44 -07003210 EXPECT_TRUE(nullptr == session_->voice_channel());
3211 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003212
deadbeefd59daf82015-10-14 15:02:44 -07003213 session_->Close();
3214 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3215 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3216 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3217 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003218}
3219
3220// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3221TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3222 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003223 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003224
Donald Curtis0e209b02015-03-24 09:29:54 -07003225 PeerConnectionInterface::RTCOfferAnswerOptions options;
3226 options.use_rtp_mux = true;
3227
3228 SessionDescriptionInterface* offer = CreateOffer(options);
3229 SetLocalDescriptionWithoutError(offer);
3230
deadbeefcbecd352015-09-23 11:50:27 -07003231 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3232 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003233
deadbeefab9b2d12015-10-14 11:33:11 -07003234 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003235
3236 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003237 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 CreateRemoteAnswer(session_->local_description()));
3239 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3240 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3241 JsepSessionDescription* modified_answer =
3242 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3243 modified_answer->Initialize(answer_copy, "1", "1");
3244 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245
deadbeefcbecd352015-09-23 11:50:27 -07003246 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3247 session_->video_rtp_transport_channel());
3248}
3249
3250// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3251TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3252 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003253 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003254
3255 SessionDescriptionInterface* offer = CreateRemoteOffer();
3256 SetRemoteDescriptionWithoutError(offer);
3257
3258 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3259 session_->video_rtp_transport_channel());
3260
deadbeefab9b2d12015-10-14 11:33:11 -07003261 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003262 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003263 SetLocalDescriptionWithoutError(answer);
3264
3265 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3266 session_->video_rtp_transport_channel());
3267}
3268
3269// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3270TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003273
3274 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003275 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003276 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3277 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3278 JsepSessionDescription* modified_offer =
3279 new JsepSessionDescription(JsepSessionDescription::kOffer);
3280 modified_offer->Initialize(offer_copy, "1", "1");
3281
3282 // Expect an error when applying the remote description
3283 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3284 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003285}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003286
Peter Thatcher4eddf182015-04-30 10:55:59 -07003287// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003288TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3289 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
Donald Curtis0e209b02015-03-24 09:29:54 -07003292 PeerConnectionInterface::RTCOfferAnswerOptions options;
3293 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294
Donald Curtis0e209b02015-03-24 09:29:54 -07003295 SessionDescriptionInterface* offer = CreateOffer(options);
3296 SetLocalDescriptionWithoutError(offer);
3297
deadbeefcbecd352015-09-23 11:50:27 -07003298 EXPECT_NE(session_->voice_rtp_transport_channel(),
3299 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003300
deadbeefab9b2d12015-10-14 11:33:11 -07003301 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003302 SessionDescriptionInterface* answer =
3303 CreateRemoteAnswer(session_->local_description());
3304 SetRemoteDescriptionWithoutError(answer);
3305
3306 // This should lead to an audio-only call but isn't implemented
3307 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003308 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3309 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003310}
3311
deadbeefcbecd352015-09-23 11:50:27 -07003312// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003313TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3314 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003315 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003316 PeerConnectionInterface::RTCOfferAnswerOptions options;
3317 options.use_rtp_mux = true;
3318
3319 SessionDescriptionInterface* offer = CreateOffer(options);
3320 SetLocalDescriptionWithoutError(offer);
3321
deadbeefcbecd352015-09-23 11:50:27 -07003322 EXPECT_NE(session_->voice_rtp_transport_channel(),
3323 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003324
deadbeefab9b2d12015-10-14 11:33:11 -07003325 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003326
3327 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003328 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003329 CreateRemoteAnswer(session_->local_description()));
3330 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3331 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3332 JsepSessionDescription* modified_answer =
3333 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3334 modified_answer->Initialize(answer_copy, "1", "1");
3335 SetRemoteDescriptionWithoutError(modified_answer); //
3336
deadbeefcbecd352015-09-23 11:50:27 -07003337 EXPECT_NE(session_->voice_rtp_transport_channel(),
3338 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339}
3340
Peter Thatcher4eddf182015-04-30 10:55:59 -07003341// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3342TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3343 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003344 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003345
3346 PeerConnectionInterface::RTCOfferAnswerOptions options;
3347 options.use_rtp_mux = true;
3348
3349 SessionDescriptionInterface* offer = CreateOffer(options);
3350 SetRemoteDescriptionWithoutError(offer);
3351
deadbeefcbecd352015-09-23 11:50:27 -07003352 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3353 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003354}
3355
skvlad6c87a672016-05-17 17:49:52 -07003356// Adding a new channel to a BUNDLE which is already connected should directly
3357// assign the bundle transport to the channel, without first setting a
3358// disconnected non-bundle transport and then replacing it. The application
3359// should not receive any changes in the ICE state.
3360TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3361 LoopbackNetworkConfiguration config;
3362 LoopbackNetworkManager loopback_network_manager(this, config);
3363 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3364 // connected. Disabling either of these two means that we need to wait for the
3365 // answer to find out if more transports are needed.
3366 configuration_.bundle_policy =
3367 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003368 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003369 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003370
3371 // Negotiate an audio channel with MAX_BUNDLE enabled.
3372 SendAudioOnlyStream2();
3373 SessionDescriptionInterface* offer = CreateOffer();
3374 SetLocalDescriptionWithoutError(offer);
3375 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3376 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3377 std::string sdp;
3378 offer->ToString(&sdp);
3379 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3380 JsepSessionDescription::kAnswer, sdp, nullptr);
3381 ASSERT_TRUE(answer != NULL);
3382 SetRemoteDescriptionWithoutError(answer);
3383
3384 // Wait for the ICE state to stabilize.
3385 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3386 observer_.ice_connection_state_, kIceCandidatesTimeout);
3387 observer_.ice_connection_state_history_.clear();
3388
3389 // Now add a video channel which should be using the same bundle transport.
3390 SendAudioVideoStream2();
3391 offer = CreateOffer();
3392 offer->ToString(&sdp);
3393 SetLocalDescriptionWithoutError(offer);
3394 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3395 sdp, nullptr);
3396 ASSERT_TRUE(answer != NULL);
3397 SetRemoteDescriptionWithoutError(answer);
3398
3399 // Wait for ICE state to stabilize
3400 rtc::Thread::Current()->ProcessMessages(0);
3401 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3402 observer_.ice_connection_state_, kIceCandidatesTimeout);
3403
3404 // No ICE state changes are expected to happen.
3405 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3406}
3407
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3409 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003410 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003411
3412 PeerConnectionInterface::RTCOfferAnswerOptions options;
3413 SessionDescriptionInterface* offer = CreateOffer(options);
3414 SetLocalDescriptionWithoutError(offer);
3415
deadbeefcbecd352015-09-23 11:50:27 -07003416 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3417 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003418
deadbeefab9b2d12015-10-14 11:33:11 -07003419 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003420 SessionDescriptionInterface* answer =
3421 CreateRemoteAnswer(session_->local_description());
3422 SetRemoteDescriptionWithoutError(answer);
3423
deadbeefcbecd352015-09-23 11:50:27 -07003424 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3425 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003426}
3427
3428TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3429 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003430 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003431
3432 PeerConnectionInterface::RTCOfferAnswerOptions options;
3433 SessionDescriptionInterface* offer = CreateOffer(options);
3434 SetLocalDescriptionWithoutError(offer);
3435
deadbeefcbecd352015-09-23 11:50:27 -07003436 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3437 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003438
deadbeefab9b2d12015-10-14 11:33:11 -07003439 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003440 SessionDescriptionInterface* answer =
3441 CreateRemoteAnswer(session_->local_description());
3442 SetRemoteDescriptionWithoutError(answer);
3443
deadbeefcbecd352015-09-23 11:50:27 -07003444 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3445 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003446}
3447
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003448// This test verifies that SetLocalDescription and SetRemoteDescription fails
3449// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3450TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003451 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003452 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003453
3454 PeerConnectionInterface::RTCOfferAnswerOptions options;
3455 options.use_rtp_mux = true;
3456
3457 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003458 std::string offer_str;
3459 offer->ToString(&offer_str);
3460 // Disable rtcp-mux
3461 const std::string rtcp_mux = "rtcp-mux";
3462 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003463 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003464 xrtcp_mux.c_str(), xrtcp_mux.length(),
3465 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003466 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003467 new JsepSessionDescription(JsepSessionDescription::kOffer);
3468 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003469 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003470 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003471 new JsepSessionDescription(JsepSessionDescription::kOffer);
3472 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003473 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003474 // Trying unmodified SDP.
3475 SetLocalDescriptionWithoutError(offer);
3476}
3477
jbauchcb560652016-08-04 05:20:32 -07003478TEST_F(WebRtcSessionTest, SetSetupGcm) {
3479 InitWithGcm();
3480 SendAudioVideoStream1();
3481 CreateAndSetRemoteOfferAndLocalAnswer();
3482}
3483
deadbeefd59daf82015-10-14 15:02:44 -07003484// This test verifies the |initial_offerer| flag when session initiates the
3485// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003487 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003488 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003489 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3491 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003492 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003494 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495}
3496
deadbeefd59daf82015-10-14 15:02:44 -07003497// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003499 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003500 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 SessionDescriptionInterface* offer = CreateRemoteOffer();
3502 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003503 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003507 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508}
3509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3511TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003512 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003513 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003514 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003516 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 CreateRemoteAnswer(session_->local_description()));
3518
3519 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3520 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003521 JsepSessionDescription* modified_answer =
3522 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523
3524 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3525 answer->session_id(),
3526 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003527 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
wu@webrtc.org4e393072014-04-07 17:04:35 +00003529 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 std::string sdp;
3531 EXPECT_TRUE(answer->ToString(&sdp));
3532 const std::string kAudioMid = "a=mid:audio";
3533 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003534 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 kAudioMidReplaceStr.c_str(),
3536 kAudioMidReplaceStr.length(),
3537 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003538 SessionDescriptionInterface* modified_answer1 =
3539 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003540 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541
wu@webrtc.org4e393072014-04-07 17:04:35 +00003542 // Different media types.
3543 EXPECT_TRUE(answer->ToString(&sdp));
3544 const std::string kAudioMline = "m=audio";
3545 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003546 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003547 kAudioMlineReplaceStr.c_str(),
3548 kAudioMlineReplaceStr.length(),
3549 &sdp);
3550 SessionDescriptionInterface* modified_answer2 =
3551 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3552 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3553
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 SetRemoteDescriptionWithoutError(answer.release());
3555}
3556
3557// Verifying remote offer and local answer have matching m-lines as per
3558// RFC 3264.
3559TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003560 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003561 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562 SessionDescriptionInterface* offer = CreateRemoteOffer();
3563 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003564 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565
3566 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3567 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003568 JsepSessionDescription* modified_answer =
3569 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570
3571 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3572 answer->session_id(),
3573 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003574 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 SetLocalDescriptionWithoutError(answer);
3576}
3577
3578// This test verifies that WebRtcSession does not start candidate allocation
3579// before SetLocalDescription is called.
3580TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003581 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003582 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003583 SessionDescriptionInterface* offer = CreateRemoteOffer();
3584 cricket::Candidate candidate;
3585 candidate.set_component(1);
3586 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3587 candidate);
3588 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3589 cricket::Candidate candidate1;
3590 candidate1.set_component(1);
3591 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3592 candidate1);
3593 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3594 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003595 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3596 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597
3598 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003599 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3601 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3602
htaa2a49d92016-03-04 02:51:39 -08003603 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003604 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3606}
3607
3608// This test verifies that crypto parameter is updated in local session
3609// description as per security policy set in MediaSessionDescriptionFactory.
3610TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003611 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003612 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003613 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
3615 // Making sure SetLocalDescription correctly sets crypto value in
3616 // SessionDescription object after de-serialization of sdp string. The value
3617 // will be set as per MediaSessionDescriptionFactory.
3618 std::string offer_str;
3619 offer->ToString(&offer_str);
3620 SessionDescriptionInterface* jsep_offer_str =
3621 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3622 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003623 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3624 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625}
3626
3627// This test verifies the crypto parameter when security is disabled.
3628TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003629 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003632 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003633
3634 // Making sure SetLocalDescription correctly sets crypto value in
3635 // SessionDescription object after de-serialization of sdp string. The value
3636 // will be set as per MediaSessionDescriptionFactory.
3637 std::string offer_str;
3638 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003639 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3641 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003642 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3643 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003644}
3645
3646// This test verifies that an answer contains new ufrag and password if an offer
3647// with new ufrag and password is received.
3648TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003651 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003652 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 SetRemoteDescriptionWithoutError(offer.release());
3654
deadbeefab9b2d12015-10-14 11:33:11 -07003655 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003656 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003657 SetLocalDescriptionWithoutError(answer.release());
3658
3659 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003660 for (const cricket::ContentInfo& content :
3661 session_->local_description()->description()->contents()) {
3662 options.transport_options[content.name].ice_restart = true;
3663 }
kwibergd1fe2812016-04-27 06:47:29 -07003664 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003665 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666 SetRemoteDescriptionWithoutError(updated_offer1.release());
3667
kwibergd1fe2812016-04-27 06:47:29 -07003668 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669
deadbeef0ed85b22016-02-23 17:24:52 -08003670 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3671 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003672
deadbeef0ed85b22016-02-23 17:24:52 -08003673 // Even a second answer (created before the description is set) should have
3674 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003675 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003676
3677 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3678 session_->local_description()->description()));
3679
3680 SetLocalDescriptionWithoutError(updated_answer2.release());
3681}
3682
3683// This test verifies that an answer contains new ufrag and password if an offer
3684// that changes either the ufrag or password (but not both) is received.
3685// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3686// a=ice-pwd attributes compared to the previous SDP from the peer, it
3687// indicates that ICE is restarting for this media stream."
3688TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3689 Init();
3690 cricket::MediaSessionOptions options;
3691 options.recv_audio = true;
3692 options.recv_video = true;
3693 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003694 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003695 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3696 SetRemoteDescriptionWithoutError(offer.release());
3697
3698 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003699 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003700 SetLocalDescriptionWithoutError(answer.release());
3701
3702 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003703 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003704 CreateRemoteOffer(options, session_->remote_description()));
3705 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3706 "original_password12345");
3707 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3708
kwibergd1fe2812016-04-27 06:47:29 -07003709 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003710 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3711 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003713
3714 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003715 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003716 CreateRemoteOffer(options, session_->remote_description()));
3717 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3718 "modified_password12345");
3719 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3720
kwibergd1fe2812016-04-27 06:47:29 -07003721 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003722 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3723 session_->local_description()->description()));
3724 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003725}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003726
wu@webrtc.org91053e72013-08-10 07:18:04 +00003727// This test verifies that an answer contains old ufrag and password if an offer
3728// with old ufrag and password is received.
3729TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003730 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003731 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003732 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003733 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003734 SetRemoteDescriptionWithoutError(offer.release());
3735
deadbeefab9b2d12015-10-14 11:33:11 -07003736 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003737 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003738 SetLocalDescriptionWithoutError(answer.release());
3739
3740 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003741 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003742 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743 SetRemoteDescriptionWithoutError(updated_offer2.release());
3744
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
deadbeef0ed85b22016-02-23 17:24:52 -08003747 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3748 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749
3750 SetLocalDescriptionWithoutError(updated_answer2.release());
3751}
3752
deadbeef0ed85b22016-02-23 17:24:52 -08003753// This test verifies that if an offer does an ICE restart on some, but not all
3754// media sections, the answer will change the ufrag/password in the correct
3755// media sections.
3756TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3757 Init();
3758 cricket::MediaSessionOptions options;
3759 options.recv_video = true;
3760 options.recv_audio = true;
3761 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003762 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003763
3764 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3765 "aaaaaaaaaaaaaaaaaaaaaa");
3766 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3767 "bbbbbbbbbbbbbbbbbbbbbb");
3768 SetRemoteDescriptionWithoutError(offer.release());
3769
3770 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003771 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003772 SetLocalDescriptionWithoutError(answer.release());
3773
3774 // Receive an offer with new ufrag and password, but only for the video media
3775 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003776 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003777 CreateRemoteOffer(options, session_->remote_description()));
3778 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3779 "cccccccccccccccccccccc");
3780 SetRemoteDescriptionWithoutError(updated_offer.release());
3781
kwibergd1fe2812016-04-27 06:47:29 -07003782 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003783
3784 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3785 session_->local_description()->description(),
3786 cricket::MEDIA_TYPE_AUDIO));
3787
3788 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3789 session_->local_description()->description(),
3790 cricket::MEDIA_TYPE_VIDEO));
3791
3792 SetLocalDescriptionWithoutError(updated_answer.release());
3793}
3794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003795TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003796 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003797 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003798 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003799 const std::string session_id_orig = offer->session_id();
3800 const std::string session_version_orig = offer->session_version();
3801 SetLocalDescriptionWithoutError(offer);
3802
3803 video_channel_ = media_engine_->GetVideoChannel(0);
3804 video_channel_->set_fail_set_send_codecs(true);
3805
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003806 SessionDescriptionInterface* answer =
3807 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003808 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003809
3810 // Test that after a content error, setting any description will
3811 // result in an error.
3812 video_channel_->set_fail_set_send_codecs(false);
3813 answer = CreateRemoteAnswer(session_->local_description());
3814 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3815 offer = CreateRemoteOffer();
3816 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003817}
3818
3819// Runs the loopback call test with BUNDLE and STUN disabled.
3820TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3821 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003822 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003823 cricket::PORTALLOCATOR_DISABLE_STUN |
3824 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003825 TestLoopbackCall();
3826}
3827
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003828TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003829 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003830 cricket::PORTALLOCATOR_DISABLE_STUN |
3831 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3832 cricket::PORTALLOCATOR_DISABLE_RELAY);
3833
3834 // best connection is IPv6 since it has higher network preference.
3835 LoopbackNetworkConfiguration config;
3836 config.test_ipv6_network_ = true;
3837 config.best_connection_after_initial_ice_converged_ =
3838 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3839
3840 TestLoopbackCall(config);
3841}
3842
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003843// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003844TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003845 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3846 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003847 TestLoopbackCall();
3848}
3849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003851 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003852 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003853 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003854 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003855 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003856}
3857
Henrik Boström87713d02015-08-25 09:53:21 +02003858TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003859 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003860 options_.disable_sctp_data_channels = false;
3861
Henrik Boström87713d02015-08-25 09:53:21 +02003862 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003863
3864 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003865 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3866}
3867
3868// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3869// before and after BUNDLE is negotiated.
3870TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003871 SetFactoryDtlsSrtp();
3872 InitWithDtls(GetParam());
3873
3874 // Initially these fields should be empty.
3875 EXPECT_FALSE(session_->sctp_content_name());
3876 EXPECT_FALSE(session_->sctp_transport_name());
3877
3878 // Create offer with audio/video/data.
3879 // Default bundle policy is "balanced", so data should be using its own
3880 // transport.
3881 SendAudioVideoStream1();
3882 CreateDataChannel();
3883 InitiateCall();
3884 ASSERT_TRUE(session_->sctp_content_name());
3885 ASSERT_TRUE(session_->sctp_transport_name());
3886 EXPECT_EQ("data", *session_->sctp_content_name());
3887 EXPECT_EQ("data", *session_->sctp_transport_name());
3888
3889 // Create answer that finishes BUNDLE negotiation, which means everything
3890 // should be bundled on the first transport (audio).
3891 cricket::MediaSessionOptions answer_options;
3892 answer_options.recv_video = true;
3893 answer_options.bundle_enabled = true;
3894 answer_options.data_channel_type = cricket::DCT_SCTP;
3895 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3896 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3897 ASSERT_TRUE(session_->sctp_content_name());
3898 ASSERT_TRUE(session_->sctp_transport_name());
3899 EXPECT_EQ("data", *session_->sctp_content_name());
3900 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003901}
3902
Henrik Boström87713d02015-08-25 09:53:21 +02003903TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003904 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003905
kwibergd1fe2812016-04-27 06:47:29 -07003906 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003907 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003908 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3909}
3910
Henrik Boström87713d02015-08-25 09:53:21 +02003911TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003912 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003913 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003914
3915 // Create remote offer with SCTP.
3916 cricket::MediaSessionOptions options;
3917 options.data_channel_type = cricket::DCT_SCTP;
3918 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003919 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003920 SetRemoteDescriptionWithoutError(offer);
3921
3922 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003923 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003924 EXPECT_TRUE(answer != NULL);
3925 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3926 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003927}
3928
deadbeef953c2ce2017-01-09 14:53:41 -08003929// Test that if DTLS is disabled, we don't end up with an SctpTransport
3930// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003931TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003932 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003933 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003934
3935 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003936 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3937 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003938}
3939
deadbeef953c2ce2017-01-09 14:53:41 -08003940// Test that if DTLS is enabled, we end up with an SctpTransport created
3941// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003942TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003943 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003944
3945 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003946 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3947 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003948}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003949
deadbeef953c2ce2017-01-09 14:53:41 -08003950// Test that if SCTP is disabled, we don't end up with an SctpTransport
3951// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003952TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003953 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003954 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003955
3956 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003957 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3958 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003959}
3960
Henrik Boström87713d02015-08-25 09:53:21 +02003961TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003962 const int new_send_port = 9998;
3963 const int new_recv_port = 7775;
3964
Henrik Boström87713d02015-08-25 09:53:21 +02003965 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003966 SetFactoryDtlsSrtp();
3967
3968 // By default, don't actually add the codecs to desc_factory_; they don't
3969 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3970 // let the session description get parsed. That'll get the proper codecs
3971 // into the stream.
3972 cricket::MediaSessionOptions options;
3973 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3974 "stream1", new_send_port, options);
3975
3976 // SetRemoteDescription will take the ownership of the offer.
3977 SetRemoteDescriptionWithoutError(offer);
3978
htaa2a49d92016-03-04 02:51:39 -08003979 SessionDescriptionInterface* answer =
3980 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003981 ASSERT_TRUE(answer != NULL);
3982
3983 // Now set the local description, which'll take ownership of the answer.
3984 SetLocalDescriptionWithoutError(answer);
3985
3986 // TEST PLAN: Set the port number to something new, set it in the SDP,
3987 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003988 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003989 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003990 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3991 EXPECT_EQ(
3992 new_recv_port,
3993 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3994 EXPECT_EQ(
3995 new_send_port,
3996 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003997}
3998
deadbeef953c2ce2017-01-09 14:53:41 -08003999// Verifies that when a session's SctpTransport receives an OPEN message,
4000// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004001// config.
4002TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004003 InitWithDtls(GetParam());
4004
4005 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004006 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4007 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004008
deadbeef953c2ce2017-01-09 14:53:41 -08004009 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004010 webrtc::DataChannelInit config;
4011 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004012 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004013 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4014 cricket::ReceiveDataParams params;
4015 params.ssrc = config.id;
4016 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004017 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4018 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004019
deadbeef953c2ce2017-01-09 14:53:41 -08004020 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004021 EXPECT_EQ(config.id, last_data_channel_config_.id);
4022 EXPECT_FALSE(last_data_channel_config_.negotiated);
4023 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4024 last_data_channel_config_.open_handshake_role);
4025}
4026
4027TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004028 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004029 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004030
htaa2a49d92016-03-04 02:51:39 -08004031 configuration_.certificates.push_back(certificate);
4032 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004033 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4034
4035 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4036}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004037
Henrik Boström87713d02015-08-25 09:53:21 +02004038// Verifies that CreateOffer succeeds when CreateOffer is called before async
4039// identity generation is finished (even if a certificate is provided this is
4040// an async op).
4041TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004042 InitWithDtls(GetParam());
4043
Henrik Boströmd8281982015-08-27 10:12:24 +02004044 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004045 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004046 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004047
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004049 VerifyNoCryptoParams(offer->description(), true);
4050 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004051}
4052
4053// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004054// identity generation is finished (even if a certificate is provided this is
4055// an async op).
4056TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004057 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004058 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004059
4060 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004061 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004062 std::unique_ptr<JsepSessionDescription> offer(
4063 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004064 ASSERT_TRUE(offer.get() != NULL);
4065 SetRemoteDescriptionWithoutError(offer.release());
4066
kwibergd1fe2812016-04-27 06:47:29 -07004067 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004069 VerifyNoCryptoParams(answer->description(), true);
4070 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004071}
4072
4073// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004074// identity generation is finished (even if a certificate is provided this is
4075// an async op).
4076TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004077 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004078
Henrik Boströmd8281982015-08-27 10:12:24 +02004079 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004080
kwibergd1fe2812016-04-27 06:47:29 -07004081 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004082 EXPECT_TRUE(offer != NULL);
4083}
4084
4085// Verifies that CreateOffer fails when CreateOffer is called after async
4086// identity generation fails.
4087TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004088 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004089
Henrik Boströmd8281982015-08-27 10:12:24 +02004090 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004091
kwibergd1fe2812016-04-27 06:47:29 -07004092 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004093 EXPECT_TRUE(offer == NULL);
4094}
4095
4096// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4097// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004098TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004100 VerifyMultipleAsyncCreateDescription(GetParam(),
4101 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004102}
4103
4104// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4105// before async identity generation fails.
4106TEST_F(WebRtcSessionTest,
4107 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004108 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4109 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004110}
4111
4112// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4113// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004114TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004117 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118}
4119
4120// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4121// before async identity generation fails.
4122TEST_F(WebRtcSessionTest,
4123 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004124 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4125 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004126}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004127
4128// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4129// offer has no SDES crypto but only DTLS fingerprint.
4130TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4131 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004132 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004133 // Create a remote offer with secured transport disabled.
4134 cricket::MediaSessionOptions options;
4135 JsepSessionDescription* offer(CreateRemoteOffer(
4136 options, cricket::SEC_DISABLED));
4137 // Adds a DTLS fingerprint to the remote offer.
4138 cricket::SessionDescription* sdp = offer->description();
4139 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4140 ASSERT_TRUE(audio != NULL);
4141 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4142 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004143 rtc::SSLFingerprint::CreateFromRfc4572(
4144 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004145 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004146 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004147}
4148
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004149TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004150 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004151 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004152 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004153 SessionDescriptionInterface* offer = CreateOffer();
4154
4155 SetLocalDescriptionWithoutError(offer);
4156
4157 voice_channel_ = media_engine_->GetVoiceChannel(0);
4158
4159 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004160 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004161 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004162}
4163
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004164// Tests that we can renegotiate new media content with ICE candidates in the
4165// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004166TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004167 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004168 SetFactoryDtlsSrtp();
4169
deadbeefab9b2d12015-10-14 11:33:11 -07004170 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004171 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004172 SetLocalDescriptionWithoutError(offer);
4173
4174 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4175 SetRemoteDescriptionWithoutError(answer);
4176
4177 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004178 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004179 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4180
4181 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004182 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004183 candidate1.set_component(1);
4184 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4185 candidate1);
4186 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4187 SetRemoteDescriptionWithoutError(offer);
4188
htaa2a49d92016-03-04 02:51:39 -08004189 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004190 SetLocalDescriptionWithoutError(answer);
4191}
4192
4193// Tests that we can renegotiate new media content with ICE candidates separated
4194// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004195TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004196 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004197 SetFactoryDtlsSrtp();
4198
deadbeefab9b2d12015-10-14 11:33:11 -07004199 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004200 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004201 SetLocalDescriptionWithoutError(offer);
4202
4203 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4204 SetRemoteDescriptionWithoutError(answer);
4205
4206 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004207 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004208 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4209 SetRemoteDescriptionWithoutError(offer);
4210
4211 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004212 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004213 candidate1.set_component(1);
4214 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4215 candidate1);
4216 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4217
htaa2a49d92016-03-04 02:51:39 -08004218 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004219 SetLocalDescriptionWithoutError(answer);
4220}
honghaiz7f777492016-02-02 21:54:01 -08004221
zhihuang9763d562016-08-05 11:14:50 -07004222#ifdef HAVE_QUIC
4223TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4224 configuration_.enable_quic = true;
4225 InitWithDtls(GetParam());
4226 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4227 SessionDescriptionInterface* offer = CreateOffer();
4228 ASSERT_TRUE(offer);
4229 ASSERT_TRUE(offer->description());
4230 SetLocalDescriptionWithoutError(offer);
4231 cricket::MediaSessionOptions options;
4232 options.recv_audio = true;
4233 options.recv_video = true;
4234 SessionDescriptionInterface* answer =
4235 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4236 ASSERT_TRUE(answer);
4237 ASSERT_TRUE(answer->description());
4238 SetRemoteDescriptionWithoutError(answer);
4239}
4240#endif // HAVE_QUIC
4241
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004242// Tests that RTX codec is removed from the answer when it isn't supported
4243// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004244TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004245 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004246 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004247 std::string offer_sdp(kSdpWithRtx);
4248
4249 SessionDescriptionInterface* offer =
4250 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4251 EXPECT_TRUE(offer->ToString(&offer_sdp));
4252
4253 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004254 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004255 SetRemoteDescriptionWithoutError(offer);
4256
htaa2a49d92016-03-04 02:51:39 -08004257 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004258 // Answer SDP does not contain the RTX codec.
4259 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004260 SetLocalDescriptionWithoutError(answer);
4261}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004262
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004263// This verifies that the voice channel after bundle has both options from video
4264// and voice channels.
4265TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4266 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004267 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004268
4269 PeerConnectionInterface::RTCOfferAnswerOptions options;
4270 options.use_rtp_mux = true;
4271
4272 SessionDescriptionInterface* offer = CreateOffer(options);
4273 SetLocalDescriptionWithoutError(offer);
4274
4275 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4276 rtc::Socket::Option::OPT_SNDBUF, 4000);
4277
4278 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4279 rtc::Socket::Option::OPT_RCVBUF, 8000);
4280
4281 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004282 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004283 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4284 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4287
deadbeefcbecd352015-09-23 11:50:27 -07004288 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004289 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4290 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004291 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004292 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4293
deadbeefcbecd352015-09-23 11:50:27 -07004294 EXPECT_NE(session_->voice_rtp_transport_channel(),
4295 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004296
deadbeefab9b2d12015-10-14 11:33:11 -07004297 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004298 SessionDescriptionInterface* answer =
4299 CreateRemoteAnswer(session_->local_description());
4300 SetRemoteDescriptionWithoutError(answer);
4301
deadbeefcbecd352015-09-23 11:50:27 -07004302 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4304 EXPECT_EQ(4000, option_val);
4305
deadbeefcbecd352015-09-23 11:50:27 -07004306 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004307 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4308 EXPECT_EQ(8000, option_val);
4309}
4310
tommi0f620f42015-07-09 03:25:02 -07004311// Test creating a session, request multiple offers, destroy the session
4312// and make sure we got success/failure callbacks for all of the requests.
4313// Background: crbug.com/507307
4314TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4315 Init();
4316
4317 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4318 PeerConnectionInterface::RTCOfferAnswerOptions options;
4319 options.offer_to_receive_audio =
4320 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004321 cricket::MediaSessionOptions session_options;
4322 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004323
4324 for (auto& o : observers) {
4325 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004326 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004327 }
4328
4329 session_.reset();
4330
tommi0f620f42015-07-09 03:25:02 -07004331 for (auto& o : observers) {
4332 // We expect to have received a notification now even if the session was
4333 // terminated. The offer creation may or may not have succeeded, but we
4334 // must have received a notification which, so the only invalid state
4335 // is kInit.
4336 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4337 }
4338}
4339
stefanc1aeaf02015-10-15 07:26:07 -07004340TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4341 TestPacketOptions();
4342}
4343
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004344// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4345// currently fails because upon disconnection and reconnection OnIceComplete is
4346// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004347
deadbeefcbecd352015-09-23 11:50:27 -07004348INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4349 WebRtcSessionTest,
4350 testing::Values(ALREADY_GENERATED,
4351 DTLS_IDENTITY_STORE));